Debian Codegraph @

ansible_collections/amazon/aws/tests/integration/targets/ec2_vpc_subnet/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 block:
9 # ============================================================
10 - name: Create a VPC
11 amazon.aws.ec2_vpc_net:
12 name: "{{ resource_prefix }}-vpc"
13 state: present
14 cidr_block: "{{ vpc_cidr }}"
15 ipv6_cidr: true
16 tags:
17 Name: "{{ resource_prefix }}-vpc"
18 Description: Created by ansible-test
19 register: vpc_result
20
21 - ansible.builtin.set_fact:
22 vpc_ipv6_cidr: "{{ vpc_result.vpc.ipv6_cidr_block_association_set[0].ipv6_cidr_block }}"
23
24 - ansible.builtin.set_fact:
25 subnet_ipv6_cidr: "{{ vpc_ipv6_cidr | regex_replace('::/.*', '::/64') }}"
26
27 # ============================================================
28 - name: Check subnet does not exist
29 amazon.aws.ec2_vpc_subnet_info:
30 filters:
31 tag:Name: "{{ ec2_vpc_subnet_name }}"
32 register: vpc_subnet_info
33
34 - name: Assert info result is zero
35 ansible.builtin.assert:
36 that:
37 - (vpc_subnet_info.subnets|length) == 0
38
39 - name: Create subnet (expected changed=true) (CHECK MODE)
40 amazon.aws.ec2_vpc_subnet:
41 cidr: "{{ subnet_cidr }}"
42 az: "{{ availability_zone }}"
43 vpc_id: "{{ vpc_result.vpc.id }}"
44 tags:
45 Name: "{{ ec2_vpc_subnet_name }}"
46 Description: "{{ ec2_vpc_subnet_description }}"
47 state: present
48 check_mode: true
49 register: vpc_subnet_create
50
51 - name: Assert creation would happen
52 ansible.builtin.assert:
53 that:
54 - vpc_subnet_create is changed
55
56 - name: Create subnet (expected changed=true)
57 amazon.aws.ec2_vpc_subnet:
58 cidr: "{{ subnet_cidr }}"
59 az: "{{ availability_zone }}"
60 vpc_id: "{{ vpc_result.vpc.id }}"
61 tags:
62 Name: "{{ ec2_vpc_subnet_name }}"
63 Description: "{{ ec2_vpc_subnet_description }}"
64 state: present
65 register: vpc_subnet_create
66
67 - name: Assert creation happened (expected changed=true)
68 ansible.builtin.assert:
69 that:
70 - vpc_subnet_create is changed
71 - "'ec2:CreateTags' not in vpc_subnet_create.resource_actions"
72 - "'ec2:DeleteTags' not in vpc_subnet_create.resource_actions"
73 - vpc_subnet_create.subnet.id.startswith("subnet-")
74 - '"Name" in vpc_subnet_create.subnet.tags and vpc_subnet_create.subnet.tags["Name"] == ec2_vpc_subnet_name'
75 - '"Description" in vpc_subnet_create.subnet.tags and vpc_subnet_create.subnet.tags["Description"] == ec2_vpc_subnet_description'
76
77 - name: Get info about the subnet
78 amazon.aws.ec2_vpc_subnet_info:
79 subnet_ids: "{{ vpc_subnet_create.subnet.id }}"
80 register: vpc_subnet_info
81
82 - name: Assert info result matches create result
83 ansible.builtin.assert:
84 that:
85 - vpc_subnet_info.subnets | length == 1
86 - '"assign_ipv6_address_on_creation" in subnet_info'
87 - subnet_info.assign_ipv6_address_on_creation == False
88 - '"availability_zone" in subnet_info'
89 - subnet_info.availability_zone == availability_zone
90 - '"available_ip_address_count" in subnet_info'
91 - '"cidr_block" in subnet_info'
92 - subnet_info.cidr_block == subnet_cidr
93 - '"default_for_az" in subnet_info'
94 - '"id" in subnet_info'
95 - subnet_info.id == vpc_subnet_create.subnet.id
96 - '"map_public_ip_on_launch" in subnet_info'
97 - subnet_info.map_public_ip_on_launch == False
98 - '"state" in subnet_info'
99 - '"subnet_id" in subnet_info'
100 - subnet_info.subnet_id == vpc_subnet_create.subnet.id
101 - '"tags" in subnet_info'
102 - subnet_info.tags["Description"] == ec2_vpc_subnet_description
103 - subnet_info.tags["Name"] == vpc_subnet_create.subnet.tags["Name"]
104 - '"vpc_id" in subnet_info'
105 - subnet_info.vpc_id == vpc_result.vpc.id
106 vars:
107 subnet_info: "{{ vpc_subnet_info.subnets[0] }}"
108
109 # ============================================================
110 - name: Recreate subnet (expected changed=false) (CHECK MODE)
111 amazon.aws.ec2_vpc_subnet:
112 cidr: "{{ subnet_cidr }}"
113 az: "{{ availability_zone }}"
114 vpc_id: "{{ vpc_result.vpc.id }}"
115 tags:
116 Name: "{{ ec2_vpc_subnet_name }}"
117 Description: "{{ ec2_vpc_subnet_description }}"
118 state: present
119 check_mode: true
120 register: vpc_subnet_recreate
121
122 - name: Assert recreation changed nothing (expected changed=false)
123 ansible.builtin.assert:
124 that:
125 - vpc_subnet_recreate is not changed
126
127 - name: Recreate subnet (expected changed=false)
128 amazon.aws.ec2_vpc_subnet:
129 cidr: "{{ subnet_cidr }}"
130 az: "{{ availability_zone }}"
131 vpc_id: "{{ vpc_result.vpc.id }}"
132 tags:
133 Name: "{{ ec2_vpc_subnet_name }}"
134 Description: "{{ ec2_vpc_subnet_description }}"
135 state: present
136 register: vpc_subnet_recreate
137
138 - name: Assert recreation changed nothing (expected changed=false)
139 ansible.builtin.assert:
140 that:
141 - vpc_subnet_recreate is not changed
142 - vpc_subnet_recreate.subnet == vpc_subnet_create.subnet
143
144 # ============================================================
145 - name: Update subnet so instances launched in it are assigned an IP (CHECK MODE)
146 amazon.aws.ec2_vpc_subnet:
147 cidr: "{{ subnet_cidr }}"
148 az: "{{ availability_zone }}"
149 vpc_id: "{{ vpc_result.vpc.id }}"
150 tags:
151 Name: "{{ ec2_vpc_subnet_name }}"
152 Description: "{{ ec2_vpc_subnet_description }}"
153 state: present
154 map_public: true
155 check_mode: true
156 register: vpc_subnet_modify
157
158 - name: Assert subnet changed
159 ansible.builtin.assert:
160 that:
161 - vpc_subnet_modify is changed
162
163 - name: Update subnet so instances launched in it are assigned an IP
164 amazon.aws.ec2_vpc_subnet:
165 cidr: "{{ subnet_cidr }}"
166 az: "{{ availability_zone }}"
167 vpc_id: "{{ vpc_result.vpc.id }}"
168 tags:
169 Name: "{{ ec2_vpc_subnet_name }}"
170 Description: "{{ ec2_vpc_subnet_description }}"
171 state: present
172 map_public: true
173 register: vpc_subnet_modify
174
175 - name: Assert subnet changed
176 ansible.builtin.assert:
177 that:
178 - vpc_subnet_modify is changed
179 - vpc_subnet_modify.subnet.map_public_ip_on_launch
180
181 # ============================================================
182 - name: Add invalid ipv6 block to subnet (expected failed)
183 amazon.aws.ec2_vpc_subnet:
184 cidr: "{{ subnet_cidr }}"
185 az: "{{ availability_zone }}"
186 vpc_id: "{{ vpc_result.vpc.id }}"
187 ipv6_cidr: 2001:db8::/64
188 tags:
189 Name: "{{ ec2_vpc_subnet_name }}"
190 Description: "{{ ec2_vpc_subnet_description }}"
191 state: present
192 register: vpc_subnet_ipv6_failed
193 ignore_errors: true
194
195 - name: Assert failure happened (expected failed)
196 ansible.builtin.assert:
197 that:
198 - vpc_subnet_ipv6_failed is failed
199 - "'Couldn\\'t associate ipv6 cidr' in vpc_subnet_ipv6_failed.msg"
200
201 # ============================================================
202 - name: Add a tag (expected changed=true) (CHECK MODE)
203 amazon.aws.ec2_vpc_subnet:
204 cidr: "{{ subnet_cidr }}"
205 az: "{{ availability_zone }}"
206 vpc_id: "{{ vpc_result.vpc.id }}"
207 tags:
208 Name: "{{ ec2_vpc_subnet_name }}"
209 Description: "{{ ec2_vpc_subnet_description }}"
210 AnotherTag: SomeValue
211 state: present
212 check_mode: true
213 register: vpc_subnet_add_a_tag
214
215 - name: Assert tag addition happened (expected changed=true)
216 ansible.builtin.assert:
217 that:
218 - vpc_subnet_add_a_tag is changed
219
220 - name: Add a tag (expected changed=true)
221 amazon.aws.ec2_vpc_subnet:
222 cidr: "{{ subnet_cidr }}"
223 az: "{{ availability_zone }}"
224 vpc_id: "{{ vpc_result.vpc.id }}"
225 tags:
226 Name: "{{ ec2_vpc_subnet_name }}"
227 Description: "{{ ec2_vpc_subnet_description }}"
228 AnotherTag: SomeValue
229 state: present
230 register: vpc_subnet_add_a_tag
231
232 - name: Assert tag addition happened (expected changed=true)
233 ansible.builtin.assert:
234 that:
235 - vpc_subnet_add_a_tag is changed
236 - '"Name" in vpc_subnet_add_a_tag.subnet.tags and vpc_subnet_add_a_tag.subnet.tags["Name"] == ec2_vpc_subnet_name'
237 - '"Description" in vpc_subnet_add_a_tag.subnet.tags and vpc_subnet_add_a_tag.subnet.tags["Description"] == ec2_vpc_subnet_description'
238 - '"AnotherTag" in vpc_subnet_add_a_tag.subnet.tags and vpc_subnet_add_a_tag.subnet.tags["AnotherTag"] == "SomeValue"'
239
240 - name: Get info by tag
241 amazon.aws.ec2_vpc_subnet_info:
242 filters:
243 tag:Name: "{{ ec2_vpc_subnet_name }}"
244 register: vpc_subnet_info_by_tag
245
246 - name: Assert info matches expected output
247 ansible.builtin.assert:
248 that:
249 - vpc_subnet_info_by_tag.subnets[0].id == vpc_subnet_add_a_tag.subnet.id
250 - (vpc_subnet_info_by_tag.subnets[0].tags|length) == 3
251 - '"Description" in vpc_subnet_info_by_tag.subnets[0].tags and vpc_subnet_info_by_tag.subnets[0].tags["Description"] == ec2_vpc_subnet_description'
252 - '"AnotherTag" in vpc_subnet_info_by_tag.subnets[0].tags and vpc_subnet_info_by_tag.subnets[0].tags["AnotherTag"] == "SomeValue"'
253
254 # ============================================================
255 - name: Remove tags with default purge_tags=true (expected changed=true) (CHECK MODE)
256 amazon.aws.ec2_vpc_subnet:
257 cidr: "{{ subnet_cidr }}"
258 az: "{{ availability_zone }}"
259 vpc_id: "{{ vpc_result.vpc.id }}"
260 tags:
261 AnotherTag: SomeValue
262 state: present
263 check_mode: true
264 register: vpc_subnet_remove_tags
265
266 - name: Assert tag removal happened (expected changed=true)
267 ansible.builtin.assert:
268 that:
269 - vpc_subnet_remove_tags is changed
270
271 - name: Remove tags with default purge_tags=true (expected changed=true)
272 amazon.aws.ec2_vpc_subnet:
273 cidr: "{{ subnet_cidr }}"
274 az: "{{ availability_zone }}"
275 vpc_id: "{{ vpc_result.vpc.id }}"
276 tags:
277 AnotherTag: SomeValue
278 state: present
279 register: vpc_subnet_remove_tags
280
281 - name: Assert tag removal happened (expected changed=true)
282 ansible.builtin.assert:
283 that:
284 - vpc_subnet_remove_tags is changed
285 - '"Name" not in vpc_subnet_remove_tags.subnet.tags'
286 - '"Description" not in vpc_subnet_remove_tags.subnet.tags'
287 - '"AnotherTag" in vpc_subnet_remove_tags.subnet.tags and vpc_subnet_remove_tags.subnet.tags["AnotherTag"] == "SomeValue"'
288
289 - name: Check tags by info
290 amazon.aws.ec2_vpc_subnet_info:
291 subnet_id: "{{ vpc_subnet_remove_tags.subnet.id }}"
292 register: vpc_subnet_info_removed_tags
293
294 - name: Assert info matches expected output
295 ansible.builtin.assert:
296 that:
297 - '"Name" not in vpc_subnet_info_removed_tags.subnets[0].tags'
298 - '"Description" not in vpc_subnet_info_removed_tags.subnets[0].tags'
299 - '"AnotherTag" in vpc_subnet_info_removed_tags.subnets[0].tags and vpc_subnet_info_removed_tags.subnets[0].tags["AnotherTag"] == "SomeValue"'
300
301 # ============================================================
302 - name: Change tags with purge_tags=false (expected changed=true) (CHECK MODE)
303 amazon.aws.ec2_vpc_subnet:
304 cidr: "{{ subnet_cidr }}"
305 az: "{{ availability_zone }}"
306 vpc_id: "{{ vpc_result.vpc.id }}"
307 tags:
308 Name: "{{ ec2_vpc_subnet_name }}"
309 Description: "{{ ec2_vpc_subnet_description }}"
310 state: present
311 purge_tags: false
312 check_mode: true
313 register: vpc_subnet_change_tags
314
315 - name: Assert tag addition happened (expected changed=true)
316 ansible.builtin.assert:
317 that:
318 - vpc_subnet_change_tags is changed
319
320 - name: Change tags with purge_tags=false (expected changed=true)
321 amazon.aws.ec2_vpc_subnet:
322 cidr: "{{ subnet_cidr }}"
323 az: "{{ availability_zone }}"
324 vpc_id: "{{ vpc_result.vpc.id }}"
325 tags:
326 Name: "{{ ec2_vpc_subnet_name }}"
327 Description: "{{ ec2_vpc_subnet_description }}"
328 state: present
329 purge_tags: false
330 register: vpc_subnet_change_tags
331
332 - name: Assert tag addition happened (expected changed=true)
333 ansible.builtin.assert:
334 that:
335 - vpc_subnet_change_tags is changed
336 - '"Name" in vpc_subnet_change_tags.subnet.tags and vpc_subnet_change_tags.subnet.tags["Name"] == ec2_vpc_subnet_name'
337 - '"Description" in vpc_subnet_change_tags.subnet.tags and vpc_subnet_change_tags.subnet.tags["Description"] == ec2_vpc_subnet_description'
338 - '"AnotherTag" in vpc_subnet_change_tags.subnet.tags and vpc_subnet_change_tags.subnet.tags["AnotherTag"] == "SomeValue"'
339
340 # ============================================================
341 - name: Test state=absent (expected changed=true) (CHECK MODE)
342 amazon.aws.ec2_vpc_subnet:
343 cidr: "{{ subnet_cidr }}"
344 vpc_id: "{{ vpc_result.vpc.id }}"
345 state: absent
346 check_mode: true
347 register: result
348
349 - name: Assert state=absent (expected changed=true)
350 ansible.builtin.assert:
351 that:
352 - result is changed
353
354 - name: Test state=absent (expected changed=true)
355 amazon.aws.ec2_vpc_subnet:
356 cidr: "{{ subnet_cidr }}"
357 vpc_id: "{{ vpc_result.vpc.id }}"
358 state: absent
359 register: result
360
361 - name: Assert state=absent (expected changed=true)
362 ansible.builtin.assert:
363 that:
364 - result is changed
365
366 # ============================================================
367 - name: Test state=absent (expected changed=false) (CHECK MODE)
368 amazon.aws.ec2_vpc_subnet:
369 cidr: "{{ subnet_cidr }}"
370 vpc_id: "{{ vpc_result.vpc.id }}"
371 state: absent
372 check_mode: true
373 register: result
374
375 - name: Assert state=absent (expected changed=false)
376 ansible.builtin.assert:
377 that:
378 - result is not changed
379
380 - name: Test state=absent (expected changed=false)
381 amazon.aws.ec2_vpc_subnet:
382 cidr: "{{ subnet_cidr }}"
383 vpc_id: "{{ vpc_result.vpc.id }}"
384 state: absent
385 register: result
386
387 - name: Assert state=absent (expected changed=false)
388 ansible.builtin.assert:
389 that:
390 - result is not changed
391
392 # ============================================================
393 - name: Create subnet without AZ (CHECK MODE)
394 amazon.aws.ec2_vpc_subnet:
395 cidr: "{{ subnet_cidr }}"
396 vpc_id: "{{ vpc_result.vpc.id }}"
397 state: present
398 check_mode: true
399 register: subnet_without_az
400
401 - name: Check that subnet without AZ works fine
402 ansible.builtin.assert:
403 that:
404 - subnet_without_az is changed
405
406 - name: Create subnet without AZ
407 amazon.aws.ec2_vpc_subnet:
408 cidr: "{{ subnet_cidr }}"
409 vpc_id: "{{ vpc_result.vpc.id }}"
410 state: present
411 register: subnet_without_az
412
413 - name: Check that subnet without AZ works fine
414 ansible.builtin.assert:
415 that:
416 - subnet_without_az is changed
417
418 # ============================================================
419 - name: Remove subnet without AZ (CHECK MODE)
420 amazon.aws.ec2_vpc_subnet:
421 cidr: "{{ subnet_cidr }}"
422 vpc_id: "{{ vpc_result.vpc.id }}"
423 state: absent
424 check_mode: true
425 register: result
426
427 - name: Assert state=absent (expected changed=true)
428 ansible.builtin.assert:
429 that:
430 - result is changed
431
432 - name: Remove subnet without AZ
433 amazon.aws.ec2_vpc_subnet:
434 cidr: "{{ subnet_cidr }}"
435 vpc_id: "{{ vpc_result.vpc.id }}"
436 state: absent
437 register: result
438
439 - name: Assert state=absent (expected changed=true)
440 ansible.builtin.assert:
441 that:
442 - result is changed
443
444 # ============================================================
445 - name: Create subnet with IPv6 (expected changed=true) (CHECK MODE)
446 amazon.aws.ec2_vpc_subnet:
447 cidr: "{{ subnet_cidr }}"
448 vpc_id: "{{ vpc_result.vpc.id }}"
449 ipv6_cidr: "{{ subnet_ipv6_cidr }}"
450 assign_instances_ipv6: true
451 state: present
452 tags:
453 Name: "{{ ec2_vpc_subnet_name }}"
454 Description: "{{ ec2_vpc_subnet_description }}"
455 check_mode: true
456 register: vpc_subnet_ipv6_create
457
458 - name: Assert creation with IPv6 happened (expected changed=true)
459 ansible.builtin.assert:
460 that:
461 - vpc_subnet_ipv6_create is changed
462
463 - name: Create subnet with IPv6 (expected changed=true)
464 amazon.aws.ec2_vpc_subnet:
465 cidr: "{{ subnet_cidr }}"
466 vpc_id: "{{ vpc_result.vpc.id }}"
467 ipv6_cidr: "{{ subnet_ipv6_cidr }}"
468 assign_instances_ipv6: true
469 state: present
470 tags:
471 Name: "{{ ec2_vpc_subnet_name }}"
472 Description: "{{ ec2_vpc_subnet_description }}"
473 register: vpc_subnet_ipv6_create
474
475 - name: Assert creation with IPv6 happened (expected changed=true)
476 ansible.builtin.assert:
477 that:
478 - vpc_subnet_ipv6_create is changed
479 - vpc_subnet_ipv6_create.subnet.id.startswith("subnet-")
480 - vpc_subnet_ipv6_create.subnet.ipv6_cidr_block == subnet_ipv6_cidr
481 - '"Name" in vpc_subnet_ipv6_create.subnet.tags and vpc_subnet_ipv6_create.subnet.tags["Name"] == ec2_vpc_subnet_name'
482 - '"Description" in vpc_subnet_ipv6_create.subnet.tags and vpc_subnet_ipv6_create.subnet.tags["Description"] == ec2_vpc_subnet_description'
483 - vpc_subnet_ipv6_create.subnet.assign_ipv6_address_on_creation
484
485 # ============================================================
486 - name: Recreate subnet (expected changed=false) (CHECK MODE)
487 amazon.aws.ec2_vpc_subnet:
488 cidr: "{{ subnet_cidr }}"
489 vpc_id: "{{ vpc_result.vpc.id }}"
490 ipv6_cidr: "{{ subnet_ipv6_cidr }}"
491 assign_instances_ipv6: true
492 state: present
493 tags:
494 Name: "{{ ec2_vpc_subnet_name }}"
495 Description: "{{ ec2_vpc_subnet_description }}"
496 check_mode: true
497 register: vpc_subnet_ipv6_recreate
498
499 - name: Assert recreation changed nothing (expected changed=false)
500 ansible.builtin.assert:
501 that:
502 - vpc_subnet_ipv6_recreate is not changed
503
504 - name: Recreate subnet (expected changed=false)
505 amazon.aws.ec2_vpc_subnet:
506 cidr: "{{ subnet_cidr }}"
507 vpc_id: "{{ vpc_result.vpc.id }}"
508 ipv6_cidr: "{{ subnet_ipv6_cidr }}"
509 assign_instances_ipv6: true
510 state: present
511 tags:
512 Name: "{{ ec2_vpc_subnet_name }}"
513 Description: "{{ ec2_vpc_subnet_description }}"
514 register: vpc_subnet_ipv6_recreate
515
516 - name: Assert recreation changed nothing (expected changed=false)
517 ansible.builtin.assert:
518 that:
519 - vpc_subnet_ipv6_recreate is not changed
520 - vpc_subnet_ipv6_recreate.subnet == vpc_subnet_ipv6_create.subnet
521
522 # ============================================================
523 - name: Change subnet assign_instances_ipv6 attribute (expected changed=true) (CHECK MODE)
524 amazon.aws.ec2_vpc_subnet:
525 cidr: "{{ subnet_cidr }}"
526 vpc_id: "{{ vpc_result.vpc.id }}"
527 ipv6_cidr: "{{ subnet_ipv6_cidr }}"
528 assign_instances_ipv6: false
529 state: present
530 purge_tags: false
531 check_mode: true
532 register: vpc_change_attribute
533
534 - name: Assert assign_instances_ipv6 attribute changed (expected changed=true)
535 ansible.builtin.assert:
536 that:
537 - vpc_change_attribute is changed
538
539 - name: Change subnet assign_instances_ipv6 attribute (expected changed=true)
540 amazon.aws.ec2_vpc_subnet:
541 cidr: "{{ subnet_cidr }}"
542 vpc_id: "{{ vpc_result.vpc.id }}"
543 ipv6_cidr: "{{ subnet_ipv6_cidr }}"
544 assign_instances_ipv6: false
545 state: present
546 purge_tags: false
547 register: vpc_change_attribute
548
549 - name: Assert assign_instances_ipv6 attribute changed (expected changed=true)
550 ansible.builtin.assert:
551 that:
552 - vpc_change_attribute is changed
553 - not vpc_change_attribute.subnet.assign_ipv6_address_on_creation
554
555 # ============================================================
556 - name: Add second subnet with duplicate ipv6 cidr (expected failure)
557 amazon.aws.ec2_vpc_subnet:
558 cidr: "{{ subnet_cidr_b }}"
559 vpc_id: "{{ vpc_result.vpc.id }}"
560 ipv6_cidr: "{{ subnet_ipv6_cidr }}"
561 state: present
562 purge_tags: false
563 register: vpc_add_duplicate_ipv6
564 ignore_errors: true
565
566 - name: Assert graceful failure (expected failed)
567 ansible.builtin.assert:
568 that:
569 - vpc_add_duplicate_ipv6 is failed
570 - '"The IPv6 CIDR "+test_char+subnet_ipv6_cidr+test_char+" conflicts with another subnet" in vpc_add_duplicate_ipv6.msg'
571 vars:
572 test_char: "'"
573
574 # ============================================================
575 - name: Remove subnet ipv6 cidr (expected changed=true) (CHECK MODE)
576 amazon.aws.ec2_vpc_subnet:
577 cidr: "{{ subnet_cidr }}"
578 vpc_id: "{{ vpc_result.vpc.id }}"
579 state: present
580 purge_tags: false
581 check_mode: true
582 register: vpc_remove_ipv6_cidr
583
584 - name: Assert subnet ipv6 cidr removed (expected changed=true)
585 ansible.builtin.assert:
586 that:
587 - vpc_remove_ipv6_cidr is changed
588
589 - name: Remove subnet ipv6 cidr (expected changed=true)
590 amazon.aws.ec2_vpc_subnet:
591 cidr: "{{ subnet_cidr }}"
592 vpc_id: "{{ vpc_result.vpc.id }}"
593 state: present
594 purge_tags: false
595 register: vpc_remove_ipv6_cidr
596
597 - name: Assert subnet ipv6 cidr removed (expected changed=true)
598 ansible.builtin.assert:
599 that:
600 - vpc_remove_ipv6_cidr is changed
601 - vpc_remove_ipv6_cidr.subnet.ipv6_cidr_block == ''
602 - not vpc_remove_ipv6_cidr.subnet.assign_ipv6_address_on_creation
603
604 # ============================================================
605 - name: Test adding a tag that looks like a boolean to the subnet (CHECK MODE)
606 amazon.aws.ec2_vpc_subnet:
607 cidr: "{{ subnet_cidr }}"
608 vpc_id: "{{ vpc_result.vpc.id }}"
609 state: present
610 purge_tags: false
611 tags:
612 looks_like_boolean: true
613 check_mode: true
614 register: vpc_subnet_info
615
616 - name: Assert a tag was added
617 ansible.builtin.assert:
618 that:
619 - vpc_subnet_info is changed
620
621 - name: Test adding a tag that looks like a boolean to the subnet
622 amazon.aws.ec2_vpc_subnet:
623 cidr: "{{ subnet_cidr }}"
624 vpc_id: "{{ vpc_result.vpc.id }}"
625 state: present
626 purge_tags: false
627 tags:
628 looks_like_boolean: true
629 register: vpc_subnet_info
630
631 - name: Assert a tag was added
632 ansible.builtin.assert:
633 that:
634 - vpc_subnet_info is changed
635 - vpc_subnet_info.subnet.tags.looks_like_boolean == "True"
636
637 # ============================================================
638 - name: Test idempotence adding a tag that looks like a boolean (CHECK MODE)
639 amazon.aws.ec2_vpc_subnet:
640 cidr: "{{ subnet_cidr }}"
641 vpc_id: "{{ vpc_result.vpc.id }}"
642 state: present
643 purge_tags: false
644 tags:
645 looks_like_boolean: true
646 check_mode: true
647 register: vpc_subnet_info
648
649 - name: Assert tags haven't changed
650 ansible.builtin.assert:
651 that:
652 - vpc_subnet_info is not changed
653
654 - name: Test idempotence adding a tag that looks like a boolean
655 amazon.aws.ec2_vpc_subnet:
656 cidr: "{{ subnet_cidr }}"
657 vpc_id: "{{ vpc_result.vpc.id }}"
658 state: present
659 purge_tags: false
660 tags:
661 looks_like_boolean: true
662 register: vpc_subnet_info
663
664 - name: Assert tags haven't changed
665 ansible.builtin.assert:
666 that:
667 - vpc_subnet_info is not changed
668
669 always:
670 ################################################
671 # TEARDOWN STARTS HERE
672 ################################################
673
674 - name: Tidy up subnet
675 amazon.aws.ec2_vpc_subnet:
676 cidr: "{{ subnet_cidr }}"
677 vpc_id: "{{ vpc_result.vpc.id }}"
678 state: absent
679
680 - name: Tidy up VPC
681 amazon.aws.ec2_vpc_net:
682 name: "{{ resource_prefix }}-vpc"
683 state: absent
684 cidr_block: "{{ vpc_cidr }}"