Skip to content

Commit 89c5645

Browse files
authored
Remove AWS NAT Gateways prior to ENI removal during L1 networking teardown (#43)
* Remove the NAT gateways before the ENI cleanup is called, when calling purge with an L1 deployment or when NAT gateways are deployed with attached ENI. * Add check for 'community.aws.ec2_vpc_nat_gateway' results during normal removal Signed-off-by: Daniel Chaffelson <chaffelson@gmail.com>
1 parent 88b2b5a commit 89c5645

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

roles/infrastructure/tasks/teardown_aws_network.yml

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,27 @@
7070
retries: 120
7171
delay: 10
7272

73+
- name: Remove discovered AWS NAT Gateways
74+
register: __infra_aws_nat_remove_result
75+
when:
76+
- __infra_aws_nat_gateways is defined
77+
- __infra_aws_nat_gateways.result is defined
78+
- __infra_aws_nat_gateways.result | length > 0
79+
community.aws.ec2_vpc_nat_gateway:
80+
state: absent
81+
region: "{{ infra__region }}"
82+
wait: true
83+
nat_gateway_id: "{{ __infra_nat_gateway_remove_item.nat_gateway_id }}"
84+
release_eip: true
85+
loop_control:
86+
label: "{{ __infra_nat_gateway_remove_item.nat_gateway_id }}"
87+
loop_var: __infra_nat_gateway_remove_item
88+
loop: "{{ __infra_aws_nat_gateways.result }}"
89+
failed_when:
90+
- "'rc' in __infra_aws_nat_remove_result"
91+
- __infra_aws_nat_remove_result.rc != 0
92+
- "'InvalidAllocationID.NotFound' not in __infra_aws_nat_remove_result.module_stderr"
93+
7394
- name: Remove discovered AWS Network Adapters
7495
when:
7596
- __infra_vpc_enis is defined
@@ -115,24 +136,6 @@
115136
label: "{{ __security_group_purge_item.group_name }}"
116137
loop: "{{ __infra_aws_sgs.security_groups }}"
117138

118-
- name: Remove discovered AWS NAT Gateways
119-
register: __infra_aws_nat_remove_result
120-
when:
121-
- __infra_aws_nat_gateways is defined
122-
- __infra_aws_nat_gateways.result is defined
123-
- __infra_aws_nat_gateways.result | length > 0
124-
community.aws.ec2_vpc_nat_gateway:
125-
state: absent
126-
region: "{{ infra__region }}"
127-
wait: true
128-
nat_gateway_id: "{{ __infra_nat_gateway_remove_item.nat_gateway_id }}"
129-
release_eip: true
130-
loop_control:
131-
label: "{{ __infra_nat_gateway_remove_item.nat_gateway_id }}"
132-
loop_var: __infra_nat_gateway_remove_item
133-
loop: "{{ __infra_aws_nat_gateways.result }}"
134-
failed_when: __infra_aws_nat_remove_result.rc != 0 and 'InvalidAllocationID.NotFound' not in __infra_aws_nat_remove_result.module_stderr
135-
136139
- name: Remove discovered AWS VPC Subnets
137140
when:
138141
- __infra_disc_subnet_cidrs is defined

0 commit comments

Comments
 (0)