Debian Codegraph @

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

raw
1 ---
2 - name: Run 'ec2_transit_gateway integration tests'
3 module_defaults:
4 group/aws:
5 access_key: "{{ aws_access_key }}"
6 secret_key: "{{ aws_secret_key }}"
7 session_token: "{{ security_token | default(omit) }}"
8 region: "{{ aws_region }}"
9 block:
10 - name: Generate unique value for testing
11 ansible.builtin.set_fact:
12 tgw_description: "{{ resource_prefix }}-tgw"
13
14 - name: Test create transit gateway without tags - check_mode
15 amazon.aws.ec2_transit_gateway:
16 description: "{{ tgw_description }}"
17 register: create_result
18 check_mode: true
19
20 - name: Assert changed is True - check_mode
21 ansible.builtin.assert:
22 that:
23 - create_result.changed == True
24 - '"ec2:CreateTransitGateway" not in create_result.resource_actions'
25
26 - name: Test create transit gateway without tags
27 amazon.aws.ec2_transit_gateway:
28 description: "{{ tgw_description }}"
29 register: create_result
30
31 - name: Assert changed is True
32 ansible.builtin.assert:
33 that:
34 - create_result.changed == True
35
36 - name: Test create transit gateway without tags - idempotency
37 amazon.aws.ec2_transit_gateway:
38 description: "{{ tgw_description }}"
39 register: create_result
40
41 - name: Assert changed is True
42 ansible.builtin.assert:
43 that:
44 - create_result.changed == False
45 - '"ec2:CreateTransitGateway" not in create_result.resource_actions'
46
47 - name: Test update transit gateway with tags by description - check_mode
48 amazon.aws.ec2_transit_gateway:
49 description: "{{ tgw_description }}"
50 tags:
51 Name: Ansible Test TGW
52 register: result
53 check_mode: true
54
55 - name: Assert changed is True - check_mode
56 ansible.builtin.assert:
57 that:
58 - result.changed == True
59 - '"ec2:CreateTags" not in result.resource_actions'
60
61 - name: Test update transit gateway with tags by description
62 amazon.aws.ec2_transit_gateway:
63 description: "{{ tgw_description }}"
64 tags:
65 Name: Ansible Test TGW
66 register: result
67
68 - name: Assert changed is True
69 ansible.builtin.assert:
70 that:
71 - result.changed == True
72 - result.transit_gateway.tags | length == 1
73 - "'Name' in result.transit_gateway.tags"
74
75 - name: Test update transit gateway with tags by description - idempotency
76 amazon.aws.ec2_transit_gateway:
77 description: "{{ tgw_description }}"
78 tags:
79 Name: Ansible Test TGW
80 register: result
81
82 - name: Assert changed is False - idempotency
83 ansible.builtin.assert:
84 that:
85 - result.changed == False
86 - result.transit_gateway.tags | length == 1
87 - "'Name' in result.transit_gateway.tags"
88
89 - name: Test update transit gateway with new tag and purge_tags false - check_mode
90 amazon.aws.ec2_transit_gateway:
91 transit_gateway_id: "{{ create_result.transit_gateway.transit_gateway_id }}"
92 purge_tags: false
93 tags:
94 status: ok to delete
95 register: result
96 check_mode: true
97
98 - name: Assert changed is True and have 2 tags - check_mode
99 ansible.builtin.assert:
100 that:
101 - result.changed == True
102 - result.transit_gateway.tags | length != 2
103 - "'Name' in result.transit_gateway.tags"
104 - '"ec2:CreateTags" not in result.resource_actions'
105
106 - name: Test update transit gateway with new tag and purge_tags false
107 amazon.aws.ec2_transit_gateway:
108 transit_gateway_id: "{{ create_result.transit_gateway.transit_gateway_id }}"
109 purge_tags: false
110 tags:
111 status: ok to delete
112 register: result
113
114 - name: Assert changed is True and have 2 tags
115 ansible.builtin.assert:
116 that:
117 - result.changed == True
118 - result.transit_gateway.tags | length == 2
119 - "'Name' in result.transit_gateway.tags"
120
121 - name: Test update transit gateway with new tag and purge_tags false - idempotency
122 amazon.aws.ec2_transit_gateway:
123 transit_gateway_id: "{{ create_result.transit_gateway.transit_gateway_id }}"
124 purge_tags: false
125 tags:
126 status: ok to delete
127 register: result
128
129 - name: Assert changed is True and have 2 tags - idempotency
130 ansible.builtin.assert:
131 that:
132 - result.changed == False
133 - result.transit_gateway.tags | length == 2
134 - "'Name' in result.transit_gateway.tags"
135
136 - name: Test update transit gateway with purge_tags true - check_mode
137 amazon.aws.ec2_transit_gateway:
138 transit_gateway_id: "{{ create_result.transit_gateway.transit_gateway_id }}"
139 purge_tags: true
140 tags:
141 status: ok to delete
142 register: result
143 check_mode: true
144
145 - name: Assert changed is True and TGW tag is absent - check_mode
146 ansible.builtin.assert:
147 that:
148 - result.changed == True
149 - result.transit_gateway.tags | length == 2
150 - '"ec2:DeleteTags" not in result.resource_actions'
151
152 - name: Test update transit gateway with purge_tags true
153 amazon.aws.ec2_transit_gateway:
154 transit_gateway_id: "{{ create_result.transit_gateway.transit_gateway_id }}"
155 purge_tags: true
156 tags:
157 status: ok to delete
158 register: result
159
160 - name: Assert changed is True and TGW tag is absent
161 ansible.builtin.assert:
162 that:
163 - result.changed == True
164 - result.transit_gateway.tags | length == 1
165 - "'Name' not in result.transit_gateway.tags"
166
167 - name: Test idempotence
168 amazon.aws.ec2_transit_gateway:
169 description: "{{ tgw_description }}"
170 purge_tags: true
171 tags:
172 status: ok to delete
173 register: result
174
175 - name: Assert changed is False
176 ansible.builtin.assert:
177 that:
178 - result.changed == False
179
180 - name: Generate unique value for testing
181 ansible.builtin.set_fact:
182 tgw_description_multicast: "{{ resource_prefix }}-tgw-multicast"
183
184 - name: Test create transit gateway with multicast enabled - check_mode
185 amazon.aws.ec2_transit_gateway:
186 description: "{{ tgw_description_multicast }}"
187 multicast_support: true
188 register: create_result
189 check_mode: true
190
191 - name: Assert changed is True - check_mode
192 ansible.builtin.assert:
193 that:
194 - create_result.changed == True
195 - '"ec2:CreateTransitGateway" not in create_result.resource_actions'
196
197 - name: Test create transit gateway with multicast enabled
198 amazon.aws.ec2_transit_gateway:
199 description: "{{ tgw_description_multicast }}"
200 multicast_support: true
201 register: create_result
202
203 - name: Assert changed is True
204 ansible.builtin.assert:
205 that:
206 - create_result.changed == True
207
208 - name: Test create transit gateway with multicast enabled - idempotency
209 amazon.aws.ec2_transit_gateway:
210 description: "{{ tgw_description_multicast }}"
211 multicast_support: true
212 register: create_result
213
214 - name: Assert changed is True - idempotency
215 ansible.builtin.assert:
216 that:
217 - create_result.changed == False
218
219 - name: Test success with filter
220 amazon.aws.ec2_transit_gateway_info:
221 filters:
222 options.multicast-support: enable
223 register: result
224
225 - name: Assert success with multicast-support filter
226 ansible.builtin.assert:
227 that:
228 - result.transit_gateways != []
229
230 # ==== Combine ec2_transit_gateway_info ======================
231 - name: Test success with no parameters
232 amazon.aws.ec2_transit_gateway_info:
233 register: result
234 - name: Assert success with no parameters
235 ansible.builtin.assert:
236 that:
237 - result.changed == false
238 - result.transit_gateways != []
239
240 - name: Test success with single filter
241 amazon.aws.ec2_transit_gateway_info:
242 filters:
243 transit-gateway-id: "{{ create_result.transit_gateway.transit_gateway_id }}"
244 register: result
245
246 - name: Assert success with transit_gateway_id filter
247 ansible.builtin.assert:
248 that:
249 - result.changed == false
250 - result.transit_gateways != []
251
252 - name: Test empty result set for non-existent tgw id via filter
253 amazon.aws.ec2_transit_gateway_info:
254 filters:
255 transit-gateway-id: tgw-00000011111111122
256 register: result
257
258 - name: Assert success with transit_gateway_id filter
259 ansible.builtin.assert:
260 that:
261 - result.changed == false
262 - result.transit_gateways == []
263
264 - name: Test NotFound exception caught and returned empty result set
265 amazon.aws.ec2_transit_gateway_info:
266 transit_gateway_id: tgw-00000011111111122
267 register: result
268
269 - name: Assert success with transit_gateway_id filter
270 ansible.builtin.assert:
271 that:
272 - result.changed == false
273 - result.transit_gateways == []
274
275 - name: Test success with multiple filters
276 amazon.aws.ec2_transit_gateway_info:
277 filters:
278 options.dns-support: enable
279 options.vpn-ecmp-support: enable
280 register: result
281
282 - name: Assert success with transit_gateway_id filter
283 ansible.builtin.assert:
284 that:
285 - result.changed == false
286 - result.transit_gateways != []
287
288 always:
289 ###### TEARDOWN STARTS HERE ######
290 - name: Delete transit gateway
291 amazon.aws.ec2_transit_gateway:
292 description: "{{ item }}"
293 state: absent
294 ignore_errors: true
295 loop:
296 - "{{ tgw_description }}"
297 - "{{ tgw_description_multicast }}"