Debian Codegraph @

ansible_collections/amazon/aws/tests/integration/targets/backup_selection/tasks/main.yml

raw
1 ---
2 - module_defaults:
3 group/aws:
4 access_key: "{{ aws_access_key }}"
5 secret_key: "{{ aws_secret_key }}"
6 session_token: "{{ security_token | default(omit) }}"
7 region: "{{ aws_region }}"
8
9 block:
10 # ============================================================
11 # Setup
12 # ============================================================
13
14 - name: Create an IAM Role
15 amazon.aws.iam_role:
16 name: "{{ backup_iam_role_name }}"
17 assume_role_policy_document: '{{ lookup("file", "backup-policy.json") }}'
18 create_instance_profile: false
19 description: Ansible AWS Backup Role
20 managed_policy:
21 - arn:aws:iam::aws:policy/service-role/AWSBackupServiceRolePolicyForBackup
22 wait: true
23 register: iam_role
24
25 - name: Wait for the role to be created
26 ansible.builtin.pause:
27 seconds: 8
28
29 - name: Create an AWS Backup vault for the plan to target
30 amazon.aws.backup_vault:
31 backup_vault_name: "{{ backup_vault_name }}"
32 register: _result_create_backup_vault
33
34 - name: Verify result
35 ansible.builtin.assert:
36 that:
37 - _result_create_backup_vault.changed
38
39 - name: Create an AWS Backup plan for the selection to target
40 amazon.aws.backup_plan:
41 backup_plan_name: "{{ backup_plan_name }}"
42 rules:
43 - rule_name: DailyBackups
44 target_backup_vault_name: "{{ backup_vault_name }}"
45 schedule_expression: cron(0 5 ? * * *)
46 start_window_minutes: 60
47 completion_window_minutes: 1440
48 tags:
49 environment: test
50 register: _result_create_backup_plan
51
52 - name: Set backup plan ID
53 ansible.builtin.set_fact:
54 backup_plan_id: "{{ _result_create_backup_plan.backup_plan_id }}"
55
56 # ============================================================
57 # Create Selection Tests
58 # ============================================================
59
60 # Create selection with all options
61 # ------------------------------------------------------------
62
63 - name: Set input variable for create selection with all options tests
64 ansible.builtin.set_fact:
65 create_with_all_options_input:
66 selection_name: all-options-{{ backup_selection_name }}
67 backup_plan_name: "{{ backup_plan_name }}"
68 iam_role_arn: "{{ iam_role.iam_role.arn }}"
69 resources:
70 - arn:aws:s3:::a-bucket
71 not_resources:
72 - arn:aws:s3:::another-bucket
73 list_of_tags:
74 - condition_type: STRINGEQUALS
75 condition_key: backup
76 condition_value: daily
77 conditions:
78 string_equals:
79 - condition_key: aws:ResourceTag/environment
80 condition_value: prod
81 string_like:
82 - condition_key: aws:ResourceTag/environment
83 condition_value: prod*
84 string_not_equals:
85 - condition_key: aws:ResourceTag/environment
86 condition_value: test
87 string_not_like:
88 - condition_key: aws:ResourceTag/environment
89 condition_value: test*
90
91 - name: Create an AWS Backup selection with all options (check_mode)
92 amazon.aws.backup_selection: "{{ create_with_all_options_input }}"
93 check_mode: true
94 register: _result_create_selection_with_all_options_check_mode
95
96 - name: Verify result
97 ansible.builtin.assert:
98 that:
99 - _result_create_selection_with_all_options_check_mode.changed
100
101 - name: Get backup selection info
102 amazon.aws.backup_selection_info:
103 backup_plan_name: "{{ backup_plan_name }}"
104 selection_names:
105 - all-options-{{ backup_selection_name }}
106 register: _result_backup_selection_info
107
108 - name: Verify backup selection was not created in check mode
109 ansible.builtin.assert:
110 that:
111 - _result_backup_selection_info.backup_selections | length == 0
112
113 - name: Create an AWS Backup selection with all options
114 amazon.aws.backup_selection: "{{ create_with_all_options_input }}"
115 register: _result_create_selection_with_all_options
116
117 - name: Verify result
118 ansible.builtin.assert:
119 that:
120 - _result_create_selection_with_all_options.changed
121 - "'backup_selection' in _result_create_selection_with_all_options"
122 - _result_create_selection_with_all_options.backup_selection.iam_role_arn == iam_role.iam_role.arn
123 - _result_create_selection_with_all_options.backup_selection.selection_name == "all-options-"+backup_selection_name
124
125 - name: Create an AWS Backup selection with all options (idempotency)
126 amazon.aws.backup_selection: "{{ create_with_all_options_input }}"
127 register: _result_create_selection_with_all_options_idempotency
128
129 - name: Verify result
130 ansible.builtin.assert:
131 that:
132 - not _result_create_selection_with_all_options_idempotency.changed
133 - "'backup_selection' in _result_create_selection_with_all_options_idempotency"
134 - _result_create_selection_with_all_options_idempotency.backup_selection.iam_role_arn == iam_role.iam_role.arn
135 - _result_create_selection_with_all_options_idempotency.backup_selection.selection_name == "all-options-"+backup_selection_name
136
137 - name: Get detailed information about the AWS Backup selection
138 amazon.aws.backup_selection_info:
139 backup_plan_name: "{{ backup_plan_name }}"
140 selection_names:
141 - all-options-{{ backup_selection_name }}
142 register: _result_backup_selection_info
143
144 - name: Verify selection was created with all options
145 ansible.builtin.assert:
146 that:
147 - _result_backup_selection_info.backup_selections | length == 1
148 - _result_backup_selection_info.backup_selections[0].iam_role_arn == iam_role.iam_role.arn
149 - _result_backup_selection_info.backup_selections[0].selection_name == "all-options-"+backup_selection_name
150 - _result_backup_selection_info.backup_selections[0].resources == ['arn:aws:s3:::a-bucket']
151 - _result_backup_selection_info.backup_selections[0].not_resources == ['arn:aws:s3:::another-bucket']
152 - _result_backup_selection_info.backup_selections[0].list_of_tags[0].condition_value == "daily"
153 - _result_backup_selection_info.backup_selections[0].conditions.string_equals | length == 1
154 - _result_backup_selection_info.backup_selections[0].conditions.string_like | length == 1
155 - _result_backup_selection_info.backup_selections[0].conditions.string_not_equals | length == 1
156 - _result_backup_selection_info.backup_selections[0].conditions.string_not_like | length == 1
157
158 # Create selection with minimal options
159 # ------------------------------------------------------------
160
161 - name: Set input variable for create selection with minimal options tests
162 ansible.builtin.set_fact:
163 create_with_minimal_options_input:
164 selection_name: "{{ backup_selection_name }}"
165 backup_plan_name: "{{ backup_plan_name }}"
166 iam_role_arn: "{{ iam_role.iam_role.arn }}"
167 resources:
168 - arn:aws:s3:::a-bucket
169
170 - name: Create an AWS Backup selection with minimal options (check_mode)
171 amazon.aws.backup_selection: "{{ create_with_minimal_options_input }}"
172 check_mode: true
173 register: _result_create_selection_with_minimal_options_check_mode
174
175 - name: Verify result
176 ansible.builtin.assert:
177 that:
178 - _result_create_selection_with_minimal_options_check_mode.changed
179
180 - name: Get backup selection info
181 amazon.aws.backup_selection_info:
182 backup_plan_name: "{{ backup_plan_name }}"
183 selection_names:
184 - "{{ backup_selection_name }}"
185 register: _result_backup_selection_info
186
187 - name: Verify backup selection was not created in check mode
188 ansible.builtin.assert:
189 that:
190 - _result_backup_selection_info.backup_selections | length == 0
191
192 - name: Create an AWS Backup selection with minimal options
193 amazon.aws.backup_selection: "{{ create_with_minimal_options_input }}"
194 register: _result_create_selection_with_minimal_options
195
196 - name: Verify result
197 ansible.builtin.assert:
198 that:
199 - _result_create_selection_with_minimal_options.changed
200 - "'backup_selection' in _result_create_selection_with_minimal_options"
201 - _result_create_selection_with_minimal_options.backup_selection.iam_role_arn == iam_role.iam_role.arn
202 - _result_create_selection_with_minimal_options.backup_selection.selection_name == backup_selection_name
203
204 - name: Create an AWS Backup selection with minimal options (idempotency)
205 amazon.aws.backup_selection: "{{ create_with_minimal_options_input }}"
206 register: _result_create_selection_with_minimal_options_idempotency
207
208 - name: Verify result
209 ansible.builtin.assert:
210 that:
211 - not _result_create_selection_with_minimal_options_idempotency.changed
212 - "'backup_selection' in _result_create_selection_with_minimal_options_idempotency"
213 - _result_create_selection_with_minimal_options_idempotency.backup_selection.iam_role_arn == iam_role.iam_role.arn
214 - _result_create_selection_with_minimal_options_idempotency.backup_selection.selection_name == backup_selection_name
215
216 - name: Get detailed information about the AWS Backup selection
217 amazon.aws.backup_selection_info:
218 backup_plan_name: "{{ backup_plan_name }}"
219 selection_names:
220 - "{{ backup_selection_name }}"
221 register: _result_backup_selection_info
222
223 - name: Verify selection was created with minimal options
224 ansible.builtin.assert:
225 that:
226 - _result_backup_selection_info.backup_selections | length == 1
227 - _result_backup_selection_info.backup_selections[0].iam_role_arn == iam_role.iam_role.arn
228 - _result_backup_selection_info.backup_selections[0].selection_name == backup_selection_name
229 - _result_backup_selection_info.backup_selections[0].resources == ['arn:aws:s3:::a-bucket']
230 - _result_backup_selection_info.backup_selections[0].not_resources == []
231 - _result_backup_selection_info.backup_selections[0].list_of_tags | length == 0
232 - _result_backup_selection_info.backup_selections[0].conditions.string_equals | length == 0
233 - _result_backup_selection_info.backup_selections[0].conditions.string_like | length == 0
234 - _result_backup_selection_info.backup_selections[0].conditions.string_not_equals | length == 0
235 - _result_backup_selection_info.backup_selections[0].conditions.string_not_like | length == 0
236
237 # ============================================================
238 # Update Selection Tests
239 # ============================================================
240
241 # Add list_of_tags
242 # ------------------------------------------------------------
243
244 - name: Set input variable for add list_of_tags tests
245 ansible.builtin.set_fact:
246 add_list_of_tags_input:
247 selection_name: "{{ backup_selection_name }}"
248 backup_plan_name: "{{ backup_plan_name }}"
249 iam_role_arn: "{{ iam_role.iam_role.arn }}"
250 resources:
251 - arn:aws:s3:::a-bucket
252 list_of_tags:
253 - condition_type: STRINGEQUALS
254 condition_key: backup
255 condition_value: weekly
256
257 - name: Modify an AWS Backup selection - add list_of_tags (check_mode)
258 amazon.aws.backup_selection: "{{ add_list_of_tags_input }}"
259 check_mode: true
260 register: _result_add_list_of_tags_check_mode
261
262 - name: Verify result
263 ansible.builtin.assert:
264 that:
265 - _result_add_list_of_tags_check_mode.changed
266
267 - name: Get backup selection info
268 amazon.aws.backup_selection_info:
269 backup_plan_name: "{{ backup_plan_name }}"
270 selection_names:
271 - "{{ backup_selection_name }}"
272 register: _result_backup_selection_info
273
274 - name: Verify list_of_tags was not added in check mode
275 ansible.builtin.assert:
276 that:
277 - _result_backup_selection_info.backup_selections[0].selection_name == backup_selection_name
278 - _result_backup_selection_info.backup_selections[0].list_of_tags == []
279
280 - name: Modify an AWS Backup selection - add list_of_tags
281 amazon.aws.backup_selection: "{{ add_list_of_tags_input }}"
282 register: _result_add_list_of_tags
283
284 - name: Verify result
285 ansible.builtin.assert:
286 that:
287 - _result_add_list_of_tags.changed
288
289 - name: Modify an AWS Backup selection - add list_of_tags (idempotency)
290 amazon.aws.backup_selection: "{{ add_list_of_tags_input }}"
291 register: _result_add_list_of_tags_idempotency
292
293 - name: Verify result
294 ansible.builtin.assert:
295 that:
296 - not _result_add_list_of_tags_idempotency.changed
297
298 - name: Get backup selection info
299 amazon.aws.backup_selection_info:
300 backup_plan_name: "{{ backup_plan_name }}"
301 selection_names:
302 - "{{ backup_selection_name }}"
303 register: _result_backup_selection_info
304
305 - name: Verify add_list_of_tags was added
306 ansible.builtin.assert:
307 that:
308 - _result_backup_selection_info.backup_selections[0].iam_role_arn == iam_role.iam_role.arn
309 - _result_backup_selection_info.backup_selections[0].selection_name == backup_selection_name
310 - _result_backup_selection_info.backup_selections[0].resources == [ 'arn:aws:s3:::a-bucket']
311 - _result_backup_selection_info.backup_selections[0].not_resources == []
312 - _result_backup_selection_info.backup_selections[0].list_of_tags[0].condition_value == "weekly"
313 - _result_backup_selection_info.backup_selections[0].conditions.string_not_equals == []
314
315 # Add conditions
316 # ------------------------------------------------------------
317
318 - name: Set input variable for add conditions tests
319 ansible.builtin.set_fact:
320 add_conditions_input:
321 selection_name: "{{ backup_selection_name }}"
322 backup_plan_name: "{{ backup_plan_name }}"
323 iam_role_arn: "{{ iam_role.iam_role.arn }}"
324 resources:
325 - arn:aws:s3:::a-bucket
326 list_of_tags:
327 - condition_type: STRINGEQUALS
328 condition_key: backup
329 condition_value: weekly
330 conditions:
331 string_not_equals:
332 - condition_key: aws:ResourceTag/environment
333 condition_value: dev
334
335 - name: Modify an AWS Backup selection - add conditions (check_mode)
336 amazon.aws.backup_selection: "{{ add_conditions_input }}"
337 check_mode: true
338 register: _result_add_conditions_check_mode
339
340 - name: Verify result
341 ansible.builtin.assert:
342 that:
343 - _result_add_conditions_check_mode.changed
344
345 - name: Get backup selection info
346 amazon.aws.backup_selection_info:
347 backup_plan_name: "{{ backup_plan_name }}"
348 selection_names:
349 - "{{ backup_selection_name }}"
350 register: _result_backup_selection_info
351
352 - name: Verify backup selection conditions were not added in check mode
353 ansible.builtin.assert:
354 that:
355 - _result_backup_selection_info.backup_selections[0].selection_name == backup_selection_name
356 - _result_backup_selection_info.backup_selections[0].conditions.string_not_equals == []
357
358 - name: Modify an AWS Backup selection - add conditions
359 amazon.aws.backup_selection: "{{ add_conditions_input }}"
360 register: _result_add_conditions
361
362 - name: Verify result
363 ansible.builtin.assert:
364 that:
365 - _result_add_conditions.changed
366
367 - name: Modify an AWS Backup selection - add conditions (idempotency)
368 amazon.aws.backup_selection: "{{ add_conditions_input }}"
369 register: _result_add_conditions_idempotency
370
371 - name: Verify result
372 ansible.builtin.assert:
373 that:
374 - not _result_add_conditions_idempotency.changed
375
376 - name: Get backup selection info
377 amazon.aws.backup_selection_info:
378 backup_plan_name: "{{ backup_plan_name }}"
379 selection_names:
380 - "{{ backup_selection_name }}"
381 register: _result_backup_selection_info
382
383 - name: Verify that selection conditions were added
384 ansible.builtin.assert:
385 that:
386 - _result_backup_selection_info.backup_selections[0].iam_role_arn == iam_role.iam_role.arn
387 - _result_backup_selection_info.backup_selections[0].selection_name == backup_selection_name
388 - _result_backup_selection_info.backup_selections[0].resources == ['arn:aws:s3:::a-bucket']
389 - _result_backup_selection_info.backup_selections[0].not_resources == []
390 - _result_backup_selection_info.backup_selections[0].list_of_tags[0].condition_value == "weekly"
391 - _result_backup_selection_info.backup_selections[0].conditions.string_not_equals[0].condition_value == "dev"
392
393 # Update all options
394 # ------------------------------------------------------------
395
396 - name: Set input variable for update all options tests
397 ansible.builtin.set_fact:
398 update_all_options_input:
399 selection_name: "{{ backup_selection_name }}"
400 backup_plan_name: "{{ backup_plan_name }}"
401 iam_role_arn: "{{ iam_role.iam_role.arn }}"
402 resources:
403 - arn:aws:s3:::another-bucket
404 not_resources:
405 - arn:aws:s3:::a-bucket
406 list_of_tags:
407 - condition_type: STRINGEQUALS
408 condition_key: backup
409 condition_value: daily
410 conditions:
411 string_not_equals:
412 - condition_key: aws:ResourceTag/environment
413 condition_value: test
414
415 - name: Modify an AWS Backup selection - update all options (check_mode)
416 amazon.aws.backup_selection: "{{ update_all_options_input }}"
417 check_mode: true
418 register: _result_update_all_options_check_mode
419
420 - name: Verify result
421 ansible.builtin.assert:
422 that:
423 - _result_update_all_options_check_mode.changed
424
425 - name: Get backup selection info
426 amazon.aws.backup_selection_info:
427 backup_plan_name: "{{ backup_plan_name }}"
428 selection_names:
429 - "{{ backup_selection_name }}"
430 register: _result_backup_selection_info
431
432 - name: Verify backup selection options were not updated in check mode
433 ansible.builtin.assert:
434 that:
435 - _result_backup_selection_info.backup_selections[0].selection_name == backup_selection_name
436 - _result_backup_selection_info.backup_selections[0].resources == ['arn:aws:s3:::a-bucket']
437 - _result_backup_selection_info.backup_selections[0].not_resources == []
438 - _result_backup_selection_info.backup_selections[0].list_of_tags[0].condition_value == "weekly"
439 - _result_backup_selection_info.backup_selections[0].conditions.string_not_equals[0].condition_value == "dev"
440
441 - name: Modify an AWS Backup selection - update all options
442 amazon.aws.backup_selection: "{{ update_all_options_input }}"
443 register: _result_update_all_options
444
445 - name: Verify result
446 ansible.builtin.assert:
447 that:
448 - _result_update_all_options.changed
449
450 - name: Modify an AWS Backup selection - update_all_options (idempotency)
451 amazon.aws.backup_selection: "{{ update_all_options_input }}"
452 register: _result_update_all_options_idempotency
453
454 - name: Verify result
455 ansible.builtin.assert:
456 that:
457 - not _result_update_all_options_idempotency.changed
458
459 - name: Get backup selection info
460 amazon.aws.backup_selection_info:
461 backup_plan_name: "{{ backup_plan_name }}"
462 selection_names:
463 - "{{ backup_selection_name }}"
464 register: _result_backup_selection_info
465
466 - name: Verify that all options were updated
467 ansible.builtin.assert:
468 that:
469 - _result_backup_selection_info.backup_selections[0].iam_role_arn == iam_role.iam_role.arn
470 - _result_backup_selection_info.backup_selections[0].selection_name == backup_selection_name
471 - _result_backup_selection_info.backup_selections[0].resources == ['arn:aws:s3:::another-bucket']
472 - _result_backup_selection_info.backup_selections[0].not_resources == ['arn:aws:s3:::a-bucket']
473 - _result_backup_selection_info.backup_selections[0].list_of_tags[0].condition_value == "daily"
474 - _result_backup_selection_info.backup_selections[0].conditions.string_not_equals[0].condition_value == "test"
475
476 # Remove list_of_tags
477 # ------------------------------------------------------------
478
479 - name: Set input variable for remove list_of_tags tests
480 ansible.builtin.set_fact:
481 remove_list_of_tags_input:
482 selection_name: "{{ backup_selection_name }}"
483 backup_plan_name: "{{ backup_plan_name }}"
484 iam_role_arn: "{{ iam_role.iam_role.arn }}"
485 resources:
486 - arn:aws:s3:::another-bucket
487 not_resources:
488 - arn:aws:s3:::a-bucket
489 conditions:
490 string_not_equals:
491 - condition_key: aws:ResourceTag/environment
492 condition_value: test
493
494 - name: Modify an AWS Backup selection - remove list_of_tags (check_mode)
495 amazon.aws.backup_selection: "{{ remove_list_of_tags_input }}"
496 check_mode: true
497 register: _result_remove_list_of_tags_check_mode
498
499 - name: Verify result
500 ansible.builtin.assert:
501 that:
502 - _result_remove_list_of_tags_check_mode.changed
503
504 - name: Get backup selection info
505 amazon.aws.backup_selection_info:
506 backup_plan_name: "{{ backup_plan_name }}"
507 selection_names:
508 - "{{ backup_selection_name }}"
509 register: _result_backup_selection_info
510
511 - name: Verify list_of_tags was not removed in check mode
512 ansible.builtin.assert:
513 that:
514 - _result_backup_selection_info.backup_selections[0].selection_name == backup_selection_name
515 - _result_backup_selection_info.backup_selections[0].resources == ['arn:aws:s3:::another-bucket']
516 - _result_backup_selection_info.backup_selections[0].not_resources == ['arn:aws:s3:::a-bucket']
517 - _result_backup_selection_info.backup_selections[0].list_of_tags [0].condition_value == "daily"
518 - _result_backup_selection_info.backup_selections[0].conditions.string_not_equals[0].condition_value == "test"
519
520 - name: Modify an AWS Backup selection - remove list_of_tags
521 amazon.aws.backup_selection: "{{ remove_list_of_tags_input }}"
522 register: _result_remove_list_of_tags
523
524 - name: Verify result
525 ansible.builtin.assert:
526 that:
527 - _result_remove_list_of_tags.changed
528
529 - name: Modify an AWS Backup selection - remove list_of_tags (idempotency)
530 amazon.aws.backup_selection: "{{ remove_list_of_tags_input }}"
531 register: _result_remove_list_of_tags_idempotency
532
533 - name: Verify result
534 ansible.builtin.assert:
535 that:
536 - not _result_remove_list_of_tags_idempotency.changed
537
538 - name: Get backup selection info
539 amazon.aws.backup_selection_info:
540 backup_plan_name: "{{ backup_plan_name }}"
541 selection_names:
542 - "{{ backup_selection_name }}"
543 register: _result_backup_selection_info
544
545 - name: Verify result
546 ansible.builtin.assert:
547 that:
548 - _result_backup_selection_info.backup_selections[0].iam_role_arn == iam_role.iam_role.arn
549 - _result_backup_selection_info.backup_selections[0].selection_name == backup_selection_name
550 - _result_backup_selection_info.backup_selections[0].resources == ['arn:aws:s3:::another-bucket']
551 - _result_backup_selection_info.backup_selections[0].not_resources == ['arn:aws:s3:::a-bucket']
552 - _result_backup_selection_info.backup_selections[0].list_of_tags == []
553 - _result_backup_selection_info.backup_selections[0].conditions.string_not_equals[0].condition_value == "test"
554
555 # Remove conditions
556 # ------------------------------------------------------------
557
558 - name: Set input variable for remove conditions tests
559 ansible.builtin.set_fact:
560 remove_conditions_input:
561 selection_name: "{{ backup_selection_name }}"
562 backup_plan_name: "{{ backup_plan_name }}"
563 iam_role_arn: "{{ iam_role.iam_role.arn }}"
564 resources:
565 - arn:aws:s3:::another-bucket
566 not_resources:
567 - arn:aws:s3:::a-bucket
568
569 - name: Modify an AWS Backup selection - remove conditions (check_mode)
570 amazon.aws.backup_selection: "{{ remove_conditions_input }}"
571 check_mode: true
572 register: _result_remove_conditions_check_mode
573
574 - name: Verify result
575 ansible.builtin.assert:
576 that:
577 - _result_remove_conditions_check_mode.changed
578
579 - name: Get backup selection info
580 amazon.aws.backup_selection_info:
581 backup_plan_name: "{{ backup_plan_name }}"
582 selection_names:
583 - "{{ backup_selection_name }}"
584 register: _result_backup_selection_info
585
586 - name: Verify conditions were not removed in check mode
587 ansible.builtin.assert:
588 that:
589 - _result_backup_selection_info.backup_selections[0].selection_name == backup_selection_name
590 - _result_backup_selection_info.backup_selections[0].resources == ['arn:aws:s3:::another-bucket']
591 - _result_backup_selection_info.backup_selections[0].not_resources == ['arn:aws:s3:::a-bucket']
592 - _result_backup_selection_info.backup_selections[0].list_of_tags == []
593 - _result_backup_selection_info.backup_selections[0].conditions.string_not_equals[0].condition_value == "test"
594
595 - name: Modify an AWS Backup selection - remove conditions
596 amazon.aws.backup_selection: "{{ remove_conditions_input }}"
597 register: _result_remove_conditions
598
599 - name: Verify result
600 ansible.builtin.assert:
601 that:
602 - _result_remove_conditions.changed
603
604 - name: Modify an AWS Backup selection - remove conditions (idempotency)
605 amazon.aws.backup_selection: "{{ remove_conditions_input }}"
606 register: _result_remove_conditions_idempotency
607
608 - name: Verify result
609 ansible.builtin.assert:
610 that:
611 - not _result_remove_conditions_idempotency.changed
612
613 - name: Get backup selection info
614 amazon.aws.backup_selection_info:
615 backup_plan_name: "{{ backup_plan_name }}"
616 selection_names:
617 - "{{ backup_selection_name }}"
618 register: _result_backup_selection_info
619
620 - name: Verify conditions were removed
621 ansible.builtin.assert:
622 that:
623 - _result_backup_selection_info.backup_selections[0].iam_role_arn == iam_role.iam_role.arn
624 - _result_backup_selection_info.backup_selections[0].selection_name == backup_selection_name
625 - _result_backup_selection_info.backup_selections[0].resources == ['arn:aws:s3:::another-bucket']
626 - _result_backup_selection_info.backup_selections[0].not_resources == ['arn:aws:s3:::a-bucket']
627 - _result_backup_selection_info.backup_selections[0].list_of_tags == []
628 - _result_backup_selection_info.backup_selections[0].conditions.string_not_equals == []
629
630 # ============================================================
631 # List Selection Tests
632 # ============================================================
633
634 - name: List all AWS Backup selections
635 amazon.aws.backup_selection_info:
636 backup_plan_name: "{{ backup_plan_name }}"
637 register: _result_backup_selection_list
638
639 - name: Verify result
640 ansible.builtin.assert:
641 that:
642 - "'backup_selections' in _result_backup_selection_list"
643 - _result_backup_selection_list.backup_selections | length == 2
644
645 # ============================================================
646 # Delete Selection Tests
647 # ============================================================
648
649 - name: Set input variable for delete selection tests
650 ansible.builtin.set_fact:
651 delete_selection_input:
652 selection_name: "{{ backup_selection_name }}"
653 backup_plan_name: "{{ backup_plan_name }}"
654 state: absent
655
656 - name: Delete AWS Backup selection (check_mode)
657 amazon.aws.backup_selection: "{{ delete_selection_input }}"
658 check_mode: true
659 register: _delete_result_backup_selection_check_mode
660
661 - name: Verify result
662 ansible.builtin.assert:
663 that:
664 - _delete_result_backup_selection_check_mode.changed
665 - not _delete_result_backup_selection_check_mode.exists
666 - "'backup_selection' in _delete_result_backup_selection_check_mode"
667 - _delete_result_backup_selection_check_mode.msg == "Would have deleted backup selection if not in check mode"
668
669 - name: Get backup selection info
670 amazon.aws.backup_selection_info:
671 backup_plan_name: "{{ backup_plan_name }}"
672 selection_names:
673 - "{{ backup_selection_name }}"
674 register: _result_backup_selection_info
675
676 - name: Verify backup selection was not deleted in check mode
677 ansible.builtin.assert:
678 that:
679 - _result_backup_selection_info.backup_selections | length == 1
680 - _result_backup_selection_info.backup_selections[0].selection_name == backup_selection_name
681
682 - name: Delete AWS Backup selection
683 amazon.aws.backup_selection: "{{ delete_selection_input }}"
684 register: _delete_result_backup_selection
685
686 - name: Verify result
687 ansible.builtin.assert:
688 that:
689 - _delete_result_backup_selection.changed
690 - not _delete_result_backup_selection.exists
691 - "'backup_selection' in _delete_result_backup_selection"
692
693 - name: Get backup selection info
694 amazon.aws.backup_selection_info:
695 backup_plan_name: "{{ backup_plan_name }}"
696 selection_names:
697 - "{{ backup_selection_name }}"
698 register: _deleted_backup_selection_info
699
700 - name: Verify backup selection was deleted
701 ansible.builtin.assert:
702 that:
703 - _deleted_backup_selection_info.backup_selections | length == 0
704
705 - name: Delete AWS Backup selection (idempotency)
706 amazon.aws.backup_selection: "{{ delete_selection_input }}"
707 register: _delete_result_backup_selection_idempotency
708
709 - name: Verify result
710 ansible.builtin.assert:
711 that:
712 - not _delete_result_backup_selection_idempotency.changed
713 - not _delete_result_backup_selection_idempotency.exists
714 - "'backup_selection' in _delete_result_backup_selection_idempotency"
715
716 # ============================================================
717 # Teardown
718 # ============================================================
719
720 always:
721 - name: Delete minimal AWS Backup selection created during this test
722 amazon.aws.backup_selection:
723 backup_selection_name: "{{ backup_selection_name }}"
724 backup_plan_name: "{{ backup_plan_name }}"
725 state: absent
726 ignore_errors: true
727
728 - name: Delete all options AWS Backup selection created during this test
729 amazon.aws.backup_selection:
730 backup_selection_name: all-options-{{ backup_selection_name }}
731 backup_plan_name: "{{ backup_plan_name }}"
732 state: absent
733 ignore_errors: true
734
735 - name: Delete AWS Backup plan created during this test
736 amazon.aws.backup_plan:
737 backup_plan_name: "{{ backup_plan_name }}"
738 state: absent
739 ignore_errors: true
740
741 - name: Delete AWS Backup vault created during this test
742 amazon.aws.backup_vault:
743 backup_vault_name: "{{ backup_vault_name }}"
744 state: absent
745 ignore_errors: true
746
747 - name: Delete IAM role created during this test
748 amazon.aws.iam_role:
749 name: "{{ backup_iam_role_name }}"
750 state: absent
751 ignore_errors: true