Debian Codegraph @

ansible_collections/amazon/aws/tests/integration/targets/autoscaling_instance/tasks/protection.yml

raw
1 ---
2 # =====================================================
3 # Test updating the protection status of all instances
4 # =====================================================
5
6 # Set all to Unprotected - no change
7 - name: Instance_ids - all Unprotected (idempotency) - check_mode
8 amazon.aws.autoscaling_instance:
9 instance_ids: "{{ initial_instances }}"
10 group_name: "{{ default_resource_name }}"
11 state: present
12 protection: false
13 diff: true
14 register: unprotected_all
15 check_mode: true
16
17 - ansible.builtin.assert:
18 that:
19 - "'autoscaling:SetInstanceProtection' not in current_result.resource_actions"
20 - current_result is not changed
21 - "'auto_scaling_instances' in current_result"
22 - initial_instances[0] in listed_instance_ids
23 - initial_instances[1] in listed_instance_ids
24 - "'protected_from_scale_in' in specific_instance_info"
25 - specific_instance_info.protected_from_scale_in == False
26 - "'health_status' in specific_instance_info"
27 - specific_instance_info.health_status == "HEALTHY"
28 - "'protected_from_scale_in' in other_instance_info"
29 - other_instance_info.protected_from_scale_in == False
30 - "'health_status' in other_instance_info"
31 - other_instance_info.health_status == "HEALTHY"
32 # Ensure we only make the limited calls we expect
33 - "'autoscaling:DetachInstances' not in current_result.resource_actions"
34 - "'autoscaling:AttachInstances' not in current_result.resource_actions"
35 - "'autoscaling:SetInstanceHealth' not in current_result.resource_actions"
36 vars:
37 current_result: "{{ unprotected_all }}"
38 listed_instance_ids: "{{ current_result.auto_scaling_instances | map(attribute='instance_id') | list }}"
39 specific_instance_info: "{{ current_result.auto_scaling_instances | selectattr('instance_id', 'equalto', initial_instances[1]) | first }}"
40 other_instance_info: "{{ current_result.auto_scaling_instances | selectattr('instance_id', 'equalto', initial_instances[0]) | first }}"
41
42 - name: Instance_ids - all Unprotected (idempotency)
43 amazon.aws.autoscaling_instance:
44 instance_ids: "{{ initial_instances }}"
45 group_name: "{{ default_resource_name }}"
46 state: present
47 protection: false
48 diff: true
49 register: unprotected_all
50
51 - ansible.builtin.assert:
52 that:
53 - "'autoscaling:SetInstanceProtection' not in current_result.resource_actions"
54 - current_result is not changed
55 - "'auto_scaling_instances' in current_result"
56 - initial_instances[0] in listed_instance_ids
57 - initial_instances[1] in listed_instance_ids
58 - "'protected_from_scale_in' in specific_instance_info"
59 - specific_instance_info.protected_from_scale_in == False
60 - "'health_status' in specific_instance_info"
61 - specific_instance_info.health_status == "HEALTHY"
62 - "'protected_from_scale_in' in other_instance_info"
63 - other_instance_info.protected_from_scale_in == False
64 - "'health_status' in other_instance_info"
65 - other_instance_info.health_status == "HEALTHY"
66 # Ensure we only make the limited calls we expect
67 - "'autoscaling:DetachInstances' not in current_result.resource_actions"
68 - "'autoscaling:AttachInstances' not in current_result.resource_actions"
69 - "'autoscaling:SetInstanceHealth' not in current_result.resource_actions"
70 vars:
71 current_result: "{{ unprotected_all }}"
72 listed_instance_ids: "{{ current_result.auto_scaling_instances | map(attribute='instance_id') | list }}"
73 specific_instance_info: "{{ current_result.auto_scaling_instances | selectattr('instance_id', 'equalto', initial_instances[1]) | first }}"
74 other_instance_info: "{{ current_result.auto_scaling_instances | selectattr('instance_id', 'equalto', initial_instances[0]) | first }}"
75
76 # Set all to Protected
77 - name: Instance_ids - all Protected - check_mode
78 amazon.aws.autoscaling_instance:
79 instance_ids: "{{ initial_instances }}"
80 group_name: "{{ default_resource_name }}"
81 state: present
82 protection: true
83 diff: true
84 register: protected_all
85 check_mode: true
86
87 - ansible.builtin.assert:
88 that:
89 - "'autoscaling:SetInstanceProtection' not in current_result.resource_actions"
90 - current_result is changed
91 - "'auto_scaling_instances' in current_result"
92 - initial_instances[0] in listed_instance_ids
93 - initial_instances[1] in listed_instance_ids
94 - "'protected_from_scale_in' in specific_instance_info"
95 - specific_instance_info.protected_from_scale_in == True
96 - "'health_status' in specific_instance_info"
97 - specific_instance_info.health_status == "HEALTHY"
98 - "'protected_from_scale_in' in other_instance_info"
99 - other_instance_info.protected_from_scale_in == True
100 - "'health_status' in other_instance_info"
101 - other_instance_info.health_status == "HEALTHY"
102 # Ensure we only make the limited calls we expect
103 - "'autoscaling:DetachInstances' not in current_result.resource_actions"
104 - "'autoscaling:AttachInstances' not in current_result.resource_actions"
105 - "'autoscaling:SetInstanceHealth' not in current_result.resource_actions"
106 vars:
107 current_result: "{{ protected_all }}"
108 listed_instance_ids: "{{ current_result.auto_scaling_instances | map(attribute='instance_id') | list }}"
109 specific_instance_info: "{{ current_result.auto_scaling_instances | selectattr('instance_id', 'equalto', initial_instances[1]) | first }}"
110 other_instance_info: "{{ current_result.auto_scaling_instances | selectattr('instance_id', 'equalto', initial_instances[0]) | first }}"
111
112 - name: Instance_ids - all Protected
113 amazon.aws.autoscaling_instance:
114 instance_ids: "{{ initial_instances }}"
115 group_name: "{{ default_resource_name }}"
116 state: present
117 protection: true
118 diff: true
119 register: protected_all
120
121 - ansible.builtin.assert:
122 that:
123 - "'autoscaling:SetInstanceProtection' in current_result.resource_actions"
124 - current_result is changed
125 - "'auto_scaling_instances' in current_result"
126 - initial_instances[0] in listed_instance_ids
127 - initial_instances[1] in listed_instance_ids
128 - "'protected_from_scale_in' in specific_instance_info"
129 - specific_instance_info.protected_from_scale_in == True
130 - "'health_status' in specific_instance_info"
131 - specific_instance_info.health_status == "HEALTHY"
132 - "'protected_from_scale_in' in other_instance_info"
133 - other_instance_info.protected_from_scale_in == True
134 - "'health_status' in other_instance_info"
135 - other_instance_info.health_status == "HEALTHY"
136 # Ensure we only make the limited calls we expect
137 - "'autoscaling:DetachInstances' not in current_result.resource_actions"
138 - "'autoscaling:AttachInstances' not in current_result.resource_actions"
139 - "'autoscaling:SetInstanceHealth' not in current_result.resource_actions"
140 vars:
141 current_result: "{{ protected_all }}"
142 listed_instance_ids: "{{ current_result.auto_scaling_instances | map(attribute='instance_id') | list }}"
143 specific_instance_info: "{{ current_result.auto_scaling_instances | selectattr('instance_id', 'equalto', initial_instances[1]) | first }}"
144 other_instance_info: "{{ current_result.auto_scaling_instances | selectattr('instance_id', 'equalto', initial_instances[0]) | first }}"
145
146 - name: Instance_ids - all Protected (idempotency) - check_mode
147 amazon.aws.autoscaling_instance:
148 instance_ids: "{{ initial_instances }}"
149 group_name: "{{ default_resource_name }}"
150 state: present
151 protection: true
152 diff: true
153 register: protected_all
154 check_mode: true
155
156 - ansible.builtin.assert:
157 that:
158 - "'autoscaling:SetInstanceProtection' not in current_result.resource_actions"
159 - current_result is not changed
160 - "'auto_scaling_instances' in current_result"
161 - initial_instances[0] in listed_instance_ids
162 - initial_instances[1] in listed_instance_ids
163 - "'protected_from_scale_in' in specific_instance_info"
164 - specific_instance_info.protected_from_scale_in == True
165 - "'health_status' in specific_instance_info"
166 - specific_instance_info.health_status == "HEALTHY"
167 - "'protected_from_scale_in' in other_instance_info"
168 - other_instance_info.protected_from_scale_in == True
169 - "'health_status' in other_instance_info"
170 - other_instance_info.health_status == "HEALTHY"
171 # Ensure we only make the limited calls we expect
172 - "'autoscaling:DetachInstances' not in current_result.resource_actions"
173 - "'autoscaling:AttachInstances' not in current_result.resource_actions"
174 - "'autoscaling:SetInstanceHealth' not in current_result.resource_actions"
175 vars:
176 current_result: "{{ protected_all }}"
177 listed_instance_ids: "{{ current_result.auto_scaling_instances | map(attribute='instance_id') | list }}"
178 specific_instance_info: "{{ current_result.auto_scaling_instances | selectattr('instance_id', 'equalto', initial_instances[1]) | first }}"
179 other_instance_info: "{{ current_result.auto_scaling_instances | selectattr('instance_id', 'equalto', initial_instances[0]) | first }}"
180
181 - name: Instance_ids - all Protected (idempotency)
182 amazon.aws.autoscaling_instance:
183 instance_ids: "{{ initial_instances }}"
184 group_name: "{{ default_resource_name }}"
185 state: present
186 protection: true
187 diff: true
188 register: protected_all
189
190 - ansible.builtin.assert:
191 that:
192 - "'autoscaling:SetInstanceProtection' not in current_result.resource_actions"
193 - current_result is not changed
194 - "'auto_scaling_instances' in current_result"
195 - initial_instances[0] in listed_instance_ids
196 - initial_instances[1] in listed_instance_ids
197 - "'protected_from_scale_in' in specific_instance_info"
198 - specific_instance_info.protected_from_scale_in == True
199 - "'health_status' in specific_instance_info"
200 - specific_instance_info.health_status == "HEALTHY"
201 - "'protected_from_scale_in' in other_instance_info"
202 - other_instance_info.protected_from_scale_in == True
203 - "'health_status' in other_instance_info"
204 - other_instance_info.health_status == "HEALTHY"
205 # Ensure we only make the limited calls we expect
206 - "'autoscaling:DetachInstances' not in current_result.resource_actions"
207 - "'autoscaling:AttachInstances' not in current_result.resource_actions"
208 - "'autoscaling:SetInstanceHealth' not in current_result.resource_actions"
209 vars:
210 current_result: "{{ protected_all }}"
211 listed_instance_ids: "{{ current_result.auto_scaling_instances | map(attribute='instance_id') | list }}"
212 specific_instance_info: "{{ current_result.auto_scaling_instances | selectattr('instance_id', 'equalto', initial_instances[1]) | first }}"
213 other_instance_info: "{{ current_result.auto_scaling_instances | selectattr('instance_id', 'equalto', initial_instances[0]) | first }}"
214
215 # Set all to Unprotected again
216 - name: Instance_ids - all Unprotected - check_mode
217 amazon.aws.autoscaling_instance:
218 instance_ids: "{{ initial_instances }}"
219 group_name: "{{ default_resource_name }}"
220 state: present
221 protection: false
222 diff: true
223 register: unprotected_all
224 check_mode: true
225
226 - ansible.builtin.assert:
227 that:
228 - "'autoscaling:SetInstanceProtection' not in current_result.resource_actions"
229 - current_result is changed
230 - "'auto_scaling_instances' in current_result"
231 - initial_instances[0] in listed_instance_ids
232 - initial_instances[1] in listed_instance_ids
233 - "'protected_from_scale_in' in specific_instance_info"
234 - specific_instance_info.protected_from_scale_in == False
235 - "'health_status' in specific_instance_info"
236 - specific_instance_info.health_status == "HEALTHY"
237 - "'protected_from_scale_in' in other_instance_info"
238 - other_instance_info.protected_from_scale_in == False
239 - "'health_status' in other_instance_info"
240 - other_instance_info.health_status == "HEALTHY"
241 # Ensure we only make the limited calls we expect
242 - "'autoscaling:DetachInstances' not in current_result.resource_actions"
243 - "'autoscaling:AttachInstances' not in current_result.resource_actions"
244 - "'autoscaling:SetInstanceHealth' not in current_result.resource_actions"
245 vars:
246 current_result: "{{ unprotected_all }}"
247 listed_instance_ids: "{{ current_result.auto_scaling_instances | map(attribute='instance_id') | list }}"
248 specific_instance_info: "{{ current_result.auto_scaling_instances | selectattr('instance_id', 'equalto', initial_instances[1]) | first }}"
249 other_instance_info: "{{ current_result.auto_scaling_instances | selectattr('instance_id', 'equalto', initial_instances[0]) | first }}"
250
251 - name: Instance_ids - all Unprotected
252 amazon.aws.autoscaling_instance:
253 instance_ids: "{{ initial_instances }}"
254 group_name: "{{ default_resource_name }}"
255 state: present
256 protection: false
257 diff: true
258 register: unprotected_all
259
260 - ansible.builtin.assert:
261 that:
262 - "'autoscaling:SetInstanceProtection' in current_result.resource_actions"
263 - current_result is changed
264 - "'auto_scaling_instances' in current_result"
265 - initial_instances[0] in listed_instance_ids
266 - initial_instances[1] in listed_instance_ids
267 - "'protected_from_scale_in' in specific_instance_info"
268 - specific_instance_info.protected_from_scale_in == False
269 - "'health_status' in specific_instance_info"
270 - specific_instance_info.health_status == "HEALTHY"
271 - "'protected_from_scale_in' in other_instance_info"
272 - other_instance_info.protected_from_scale_in == False
273 - "'health_status' in other_instance_info"
274 - other_instance_info.health_status == "HEALTHY"
275 # Ensure we only make the limited calls we expect
276 - "'autoscaling:DetachInstances' not in current_result.resource_actions"
277 - "'autoscaling:AttachInstances' not in current_result.resource_actions"
278 - "'autoscaling:SetInstanceHealth' not in current_result.resource_actions"
279 vars:
280 current_result: "{{ unprotected_all }}"
281 listed_instance_ids: "{{ current_result.auto_scaling_instances | map(attribute='instance_id') | list }}"
282 specific_instance_info: "{{ current_result.auto_scaling_instances | selectattr('instance_id', 'equalto', initial_instances[1]) | first }}"
283 other_instance_info: "{{ current_result.auto_scaling_instances | selectattr('instance_id', 'equalto', initial_instances[0]) | first }}"
284
285 # -- implicit instance list --
286
287 # implicitly change all
288 - name: No instance_ids - all Protected
289 amazon.aws.autoscaling_instance:
290 group_name: "{{ default_resource_name }}"
291 state: present
292 protection: true
293 diff: true
294 register: protected_all
295
296 - ansible.builtin.assert:
297 that:
298 - "'autoscaling:SetInstanceProtection' in current_result.resource_actions"
299 - current_result is changed
300 - "'auto_scaling_instances' in current_result"
301 - initial_instances[0] in listed_instance_ids
302 - initial_instances[1] in listed_instance_ids
303 - "'protected_from_scale_in' in specific_instance_info"
304 - specific_instance_info.protected_from_scale_in == True
305 - "'health_status' in specific_instance_info"
306 - specific_instance_info.health_status == "HEALTHY"
307 - "'protected_from_scale_in' in other_instance_info"
308 - other_instance_info.protected_from_scale_in == True
309 - "'health_status' in other_instance_info"
310 - other_instance_info.health_status == "HEALTHY"
311 # Ensure we only make the limited calls we expect
312 - "'autoscaling:DetachInstances' not in current_result.resource_actions"
313 - "'autoscaling:AttachInstances' not in current_result.resource_actions"
314 - "'autoscaling:SetInstanceHealth' not in current_result.resource_actions"
315 vars:
316 current_result: "{{ protected_all }}"
317 listed_instance_ids: "{{ current_result.auto_scaling_instances | map(attribute='instance_id') | list }}"
318 specific_instance_info: "{{ current_result.auto_scaling_instances | selectattr('instance_id', 'equalto', initial_instances[1]) | first }}"
319 other_instance_info: "{{ current_result.auto_scaling_instances | selectattr('instance_id', 'equalto', initial_instances[0]) | first }}"
320
321 # implicitly change all
322 - name: No instance_ids - all Unprotected
323 amazon.aws.autoscaling_instance:
324 group_name: "{{ default_resource_name }}"
325 state: present
326 protection: false
327 diff: true
328 register: unprotected_all
329
330 - ansible.builtin.assert:
331 that:
332 - "'autoscaling:SetInstanceProtection' in current_result.resource_actions"
333 - current_result is changed
334 - "'auto_scaling_instances' in current_result"
335 - initial_instances[0] in listed_instance_ids
336 - initial_instances[1] in listed_instance_ids
337 - "'protected_from_scale_in' in specific_instance_info"
338 - specific_instance_info.protected_from_scale_in == False
339 - "'health_status' in specific_instance_info"
340 - specific_instance_info.health_status == "HEALTHY"
341 - "'protected_from_scale_in' in other_instance_info"
342 - other_instance_info.protected_from_scale_in == False
343 - "'health_status' in other_instance_info"
344 - other_instance_info.health_status == "HEALTHY"
345 # Ensure we only make the limited calls we expect
346 - "'autoscaling:DetachInstances' not in current_result.resource_actions"
347 - "'autoscaling:AttachInstances' not in current_result.resource_actions"
348 - "'autoscaling:SetInstanceHealth' not in current_result.resource_actions"
349 vars:
350 current_result: "{{ unprotected_all }}"
351 listed_instance_ids: "{{ current_result.auto_scaling_instances | map(attribute='instance_id') | list }}"
352 specific_instance_info: "{{ current_result.auto_scaling_instances | selectattr('instance_id', 'equalto', initial_instances[1]) | first }}"
353 other_instance_info: "{{ current_result.auto_scaling_instances | selectattr('instance_id', 'equalto', initial_instances[0]) | first }}"
354
355 # =====================================================
356 # Test updating the health of one instance
357 # =====================================================
358
359 # Set to Unprotected - no change
360 - name: Instance_ids - one Unprotected (idempotency) - check_mode
361 amazon.aws.autoscaling_instance:
362 instance_ids: "{{ initial_instances[1] }}"
363 group_name: "{{ default_resource_name }}"
364 state: present
365 protection: false
366 diff: true
367 register: unprotected_one
368 check_mode: true
369
370 - name: Instance_ids - one Unprotected (idempotency)
371 amazon.aws.autoscaling_instance:
372 instance_ids: "{{ initial_instances[1] }}"
373 group_name: "{{ default_resource_name }}"
374 state: present
375 protection: false
376 diff: true
377 register: unprotected_one
378
379 # Set to Protected
380 - name: Instance_ids - one Protected - check_mode
381 amazon.aws.autoscaling_instance:
382 instance_ids: "{{ initial_instances[1] }}"
383 group_name: "{{ default_resource_name }}"
384 state: present
385 protection: true
386 diff: true
387 register: protected_one
388 check_mode: true
389
390 - name: Instance_ids - one Protected
391 amazon.aws.autoscaling_instance:
392 instance_ids: "{{ initial_instances[1] }}"
393 group_name: "{{ default_resource_name }}"
394 state: present
395 protection: true
396 diff: true
397 register: protected_one
398
399 - name: Instance_ids - one Protected (idempotency) - check_mode
400 amazon.aws.autoscaling_instance:
401 instance_ids: "{{ initial_instances[1] }}"
402 group_name: "{{ default_resource_name }}"
403 state: present
404 protection: true
405 diff: true
406 register: protected_one
407 check_mode: true
408
409 - name: Instance_ids - one Protected (idempotency)
410 amazon.aws.autoscaling_instance:
411 instance_ids: "{{ initial_instances[1] }}"
412 group_name: "{{ default_resource_name }}"
413 state: present
414 protection: true
415 diff: true
416 register: protected_one
417
418 # Set to Unprotected again
419 - name: Instance_ids - one Unprotected - check_mode
420 amazon.aws.autoscaling_instance:
421 instance_ids: "{{ initial_instances[1] }}"
422 group_name: "{{ default_resource_name }}"
423 state: present
424 protection: false
425 diff: true
426 register: unprotected_one
427 check_mode: true
428
429 - name: Instance_ids - one Unprotected
430 amazon.aws.autoscaling_instance:
431 instance_ids: "{{ initial_instances[1] }}"
432 group_name: "{{ default_resource_name }}"
433 state: present
434 protection: false
435 diff: true
436 register: unprotected_one