Debian Codegraph @

ansible_collections/community/aws/tests/integration/targets/stepfunctions_state_machine/tasks/main.yml

raw
1 ---
2
3 - name: Integration test for AWS Step Function state machine module
4 module_defaults:
5 group/aws:
6 access_key: "{{ aws_access_key }}"
7 secret_key: "{{ aws_secret_key }}"
8 session_token: "{{ security_token | default(omit) }}"
9 region: "{{ aws_region }}"
10 collections:
11 - amazon.aws
12
13 block:
14
15 # ==== Setup ==================================================
16
17 - name: Create IAM service role needed for Step Functions
18 iam_role:
19 name: "{{ step_functions_role_name }}"
20 description: Role with permissions for AWS Step Functions actions.
21 assume_role_policy_document: "{{ lookup('file', 'state_machines_iam_trust_policy.json') }}"
22 state: present
23 register: step_functions_role
24
25 - name: Pause a few seconds to ensure IAM role is available to next task
26 pause:
27 seconds: 10
28
29 - name: Create a random component for state machine name
30 set_fact:
31 random_num: "{{ 999999999 | random }}"
32
33 # ==== Tests ===================================================
34
35 - name: Create a new state machine -- check_mode
36 stepfunctions_state_machine:
37 name: "{{ state_machine_name }}"
38 definition: "{{ lookup('file','state_machine.json') }}"
39 role_arn: "{{ step_functions_role.iam_role.arn }}"
40 tags:
41 project: helloWorld
42 state: present
43 register: creation_check
44 check_mode: yes
45
46 - assert:
47 that:
48 - creation_check.changed == True
49 - creation_check.output == 'State machine would be created.'
50
51 - name: Create a new state machine
52 stepfunctions_state_machine:
53 name: "{{ state_machine_name }}"
54 definition: "{{ lookup('file','state_machine.json') }}"
55 role_arn: "{{ step_functions_role.iam_role.arn }}"
56 tags:
57 project: helloWorld
58 state: present
59 register: creation_output
60
61 - assert:
62 that:
63 - creation_output.changed == True
64 - '"state_machine_arn" in creation_output'
65
66 - name: Pause a few seconds to ensure state machine role is available
67 pause:
68 seconds: 5
69
70 - name: Idempotent rerun of same state function -- check_mode
71 stepfunctions_state_machine:
72 name: "{{ state_machine_name }}"
73 definition: "{{ lookup('file','state_machine.json') }}"
74 role_arn: "{{ step_functions_role.iam_role.arn }}"
75 tags:
76 project: helloWorld
77 state: present
78 register: result
79 check_mode: yes
80
81 - assert:
82 that:
83 - result.changed == False
84 - result.output == 'State is up-to-date.'
85
86 - name: Idempotent rerun of same state function
87 stepfunctions_state_machine:
88 name: "{{ state_machine_name }}"
89 definition: "{{ lookup('file','state_machine.json') }}"
90 role_arn: "{{ step_functions_role.iam_role.arn }}"
91 tags:
92 project: helloWorld
93 state: present
94 register: result
95
96 - assert:
97 that:
98 - result.changed == False
99 - result.state_machine_arn == creation_output.state_machine_arn
100
101 - name: Update an existing state machine -- check_mode
102 stepfunctions_state_machine:
103 name: "{{ state_machine_name }}"
104 definition: "{{ lookup('file','alternative_state_machine.json') }}"
105 role_arn: "{{ step_functions_role.iam_role.arn }}"
106 tags:
107 differentTag: different_tag
108 state: present
109 register: update_check
110 check_mode: yes
111
112 - assert:
113 that:
114 - update_check.changed == True
115 - "update_check.output == 'State machine would be updated: ' ~ creation_output.state_machine_arn"
116
117 - name: Update an existing state machine
118 stepfunctions_state_machine:
119 name: "{{ state_machine_name }}"
120 definition: "{{ lookup('file','alternative_state_machine.json') }}"
121 role_arn: "{{ step_functions_role.iam_role.arn }}"
122 tags:
123 differentTag: different_tag
124 state: present
125 register: update_output
126
127 - assert:
128 that:
129 - update_output.changed == True
130 - update_output.state_machine_arn == creation_output.state_machine_arn
131
132 - name: Start execution of state machine -- check_mode
133 stepfunctions_state_machine_execution:
134 name: "{{ execution_name }}"
135 execution_input: "{}"
136 state_machine_arn: "{{ creation_output.state_machine_arn }}"
137 register: start_execution_output
138 check_mode: yes
139
140 - assert:
141 that:
142 - start_execution_output.changed == True
143 - "start_execution_output.output == 'State machine execution would be started.'"
144
145 - name: Start execution of state machine
146 stepfunctions_state_machine_execution:
147 name: "{{ execution_name }}"
148 execution_input: "{}"
149 state_machine_arn: "{{ creation_output.state_machine_arn }}"
150 register: start_execution_output
151
152 - assert:
153 that:
154 - start_execution_output.changed
155 - "'execution_arn' in start_execution_output"
156 - "'start_date' in start_execution_output"
157
158 - name: Start execution of state machine (check for idempotency) (check mode)
159 stepfunctions_state_machine_execution:
160 name: "{{ execution_name }}"
161 execution_input: "{}"
162 state_machine_arn: "{{ creation_output.state_machine_arn }}"
163 register: start_execution_output_idem_check
164 check_mode: yes
165
166 - assert:
167 that:
168 - not start_execution_output_idem_check.changed
169 - "start_execution_output_idem_check.output == 'State machine execution already exists.'"
170
171 - name: Start execution of state machine (check for idempotency)
172 stepfunctions_state_machine_execution:
173 name: "{{ execution_name }}"
174 execution_input: "{}"
175 state_machine_arn: "{{ creation_output.state_machine_arn }}"
176 register: start_execution_output_idem
177
178 - assert:
179 that:
180 - not start_execution_output_idem.changed
181
182 - name: Stop execution of state machine -- check_mode
183 stepfunctions_state_machine_execution:
184 action: stop
185 execution_arn: "{{ start_execution_output.execution_arn }}"
186 cause: "cause of the failure"
187 error: "error code of the failure"
188 register: stop_execution_output
189 check_mode: yes
190
191 - assert:
192 that:
193 - stop_execution_output.changed
194 - "stop_execution_output.output == 'State machine execution would be stopped.'"
195
196 - name: Stop execution of state machine
197 stepfunctions_state_machine_execution:
198 action: stop
199 execution_arn: "{{ start_execution_output.execution_arn }}"
200 cause: "cause of the failure"
201 error: "error code of the failure"
202 register: stop_execution_output
203
204 - assert:
205 that:
206 - stop_execution_output.changed
207 - "'stop_date' in stop_execution_output"
208
209 - name: Stop execution of state machine (check for idempotency)
210 stepfunctions_state_machine_execution:
211 action: stop
212 execution_arn: "{{ start_execution_output.execution_arn }}"
213 cause: "cause of the failure"
214 error: "error code of the failure"
215 register: stop_execution_output
216
217 - assert:
218 that:
219 - not stop_execution_output.changed
220
221 - name: Try stopping a non-running execution -- check_mode
222 stepfunctions_state_machine_execution:
223 action: stop
224 execution_arn: "{{ start_execution_output.execution_arn }}"
225 cause: "cause of the failure"
226 error: "error code of the failure"
227 register: stop_execution_output
228 check_mode: yes
229
230 - assert:
231 that:
232 - not stop_execution_output.changed
233 - "stop_execution_output.output == 'State machine execution is not running.'"
234
235 - name: Try stopping a non-running execution
236 stepfunctions_state_machine_execution:
237 action: stop
238 execution_arn: "{{ start_execution_output.execution_arn }}"
239 cause: "cause of the failure"
240 error: "error code of the failure"
241 register: stop_execution_output
242 check_mode: yes
243
244 - assert:
245 that:
246 - not stop_execution_output.changed
247
248 - name: Start execution of state machine with the same execution name
249 stepfunctions_state_machine_execution:
250 name: "{{ execution_name }}"
251 state_machine_arn: "{{ creation_output.state_machine_arn }}"
252 register: start_execution_output_again
253
254 - assert:
255 that:
256 - not start_execution_output_again.changed
257
258 - name: Remove state machine -- check_mode
259 stepfunctions_state_machine:
260 name: "{{ state_machine_name }}"
261 state: absent
262 register: deletion_check
263 check_mode: yes
264
265 - assert:
266 that:
267 - deletion_check.changed == True
268 - "deletion_check.output == 'State machine would be deleted: ' ~ creation_output.state_machine_arn"
269
270 - name: Remove state machine
271 stepfunctions_state_machine:
272 name: "{{ state_machine_name }}"
273 state: absent
274 register: deletion_output
275
276 - assert:
277 that:
278 - deletion_output.changed == True
279 - deletion_output.state_machine_arn == creation_output.state_machine_arn
280
281 - name: Non-existent state machine is absent
282 stepfunctions_state_machine:
283 name: "non_existing_state_machine"
284 state: absent
285 register: result
286
287 - assert:
288 that:
289 - result.changed == False
290
291 # ==== Cleanup ====================================================
292
293 always:
294
295 - name: Cleanup - delete state machine
296 stepfunctions_state_machine:
297 name: "{{ state_machine_name }}"
298 state: absent
299 ignore_errors: true
300
301 - name: Cleanup - delete IAM role needed for Step Functions test
302 iam_role:
303 name: "{{ step_functions_role_name }}"
304 state: absent
305 ignore_errors: true