Debian Codegraph @

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

raw
1 ---
2 # Tests for rds_subnet_group
3 #
4 # Note: (From Amazon's documentation)
5 # https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/rds.html#RDS.Client.modify_db_subnet_group
6 # DB subnet groups must contain at least one subnet in at least two AZs in the
7 # AWS Region.
8
9 - module_defaults:
10 group/aws:
11 access_key: "{{ aws_access_key }}"
12 secret_key: "{{ aws_secret_key }}"
13 session_token: "{{ security_token | default(omit) }}"
14 region: "{{ aws_region }}"
15 block:
16 # ============================================================
17
18 - name: Fetch AZ availability
19 amazon.aws.aws_az_info:
20 register: az_info
21
22 - name: Assert that we have multiple AZs available to us
23 ansible.builtin.assert:
24 that: az_info.availability_zones | length >= 2
25
26 - name: Pick AZs
27 ansible.builtin.set_fact:
28 az_one: "{{ az_info.availability_zones[0].zone_name }}"
29 az_two: "{{ az_info.availability_zones[1].zone_name }}"
30
31 # ============================================================
32
33 - name: Create a VPC
34 amazon.aws.ec2_vpc_net:
35 state: present
36 cidr_block: "{{ vpc_cidr }}"
37 name: "{{ resource_prefix }}"
38 register: vpc
39
40 - name: Create subnets
41 amazon.aws.ec2_vpc_subnet:
42 state: present
43 cidr: "{{ item.cidr }}"
44 az: "{{ item.az }}"
45 vpc_id: "{{ vpc.vpc.id }}"
46 tags:
47 Name: "{{ item.name }}"
48 with_items:
49 - cidr: "{{ subnet_a }}"
50 az: "{{ az_one }}"
51 name: "{{ resource_prefix }}-subnet-a"
52 - cidr: "{{ subnet_b }}"
53 az: "{{ az_two }}"
54 name: "{{ resource_prefix }}-subnet-b"
55 - cidr: "{{ subnet_c }}"
56 az: "{{ az_one }}"
57 name: "{{ resource_prefix }}-subnet-c"
58 - cidr: "{{ subnet_d }}"
59 az: "{{ az_two }}"
60 name: "{{ resource_prefix }}-subnet-d"
61 register: subnets
62
63 - ansible.builtin.set_fact:
64 subnet_ids: '{{ subnets.results | map(attribute="subnet.id") | list }}'
65
66 # ============================================================
67
68 - ansible.builtin.include_tasks: params.yml
69 - ansible.builtin.include_tasks: tests.yml
70 always:
71 - name: Remove subnet group
72 amazon.aws.rds_subnet_group:
73 state: absent
74 name: "{{ resource_prefix }}"
75 ignore_errors: true
76
77 - name: Remove subnets
78 amazon.aws.ec2_vpc_subnet:
79 state: absent
80 cidr: "{{ item.cidr }}"
81 vpc_id: "{{ vpc.vpc.id }}"
82 with_items:
83 - cidr: "{{ subnet_a }}"
84 name: "{{ resource_prefix }}-subnet-a"
85 - cidr: "{{ subnet_b }}"
86 name: "{{ resource_prefix }}-subnet-b"
87 - cidr: "{{ subnet_c }}"
88 name: "{{ resource_prefix }}-subnet-c"
89 - cidr: "{{ subnet_d }}"
90 name: "{{ resource_prefix }}-subnet-d"
91 ignore_errors: true
92 register: removed_subnets
93 until: removed_subnets is succeeded
94 retries: 5
95 delay: 5
96
97 - name: Remove the VPC
98 amazon.aws.ec2_vpc_net:
99 state: absent
100 cidr_block: "{{ vpc_cidr }}"
101 name: "{{ resource_prefix }}"
102 ignore_errors: true
103 register: removed_vpc
104 until: removed_vpc is success
105 retries: 5
106 delay: 5
107
108 # ============================================================