Debian Codegraph @

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

raw
1 ---
2 - module_defaults:
3 group/aws:
4 region: "{{ aws_region }}"
5 access_key: "{{ aws_access_key }}"
6 secret_key: "{{ aws_secret_key }}"
7 session_token: "{{ security_token | default(omit) }}"
8
9 block:
10 - name: Create a source mariadb instance
11 amazon.aws.rds_instance:
12 id: "{{ instance_id }}"
13 state: present
14 engine: "{{ engine }}"
15 engine_version: "{{ mariadb_engine_version }}"
16 allow_major_version_upgrade: true
17 username: "{{ username }}"
18 password: "{{ password }}"
19 db_instance_class: "{{ db_instance_class }}"
20 allocated_storage: "{{ allocated_storage }}"
21 register: _result_create_instance
22
23 - ansible.builtin.assert:
24 that:
25 - _result_create_instance.changed
26 - _result_create_instance.db_instance_identifier == instance_id
27
28 - name: Get all RDS snapshots for the existing instance
29 amazon.aws.rds_snapshot_info:
30 db_instance_identifier: "{{ instance_id }}"
31 register: _result_instance_snapshot_info
32
33 - ansible.builtin.assert:
34 that:
35 - _result_instance_snapshot_info is successful
36 - _result_instance_snapshot_info.snapshots | length == 1
37
38 - name: Take a snapshot of the existing RDS instance (CHECK_MODE)
39 amazon.aws.rds_instance_snapshot:
40 state: present
41 db_instance_identifier: "{{ instance_id }}"
42 db_snapshot_identifier: "{{ snapshot_id }}"
43 check_mode: true
44 register: _result_instance_snapshot
45
46 - ansible.builtin.assert:
47 that:
48 - _result_instance_snapshot.changed
49
50 - name: Take a snapshot of the existing RDS instance
51 amazon.aws.rds_instance_snapshot:
52 state: present
53 db_instance_identifier: "{{ instance_id }}"
54 db_snapshot_identifier: "{{ snapshot_id }}"
55 wait: true
56 register: _result_instance_snapshot
57
58 - ansible.builtin.assert:
59 that:
60 - _result_instance_snapshot.changed
61 - "'availability_zone' in _result_instance_snapshot"
62 - "'instance_create_time' in _result_instance_snapshot"
63 - "'db_instance_identifier' in _result_instance_snapshot"
64 - _result_instance_snapshot.db_instance_identifier == instance_id
65 - "'db_snapshot_identifier' in _result_instance_snapshot"
66 - _result_instance_snapshot.db_snapshot_identifier == snapshot_id
67 - "'db_snapshot_arn' in _result_instance_snapshot"
68 - "'dbi_resource_id' in _result_instance_snapshot"
69 - "'encrypted' in _result_instance_snapshot"
70 - "'engine' in _result_instance_snapshot"
71 - _result_instance_snapshot.engine == engine
72 - "'engine_version' in _result_instance_snapshot"
73 - _result_instance_snapshot.engine_version == mariadb_engine_version
74 - "'iam_database_authentication_enabled' in _result_instance_snapshot"
75 - "'license_model' in _result_instance_snapshot"
76 - "'master_username' in _result_instance_snapshot"
77 - _result_instance_snapshot.master_username == username
78 - "'snapshot_create_time' in _result_instance_snapshot"
79 - "'snapshot_type' in _result_instance_snapshot"
80 - "'status' in _result_instance_snapshot"
81 - _result_instance_snapshot.status == "available"
82 - "'snapshot_type' in _result_instance_snapshot"
83 - _result_instance_snapshot.snapshot_type == "manual"
84 - "'status' in _result_instance_snapshot"
85 - "'storage_type' in _result_instance_snapshot"
86 - _result_instance_snapshot.storage_type == "gp2"
87 - "'tags' in _result_instance_snapshot"
88 - "'vpc_id' in _result_instance_snapshot"
89
90 - name: Take a snapshot of the existing RDS instance (CHECK_MODE - IDEMPOTENCE)
91 amazon.aws.rds_instance_snapshot:
92 state: present
93 db_instance_identifier: "{{ instance_id }}"
94 db_snapshot_identifier: "{{ snapshot_id }}"
95 check_mode: true
96 register: _result_instance_snapshot
97
98 - ansible.builtin.assert:
99 that:
100 - not _result_instance_snapshot.changed
101
102 - name: Take a snapshot of the existing RDS instance (IDEMPOTENCE)
103 amazon.aws.rds_instance_snapshot:
104 state: present
105 db_instance_identifier: "{{ instance_id }}"
106 db_snapshot_identifier: "{{ snapshot_id }}"
107 wait: true
108 register: _result_instance_snapshot
109
110 - ansible.builtin.assert:
111 that:
112 - not _result_instance_snapshot.changed
113 - "'availability_zone' in _result_instance_snapshot"
114 - "'instance_create_time' in _result_instance_snapshot"
115 - "'db_instance_identifier' in _result_instance_snapshot"
116 - _result_instance_snapshot.db_instance_identifier == instance_id
117 - "'db_snapshot_identifier' in _result_instance_snapshot"
118 - _result_instance_snapshot.db_snapshot_identifier == snapshot_id
119 - "'db_snapshot_arn' in _result_instance_snapshot"
120 - "'dbi_resource_id' in _result_instance_snapshot"
121 - "'encrypted' in _result_instance_snapshot"
122 - "'engine' in _result_instance_snapshot"
123 - _result_instance_snapshot.engine == engine
124 - "'engine_version' in _result_instance_snapshot"
125 - _result_instance_snapshot.engine_version == mariadb_engine_version
126 - "'iam_database_authentication_enabled' in _result_instance_snapshot"
127 - "'license_model' in _result_instance_snapshot"
128 - "'master_username' in _result_instance_snapshot"
129 - _result_instance_snapshot.master_username == username
130 - "'snapshot_create_time' in _result_instance_snapshot"
131 - "'snapshot_type' in _result_instance_snapshot"
132 - "'status' in _result_instance_snapshot"
133 - _result_instance_snapshot.status == "available"
134 - "'snapshot_type' in _result_instance_snapshot"
135 - _result_instance_snapshot.snapshot_type == "manual"
136 - "'status' in _result_instance_snapshot"
137 - "'storage_type' in _result_instance_snapshot"
138 - _result_instance_snapshot.storage_type == "gp2"
139 - "'tags' in _result_instance_snapshot"
140 - "'vpc_id' in _result_instance_snapshot"
141
142 - name: Get information about the existing DB snapshot
143 amazon.aws.rds_snapshot_info:
144 db_snapshot_identifier: "{{ snapshot_id }}"
145 register: _result_instance_snapshot_info
146
147 - ansible.builtin.assert:
148 that:
149 - _result_instance_snapshot_info is successful
150 - _result_instance_snapshot_info.snapshots[0].db_instance_identifier == instance_id
151 - _result_instance_snapshot_info.snapshots[0].db_snapshot_identifier == snapshot_id
152
153 - name: Take another snapshot of the existing RDS instance
154 amazon.aws.rds_instance_snapshot:
155 state: present
156 db_instance_identifier: "{{ instance_id }}"
157 db_snapshot_identifier: "{{ snapshot_id }}-b"
158 wait: true
159 register: _result_instance_snapshot
160
161 - ansible.builtin.assert:
162 that:
163 - _result_instance_snapshot.changed
164 - "'availability_zone' in _result_instance_snapshot"
165 - "'instance_create_time' in _result_instance_snapshot"
166 - "'db_instance_identifier' in _result_instance_snapshot"
167 - _result_instance_snapshot.db_instance_identifier == instance_id
168 - "'db_snapshot_identifier' in _result_instance_snapshot"
169 - _result_instance_snapshot.db_snapshot_identifier == snapshot_id+"-b"
170 - "'db_snapshot_arn' in _result_instance_snapshot"
171 - "'dbi_resource_id' in _result_instance_snapshot"
172 - "'encrypted' in _result_instance_snapshot"
173 - "'engine' in _result_instance_snapshot"
174 - _result_instance_snapshot.engine == engine
175 - "'engine_version' in _result_instance_snapshot"
176 - _result_instance_snapshot.engine_version == mariadb_engine_version
177 - "'iam_database_authentication_enabled' in _result_instance_snapshot"
178 - "'license_model' in _result_instance_snapshot"
179 - "'master_username' in _result_instance_snapshot"
180 - _result_instance_snapshot.master_username == username
181 - "'snapshot_create_time' in _result_instance_snapshot"
182 - "'snapshot_type' in _result_instance_snapshot"
183 - "'status' in _result_instance_snapshot"
184 - _result_instance_snapshot.status == "available"
185 - "'snapshot_type' in _result_instance_snapshot"
186 - _result_instance_snapshot.snapshot_type == "manual"
187 - "'status' in _result_instance_snapshot"
188 - "'storage_type' in _result_instance_snapshot"
189 - _result_instance_snapshot.storage_type == "gp2"
190 - "'tags' in _result_instance_snapshot"
191 - "'vpc_id' in _result_instance_snapshot"
192
193 - name: Get all snapshots for the existing RDS instance
194 amazon.aws.rds_snapshot_info:
195 db_instance_identifier: "{{ instance_id }}"
196 register: _result_instance_snapshot_info
197
198 - ansible.builtin.assert:
199 that:
200 - _result_instance_snapshot_info is successful
201 # - _result_instance_snapshot_info.cluster_snapshots | length == 3
202
203 - name: Delete existing DB instance snapshot (CHECK_MODE)
204 amazon.aws.rds_instance_snapshot:
205 state: absent
206 db_snapshot_identifier: "{{ snapshot_id }}-b"
207 register: _result_delete_snapshot
208 check_mode: true
209
210 - ansible.builtin.assert:
211 that:
212 - _result_delete_snapshot.changed
213
214 - name: Delete the existing DB instance snapshot
215 amazon.aws.rds_instance_snapshot:
216 state: absent
217 db_snapshot_identifier: "{{ snapshot_id }}-b"
218 register: _result_delete_snapshot
219
220 - ansible.builtin.assert:
221 that:
222 - _result_delete_snapshot.changed
223
224 - name: Delete existing DB instance snapshot (CHECK_MODE - IDEMPOTENCE)
225 amazon.aws.rds_instance_snapshot:
226 state: absent
227 db_snapshot_identifier: "{{ snapshot_id }}-b"
228 register: _result_delete_snapshot
229 check_mode: true
230
231 - ansible.builtin.assert:
232 that:
233 - not _result_delete_snapshot.changed
234
235 - name: Delete the existing DB instance snapshot (IDEMPOTENCE)
236 amazon.aws.rds_instance_snapshot:
237 state: absent
238 db_snapshot_identifier: "{{ snapshot_id }}-b"
239 register: _result_delete_snapshot
240
241 - ansible.builtin.assert:
242 that:
243 - not _result_delete_snapshot.changed
244
245 - name: Take another snapshot of the existing RDS instance and assign tags
246 amazon.aws.rds_instance_snapshot:
247 state: present
248 db_instance_identifier: "{{ instance_id }}"
249 db_snapshot_identifier: "{{ snapshot_id }}-b"
250 wait: true
251 tags:
252 tag_one: "{{ snapshot_id }}-b One"
253 Tag Two: two {{ snapshot_id }}-b
254 register: _result_instance_snapshot
255
256 - ansible.builtin.assert:
257 that:
258 - _result_instance_snapshot.changed
259 - "'availability_zone' in _result_instance_snapshot"
260 - "'instance_create_time' in _result_instance_snapshot"
261 - "'db_instance_identifier' in _result_instance_snapshot"
262 - _result_instance_snapshot.db_instance_identifier == instance_id
263 - "'db_snapshot_identifier' in _result_instance_snapshot"
264 - _result_instance_snapshot.db_snapshot_identifier == snapshot_id+"-b"
265 - "'db_snapshot_arn' in _result_instance_snapshot"
266 - "'dbi_resource_id' in _result_instance_snapshot"
267 - "'encrypted' in _result_instance_snapshot"
268 - "'engine' in _result_instance_snapshot"
269 - _result_instance_snapshot.engine == engine
270 - "'engine_version' in _result_instance_snapshot"
271 - _result_instance_snapshot.engine_version == mariadb_engine_version
272 - "'iam_database_authentication_enabled' in _result_instance_snapshot"
273 - "'license_model' in _result_instance_snapshot"
274 - "'master_username' in _result_instance_snapshot"
275 - _result_instance_snapshot.master_username == username
276 - "'snapshot_create_time' in _result_instance_snapshot"
277 - "'snapshot_type' in _result_instance_snapshot"
278 - "'status' in _result_instance_snapshot"
279 - _result_instance_snapshot.status == "available"
280 - "'snapshot_type' in _result_instance_snapshot"
281 - _result_instance_snapshot.snapshot_type == "manual"
282 - "'status' in _result_instance_snapshot"
283 - "'storage_type' in _result_instance_snapshot"
284 - _result_instance_snapshot.storage_type == "gp2"
285 - "'tags' in _result_instance_snapshot"
286 - _result_instance_snapshot.tags | length == 2
287 - _result_instance_snapshot.tags["tag_one"] == snapshot_id+"-b One"
288 - _result_instance_snapshot.tags["Tag Two"] == "two "+snapshot_id +"-b"
289 - "'vpc_id' in _result_instance_snapshot"
290
291 - name: Attempt to take another snapshot of the existing RDS instance and assign tags (idempotence)
292 amazon.aws.rds_instance_snapshot:
293 state: present
294 db_instance_identifier: "{{ instance_id }}"
295 db_snapshot_identifier: "{{ snapshot_id }}-b"
296 wait: true
297 tags:
298 tag_one: "{{ snapshot_id }}-b One"
299 Tag Two: two {{ snapshot_id }}-b
300 register: _result_instance_snapshot
301
302 - ansible.builtin.assert:
303 that:
304 - not _result_instance_snapshot.changed
305
306 - name: Take another snapshot of the existing RDS instance and update tags
307 amazon.aws.rds_instance_snapshot:
308 state: present
309 db_instance_identifier: "{{ instance_id }}"
310 db_snapshot_identifier: "{{ snapshot_id }}-b"
311 tags:
312 tag_three: "{{ snapshot_id }}-b Three"
313 Tag Two: two {{ snapshot_id }}-b
314 register: _result_instance_snapshot
315
316 - ansible.builtin.assert:
317 that:
318 - _result_instance_snapshot.changed
319 - "'availability_zone' in _result_instance_snapshot"
320 - "'instance_create_time' in _result_instance_snapshot"
321 - "'db_instance_identifier' in _result_instance_snapshot"
322 - _result_instance_snapshot.db_instance_identifier == instance_id
323 - "'db_snapshot_identifier' in _result_instance_snapshot"
324 - _result_instance_snapshot.db_snapshot_identifier == snapshot_id+"-b"
325 - "'db_snapshot_arn' in _result_instance_snapshot"
326 - "'dbi_resource_id' in _result_instance_snapshot"
327 - "'encrypted' in _result_instance_snapshot"
328 - "'engine' in _result_instance_snapshot"
329 - _result_instance_snapshot.engine == engine
330 - "'engine_version' in _result_instance_snapshot"
331 - _result_instance_snapshot.engine_version == mariadb_engine_version
332 - "'iam_database_authentication_enabled' in _result_instance_snapshot"
333 - "'license_model' in _result_instance_snapshot"
334 - "'master_username' in _result_instance_snapshot"
335 - _result_instance_snapshot.master_username == username
336 - "'snapshot_create_time' in _result_instance_snapshot"
337 - "'snapshot_type' in _result_instance_snapshot"
338 - "'status' in _result_instance_snapshot"
339 - _result_instance_snapshot.status == "available"
340 - "'snapshot_type' in _result_instance_snapshot"
341 - _result_instance_snapshot.snapshot_type == "manual"
342 - "'status' in _result_instance_snapshot"
343 - "'storage_type' in _result_instance_snapshot"
344 - _result_instance_snapshot.storage_type == "gp2"
345 - "'tags' in _result_instance_snapshot"
346 - _result_instance_snapshot.tags | length == 2
347 - _result_instance_snapshot.tags["tag_three"] == snapshot_id+"-b Three"
348 - _result_instance_snapshot.tags["Tag Two"] == "two "+snapshot_id +"-b"
349 - "'vpc_id' in _result_instance_snapshot"
350
351 - name: Take another snapshot of the existing RDS instance and update tags without purge
352 amazon.aws.rds_instance_snapshot:
353 state: present
354 db_instance_identifier: "{{ instance_id }}"
355 db_snapshot_identifier: "{{ snapshot_id }}-b"
356 purge_tags: false
357 tags:
358 tag_one: "{{ snapshot_id }}-b One"
359 register: _result_instance_snapshot
360
361 - ansible.builtin.assert:
362 that:
363 - _result_instance_snapshot.changed
364 - "'availability_zone' in _result_instance_snapshot"
365 - "'instance_create_time' in _result_instance_snapshot"
366 - "'db_instance_identifier' in _result_instance_snapshot"
367 - _result_instance_snapshot.db_instance_identifier == instance_id
368 - "'db_snapshot_identifier' in _result_instance_snapshot"
369 - _result_instance_snapshot.db_snapshot_identifier == snapshot_id+"-b"
370 - "'db_snapshot_arn' in _result_instance_snapshot"
371 - "'dbi_resource_id' in _result_instance_snapshot"
372 - "'encrypted' in _result_instance_snapshot"
373 - "'engine' in _result_instance_snapshot"
374 - _result_instance_snapshot.engine == engine
375 - "'engine_version' in _result_instance_snapshot"
376 - _result_instance_snapshot.engine_version == mariadb_engine_version
377 - "'iam_database_authentication_enabled' in _result_instance_snapshot"
378 - "'license_model' in _result_instance_snapshot"
379 - "'master_username' in _result_instance_snapshot"
380 - _result_instance_snapshot.master_username == username
381 - "'snapshot_create_time' in _result_instance_snapshot"
382 - "'snapshot_type' in _result_instance_snapshot"
383 - "'status' in _result_instance_snapshot"
384 - _result_instance_snapshot.status == "available"
385 - "'snapshot_type' in _result_instance_snapshot"
386 - _result_instance_snapshot.snapshot_type == "manual"
387 - "'status' in _result_instance_snapshot"
388 - "'storage_type' in _result_instance_snapshot"
389 - _result_instance_snapshot.storage_type == "gp2"
390 - "'tags' in _result_instance_snapshot"
391 - _result_instance_snapshot.tags | length == 3
392 - _result_instance_snapshot.tags["tag_one"] == snapshot_id+"-b One"
393 - _result_instance_snapshot.tags["Tag Two"] == "two "+snapshot_id +"-b"
394 - _result_instance_snapshot.tags["tag_three"] == snapshot_id+"-b Three"
395 - "'vpc_id' in _result_instance_snapshot"
396
397 - name: Take another snapshot of the existing RDS instance and do not specify any tag to ensure previous tags are not removed
398 amazon.aws.rds_instance_snapshot:
399 state: present
400 db_instance_identifier: "{{ instance_id }}"
401 db_snapshot_identifier: "{{ snapshot_id }}-b"
402 register: _result_instance_snapshot
403
404 - ansible.builtin.assert:
405 that:
406 - not _result_instance_snapshot.changed
407
408 # ------------------------------------------------------------------------------------------
409 # Test copying a snapshot
410 ### Note - copying a snapshot from a different region is supported, but not in CI runs,
411 ### because the aws-terminator only terminates resources in one region.
412
413 - ansible.builtin.set_fact:
414 _snapshot_arn: "{{ _result_instance_snapshot.db_snapshot_arn }}"
415
416 - name: Copy a snapshot (check mode)
417 amazon.aws.rds_instance_snapshot:
418 id: "{{ snapshot_id }}-copy"
419 source_id: "{{ snapshot_id }}-b"
420 copy_tags: true
421 wait: true
422 register: _result_instance_snapshot
423 check_mode: true
424
425 - ansible.builtin.assert:
426 that:
427 - _result_instance_snapshot.changed
428
429 - name: Copy a snapshot
430 amazon.aws.rds_instance_snapshot:
431 id: "{{ snapshot_id }}-copy"
432 source_id: "{{ snapshot_id }}-b"
433 copy_tags: true
434 wait: true
435 register: _result_instance_snapshot
436
437 - ansible.builtin.assert:
438 that:
439 - _result_instance_snapshot.changed
440 - _result_instance_snapshot.db_instance_identifier == instance_id
441 - _result_instance_snapshot.source_db_snapshot_identifier == _snapshot_arn
442 - _result_instance_snapshot.db_snapshot_identifier == snapshot_id+"-copy"
443 - "'tags' in _result_instance_snapshot"
444 - _result_instance_snapshot.tags | length == 3
445 - _result_instance_snapshot.tags["tag_one"] == snapshot_id+"-b One"
446 - _result_instance_snapshot.tags["Tag Two"] == "two "+snapshot_id +"-b"
447 - _result_instance_snapshot.tags["tag_three"] == snapshot_id+"-b Three"
448
449 - name: Copy a snapshot (idempotence - check mode)
450 amazon.aws.rds_instance_snapshot:
451 id: "{{ snapshot_id }}-copy"
452 source_id: "{{ snapshot_id }}-b"
453 copy_tags: true
454 wait: true
455 register: _result_instance_snapshot
456 check_mode: true
457
458 - ansible.builtin.assert:
459 that:
460 - not _result_instance_snapshot.changed
461
462 - name: Copy a snapshot (idempotence)
463 amazon.aws.rds_instance_snapshot:
464 id: "{{ snapshot_id }}-copy"
465 source_id: "{{ snapshot_id }}-b"
466 copy_tags: true
467 wait: true
468 register: _result_instance_snapshot
469
470 - ansible.builtin.assert:
471 that:
472 - not _result_instance_snapshot.changed
473 - _result_instance_snapshot.db_instance_identifier == instance_id
474 - _result_instance_snapshot.source_db_snapshot_identifier == _snapshot_arn
475 - _result_instance_snapshot.db_snapshot_identifier == snapshot_id+"-copy"
476 - "'tags' in _result_instance_snapshot"
477 - _result_instance_snapshot.tags | length == 3
478 - _result_instance_snapshot.tags["tag_one"] == snapshot_id+"-b One"
479 - _result_instance_snapshot.tags["Tag Two"] == "two "+snapshot_id +"-b"
480 - _result_instance_snapshot.tags["tag_three"] == snapshot_id+"-b Three"
481
482 always:
483 - name: Delete the existing DB instance snapshots
484 amazon.aws.rds_instance_snapshot:
485 state: absent
486 db_snapshot_identifier: "{{ item }}"
487 wait: false
488 register: _result_delete_snapshot
489 ignore_errors: true
490 loop:
491 - "{{ snapshot_id }}"
492 - "{{ snapshot_id }}-b"
493 - "{{ snapshot_id }}-copy"
494
495 - name: Delete the existing RDS instance without creating a final snapshot
496 amazon.aws.rds_instance:
497 state: absent
498 instance_id: "{{ instance_id }}"
499 skip_final_snapshot: true
500 wait: false
501 register: _result_delete_instance
502 ignore_errors: true