| 1 |
--- |
| 2 |
- name: EC2 VPN Connection 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 |
# ============================================================ |
| 11 |
- name: Create a VPC |
| 12 |
amazon.aws.ec2_vpc_net: |
| 13 |
name: "{{ resource_prefix }}-vpc" |
| 14 |
state: present |
| 15 |
cidr_block: 10.0.0.0/26 |
| 16 |
tags: |
| 17 |
Name: "{{ resource_prefix }}-vpc" |
| 18 |
Description: Created by ansible-test |
| 19 |
register: vpc_result |
| 20 |
|
| 21 |
- name: Create an EC2 VPC gateway and attach it to VPC |
| 22 |
amazon.aws.ec2_vpc_vgw: |
| 23 |
state: present |
| 24 |
vpc_id: "{{ vpc_result.vpc.id }}" |
| 25 |
name: "{{ resource_prefix }}-vgw" |
| 26 |
register: vgw |
| 27 |
|
| 28 |
- name: Create customer gateway |
| 29 |
community.aws.ec2_customer_gateway: |
| 30 |
bgp_asn: 12345 |
| 31 |
ip_address: 1.2.3.4 |
| 32 |
name: testcgw |
| 33 |
register: cgw |
| 34 |
|
| 35 |
- name: Create transit gateway |
| 36 |
amazon.aws.ec2_transit_gateway: |
| 37 |
description: Transit Gateway for vpn attachment |
| 38 |
wait: true |
| 39 |
register: tgw |
| 40 |
|
| 41 |
- name: Create an EC2 VPN Connection, with customer gateway, vpn_gateway_id and transit_gateway |
| 42 |
amazon.aws.ec2_vpc_vpn: |
| 43 |
customer_gateway_id: "{{ cgw.gateway.customer_gateway.customer_gateway_id }}" |
| 44 |
vpn_gateway_id: "{{ vgw.vgw.id }}" |
| 45 |
transit_gateway_id: "{{ tgw.transit_gateway.transit_gateway_id }}" |
| 46 |
state: present |
| 47 |
register: result |
| 48 |
ignore_errors: true |
| 49 |
|
| 50 |
- name: Assert creation of vpn failed |
| 51 |
ansible.builtin.assert: |
| 52 |
that: |
| 53 |
- result is failed |
| 54 |
- "'parameters are mutually exclusive: vpn_gateway_id|transit_gateway_id' in result.msg" |
| 55 |
|
| 56 |
- name: Create EC2 VPN Connection, with customer gateway and transit_gateway |
| 57 |
amazon.aws.ec2_vpc_vpn: |
| 58 |
customer_gateway_id: "{{ cgw.gateway.customer_gateway.customer_gateway_id }}" |
| 59 |
transit_gateway_id: "{{ tgw.transit_gateway.transit_gateway_id }}" |
| 60 |
state: present |
| 61 |
wait_timeout: 1000 |
| 62 |
register: tgw_vpn |
| 63 |
|
| 64 |
- name: Store ID of VPN |
| 65 |
ansible.builtin.set_fact: |
| 66 |
vpn_id: "{{ tgw_vpn.vpn_connection_id }}" |
| 67 |
|
| 68 |
# ============================================================ |
| 69 |
- name: Test success with no parameters |
| 70 |
amazon.aws.ec2_vpc_vpn_info: |
| 71 |
register: result |
| 72 |
|
| 73 |
- name: Assert success with no parameters |
| 74 |
ansible.builtin.assert: |
| 75 |
that: |
| 76 |
- result.changed == false |
| 77 |
- result.vpn_connections != [] |
| 78 |
# ============================================================ |
| 79 |
|
| 80 |
- name: Delete EC2 VPN Connection created with transit gateway |
| 81 |
amazon.aws.ec2_vpc_vpn: |
| 82 |
state: absent |
| 83 |
vpn_connection_id: "{{ vpn_id }}" |
| 84 |
register: result |
| 85 |
retries: 10 |
| 86 |
delay: 3 |
| 87 |
until: result is not failed |
| 88 |
ignore_errors: true |
| 89 |
|
| 90 |
# ============================================================ |
| 91 |
|
| 92 |
- name: Create EC2 VPN Connection, with customer gateway and vpn gateway |
| 93 |
amazon.aws.ec2_vpc_vpn: |
| 94 |
customer_gateway_id: "{{ cgw.gateway.customer_gateway.customer_gateway_id }}" |
| 95 |
vpn_gateway_id: "{{ vgw.vgw.id }}" |
| 96 |
state: present |
| 97 |
register: vpn |
| 98 |
|
| 99 |
- name: Store ID of the EC2 VPN Connection |
| 100 |
ansible.builtin.set_fact: |
| 101 |
vpn_id: "{{ vpn.vpn_connection_id }}" |
| 102 |
|
| 103 |
# ============================================================ |
| 104 |
|
| 105 |
- name: Test success with no parameters |
| 106 |
amazon.aws.ec2_vpc_vpn_info: |
| 107 |
register: result |
| 108 |
|
| 109 |
- name: Assert success with no parameters |
| 110 |
ansible.builtin.assert: |
| 111 |
that: |
| 112 |
- result.changed == false |
| 113 |
- result.vpn_connections != [] |
| 114 |
|
| 115 |
- name: Test success with customer gateway id as a filter |
| 116 |
amazon.aws.ec2_vpc_vpn_info: |
| 117 |
filters: |
| 118 |
customer-gateway-id: "{{ cgw.gateway.customer_gateway.customer_gateway_id }}" |
| 119 |
vpn-connection-id: "{{ vpn.vpn_connection_id }}" |
| 120 |
register: result |
| 121 |
|
| 122 |
- name: Assert success with customer gateway id as filter |
| 123 |
ansible.builtin.assert: |
| 124 |
that: |
| 125 |
- result.changed == false |
| 126 |
- result.vpn_connections != [] |
| 127 |
|
| 128 |
# ============================================================ |
| 129 |
|
| 130 |
- ansible.builtin.include_tasks: tags.yml |
| 131 |
- name: Delete EC2 VPN Connection (check_mode) |
| 132 |
amazon.aws.ec2_vpc_vpn: |
| 133 |
state: absent |
| 134 |
vpn_connection_id: "{{ vpn_id }}" |
| 135 |
register: result |
| 136 |
check_mode: true |
| 137 |
|
| 138 |
- name: Assert EC2 VPN Connection is deleted (check_mode) |
| 139 |
ansible.builtin.assert: |
| 140 |
that: |
| 141 |
- result is changed |
| 142 |
|
| 143 |
- name: Delete EC2 VPN Connection |
| 144 |
amazon.aws.ec2_vpc_vpn: |
| 145 |
state: absent |
| 146 |
vpn_connection_id: "{{ vpn_id }}" |
| 147 |
register: result |
| 148 |
|
| 149 |
- name: Assert EC2 VPN Connection is deleted |
| 150 |
ansible.builtin.assert: |
| 151 |
that: |
| 152 |
- result is changed |
| 153 |
|
| 154 |
- name: Delete EC2 VPN Connection - idempotency (check) |
| 155 |
amazon.aws.ec2_vpc_vpn: |
| 156 |
state: absent |
| 157 |
vpn_connection_id: "{{ vpn_id }}" |
| 158 |
register: result |
| 159 |
check_mode: true |
| 160 |
|
| 161 |
- name: Assert result has not changed (idempotency check_mode) |
| 162 |
ansible.builtin.assert: |
| 163 |
that: |
| 164 |
- result is not changed |
| 165 |
|
| 166 |
- name: Delete EC2 VPN Connection - idempotency |
| 167 |
amazon.aws.ec2_vpc_vpn: |
| 168 |
state: absent |
| 169 |
vpn_connection_id: "{{ vpn_id }}" |
| 170 |
register: result |
| 171 |
|
| 172 |
- name: Assert result has not changed (idempotency) |
| 173 |
ansible.builtin.assert: |
| 174 |
that: |
| 175 |
- result is not changed |
| 176 |
|
| 177 |
# ============================================================ |
| 178 |
always: |
| 179 |
- name: Delete EC2 VPN Connection |
| 180 |
amazon.aws.ec2_vpc_vpn: |
| 181 |
state: absent |
| 182 |
vpn_connection_id: "{{ vpn.vpn_connection_id }}" |
| 183 |
register: result |
| 184 |
retries: 10 |
| 185 |
delay: 3 |
| 186 |
until: result is not failed |
| 187 |
ignore_errors: true |
| 188 |
|
| 189 |
- name: Delete customer gateway |
| 190 |
community.aws.ec2_customer_gateway: |
| 191 |
state: absent |
| 192 |
ip_address: 1.2.3.4 |
| 193 |
name: testcgw |
| 194 |
bgp_asn: 12345 |
| 195 |
register: result |
| 196 |
retries: 10 |
| 197 |
delay: 3 |
| 198 |
until: result is not failed |
| 199 |
ignore_errors: true |
| 200 |
|
| 201 |
- name: Delete VPN gateway |
| 202 |
amazon.aws.ec2_vpc_vgw: |
| 203 |
state: absent |
| 204 |
vpn_gateway_id: "{{ vgw.vgw.id }}" |
| 205 |
register: result |
| 206 |
retries: 10 |
| 207 |
delay: 3 |
| 208 |
until: result is not failed |
| 209 |
ignore_errors: true |
| 210 |
|
| 211 |
- name: Delete VPC |
| 212 |
amazon.aws.ec2_vpc_net: |
| 213 |
name: "{{ resource_prefix }}-vpc" |
| 214 |
state: absent |
| 215 |
cidr_block: 10.0.0.0/26 |
| 216 |
register: result |
| 217 |
retries: 10 |
| 218 |
delay: 3 |
| 219 |
until: result is not failed |
| 220 |
ignore_errors: true |
| 221 |
|
| 222 |
- name: Delete transit gateway |
| 223 |
amazon.aws.ec2_transit_gateway: |
| 224 |
transit_gateway_id: "{{ tgw.transit_gateway.transit_gateway_id }}" |
| 225 |
state: absent |
| 226 |
ignore_errors: true |