| 1 |
--- |
| 2 |
# |
| 3 |
# We can't start deleting the other resources until the firewalls have finished |
| 4 |
# detatching from the subnets |
| 5 |
# |
| 6 |
- name: 'Fetch all firewalls' |
| 7 |
networkfirewall_info: {} |
| 8 |
register: account_firewalls_info |
| 9 |
ignore_errors: true |
| 10 |
|
| 11 |
- name: 'Get a list of all firewalls matching {{ firewall_name_prefix }}' |
| 12 |
set_fact: |
| 13 |
matching_firewalls: '{{ account_firewalls_info.firewall_list | select("search", firewall_name_prefix) | list }}' |
| 14 |
ignore_errors: true |
| 15 |
|
| 16 |
- name: 'Delete matching firewalls' |
| 17 |
networkfirewall: |
| 18 |
arn: '{{ item }}' |
| 19 |
state: absent |
| 20 |
delete_protection: False |
| 21 |
wait: True |
| 22 |
ignore_errors: true |
| 23 |
loop: '{{ matching_firewalls }}' |
| 24 |
|
| 25 |
# |
| 26 |
# Policies can take a while to delete, but we can start the process, trigger the |
| 27 |
# deletion of the Subnets/VPC and then come back and delete the Rule Groups |
| 28 |
# |
| 29 |
- name: 'Fetch all policies' |
| 30 |
networkfirewall_policy_info: {} |
| 31 |
register: account_policies_info |
| 32 |
ignore_errors: true |
| 33 |
|
| 34 |
- name: 'Get a list of all rules matching {{ policy_name_prefix }}' |
| 35 |
set_fact: |
| 36 |
matching_policies: '{{ account_policies_info.policy_list | select("search", policy_name_prefix) | list }}' |
| 37 |
ignore_errors: true |
| 38 |
|
| 39 |
- name: 'Delete matching policies' |
| 40 |
networkfirewall_policy: |
| 41 |
arn: '{{ item }}' |
| 42 |
state: absent |
| 43 |
wait: False |
| 44 |
ignore_errors: true |
| 45 |
loop: '{{ matching_policies }}' |
| 46 |
|
| 47 |
- name: 'Start deletion of subnets' |
| 48 |
ec2_vpc_subnet: |
| 49 |
state: absent |
| 50 |
cidr: '{{ item.cidr }}' |
| 51 |
vpc_id: '{{ item.vpc_id }}' |
| 52 |
wait: False |
| 53 |
loop: |
| 54 |
- cidr: '{{ subnet_cidr_a_1 }}' |
| 55 |
vpc_id: '{{ vpc_id_a }}' |
| 56 |
- cidr: '{{ subnet_cidr_a_2 }}' |
| 57 |
vpc_id: '{{ vpc_id_a }}' |
| 58 |
- cidr: '{{ subnet_cidr_a_3 }}' |
| 59 |
vpc_id: '{{ vpc_id_a }}' |
| 60 |
- cidr: '{{ subnet_cidr_b_1 }}' |
| 61 |
vpc_id: '{{ vpc_id_b }}' |
| 62 |
- cidr: '{{ subnet_cidr_b_2 }}' |
| 63 |
vpc_id: '{{ vpc_id_b }}' |
| 64 |
- cidr: '{{ subnet_cidr_a_1a }}' |
| 65 |
vpc_id: '{{ vpc_id_a }}' |
| 66 |
ignore_errors: True |
| 67 |
|
| 68 |
- name: 'Wait for deletion of subnets' |
| 69 |
ec2_vpc_subnet: |
| 70 |
state: absent |
| 71 |
cidr: '{{ item.cidr }}' |
| 72 |
vpc_id: '{{ item.vpc_id }}' |
| 73 |
wait: True |
| 74 |
loop: |
| 75 |
- cidr: '{{ subnet_cidr_a_1 }}' |
| 76 |
vpc_id: '{{ vpc_id_a }}' |
| 77 |
- cidr: '{{ subnet_cidr_a_2 }}' |
| 78 |
vpc_id: '{{ vpc_id_a }}' |
| 79 |
- cidr: '{{ subnet_cidr_a_3 }}' |
| 80 |
vpc_id: '{{ vpc_id_a }}' |
| 81 |
- cidr: '{{ subnet_cidr_b_1 }}' |
| 82 |
vpc_id: '{{ vpc_id_b }}' |
| 83 |
- cidr: '{{ subnet_cidr_b_2 }}' |
| 84 |
vpc_id: '{{ vpc_id_b }}' |
| 85 |
- cidr: '{{ subnet_cidr_a_1a }}' |
| 86 |
vpc_id: '{{ vpc_id_a }}' |
| 87 |
ignore_errors: True |
| 88 |
|
| 89 |
- name: 'Delete VPCs' |
| 90 |
ec2_vpc_net: |
| 91 |
state: absent |
| 92 |
cidr_block: '{{ item.cidr }}' |
| 93 |
name: '{{ item.name }}' |
| 94 |
loop: |
| 95 |
- cidr: '{{ vpc_cidr_a }}' |
| 96 |
name: '{{ vpc_name_a }}' |
| 97 |
- cidr: '{{ vpc_cidr_b }}' |
| 98 |
name: '{{ vpc_name_b }}' |
| 99 |
ignore_errors: True |
| 100 |
|
| 101 |
- name: 'Wait for policies to finish deletion' |
| 102 |
networkfirewall_policy: |
| 103 |
arn: '{{ item }}' |
| 104 |
state: absent |
| 105 |
ignore_errors: true |
| 106 |
loop: '{{ matching_policies }}' |
| 107 |
|
| 108 |
- name: 'Fetch all account rule groups' |
| 109 |
networkfirewall_rule_group_info: {} |
| 110 |
register: account_rules_info |
| 111 |
ignore_errors: true |
| 112 |
|
| 113 |
- name: 'Get a list of all rules matching {{ group_name_prefix }}' |
| 114 |
set_fact: |
| 115 |
matching_rules: '{{ account_rules_info.rule_list | select("search", group_name_prefix) | list }}' |
| 116 |
ignore_errors: true |
| 117 |
|
| 118 |
- name: 'Delete matching rule groups' |
| 119 |
networkfirewall_rule_group: |
| 120 |
arn: '{{ item }}' |
| 121 |
state: absent |
| 122 |
ignore_errors: true |
| 123 |
loop: '{{ matching_rules }}' |