| 1 |
--- |
| 2 |
- name: EC2 VPC Peering 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 |
- name: Get ARN of calling user |
| 11 |
amazon.aws.aws_caller_info: |
| 12 |
register: aws_caller_info |
| 13 |
|
| 14 |
- name: Store Account ID for later use |
| 15 |
ansible.builtin.set_fact: |
| 16 |
account_id: "{{ aws_caller_info.account }}" |
| 17 |
|
| 18 |
# ============================================================ |
| 19 |
- name: Fetch EC2 VPC Peering Connections in check_mode |
| 20 |
amazon.aws.ec2_vpc_peering_info: |
| 21 |
register: peers_info |
| 22 |
check_mode: true |
| 23 |
|
| 24 |
- name: Assert success |
| 25 |
ansible.builtin.assert: |
| 26 |
that: |
| 27 |
- peers_info is successful |
| 28 |
- '"vpc_peering_connections" in peers_info' |
| 29 |
|
| 30 |
# ============================================================ |
| 31 |
- name: Create VPC 1 |
| 32 |
amazon.aws.ec2_vpc_net: |
| 33 |
name: "{{ vpc_1_name }}" |
| 34 |
state: present |
| 35 |
cidr_block: "{{ vpc_1_cidr }}" |
| 36 |
tags: |
| 37 |
Name: "{{ vpc_1_name }}" |
| 38 |
TestPrefex: "{{ resource_prefix }}" |
| 39 |
register: vpc_1_result |
| 40 |
|
| 41 |
- name: Assert success |
| 42 |
ansible.builtin.assert: |
| 43 |
that: |
| 44 |
- vpc_1_result is successful |
| 45 |
|
| 46 |
- name: Create VPC 2 |
| 47 |
amazon.aws.ec2_vpc_net: |
| 48 |
name: "{{ vpc_2_name }}" |
| 49 |
state: present |
| 50 |
cidr_block: "{{ vpc_2_cidr }}" |
| 51 |
tags: |
| 52 |
Name: "{{ vpc_2_name }}" |
| 53 |
TestPrefex: "{{ resource_prefix }}" |
| 54 |
register: vpc_2_result |
| 55 |
|
| 56 |
- name: Assert success |
| 57 |
ansible.builtin.assert: |
| 58 |
that: |
| 59 |
- vpc_2_result is successful |
| 60 |
|
| 61 |
- name: Store VPC IDs |
| 62 |
ansible.builtin.set_fact: |
| 63 |
vpc_1: "{{ vpc_1_result.vpc.id }}" |
| 64 |
vpc_2: "{{ vpc_2_result.vpc.id }}" |
| 65 |
|
| 66 |
- name: Set a name to use with the connections |
| 67 |
ansible.builtin.set_fact: |
| 68 |
connection_name: Peering connection for VPC {{ vpc_1 }} to VPC {{ vpc_2 }} |
| 69 |
|
| 70 |
- name: Create local account EC2 VPC Peering Connection request (check_mode) |
| 71 |
amazon.aws.ec2_vpc_peering: |
| 72 |
vpc_id: "{{ vpc_1 }}" |
| 73 |
peer_vpc_id: "{{ vpc_2 }}" |
| 74 |
state: present |
| 75 |
tags: |
| 76 |
Name: "{{ connection_name }}" |
| 77 |
check_mode: true |
| 78 |
register: vpc_peer |
| 79 |
|
| 80 |
- name: Assert success |
| 81 |
ansible.builtin.assert: |
| 82 |
that: |
| 83 |
- vpc_peer is changed |
| 84 |
|
| 85 |
- name: Create local account EC2 VPC Peering Connection request |
| 86 |
amazon.aws.ec2_vpc_peering: |
| 87 |
vpc_id: "{{ vpc_1 }}" |
| 88 |
peer_vpc_id: "{{ vpc_2 }}" |
| 89 |
state: present |
| 90 |
tags: |
| 91 |
Name: "{{ connection_name }}" |
| 92 |
register: vpc_peer |
| 93 |
|
| 94 |
- name: Assert success |
| 95 |
ansible.builtin.assert: |
| 96 |
that: |
| 97 |
- vpc_peer is changed |
| 98 |
- vpc_peer is successful |
| 99 |
- "'peering_id' in vpc_peer" |
| 100 |
- vpc_peer.vpc_peering_connection.requester_vpc_info.cidr_block == vpc_1_cidr |
| 101 |
- vpc_peer.peering_id.startswith('pcx-') |
| 102 |
|
| 103 |
- name: Store Connection ID |
| 104 |
ansible.builtin.set_fact: |
| 105 |
peer_id_1: "{{ vpc_peer.peering_id }}" |
| 106 |
|
| 107 |
- name: Re-create local account EC2 VPC Peering Connection request (idempotency check_mode) |
| 108 |
amazon.aws.ec2_vpc_peering: |
| 109 |
vpc_id: "{{ vpc_1 }}" |
| 110 |
peer_vpc_id: "{{ vpc_2 }}" |
| 111 |
state: present |
| 112 |
tags: |
| 113 |
Name: "{{ connection_name }}" |
| 114 |
check_mode: true |
| 115 |
register: vpc_peer |
| 116 |
|
| 117 |
- name: Assert success |
| 118 |
ansible.builtin.assert: |
| 119 |
that: |
| 120 |
- vpc_peer is not changed |
| 121 |
|
| 122 |
- name: Re-create local account EC2 VPC Peering Connection request (idempotency) |
| 123 |
amazon.aws.ec2_vpc_peering: |
| 124 |
vpc_id: "{{ vpc_1 }}" |
| 125 |
peer_vpc_id: "{{ vpc_2 }}" |
| 126 |
state: present |
| 127 |
tags: |
| 128 |
Name: "{{ connection_name }}" |
| 129 |
register: vpc_peer |
| 130 |
|
| 131 |
- name: Assert success |
| 132 |
ansible.builtin.assert: |
| 133 |
that: |
| 134 |
- vpc_peer is not changed |
| 135 |
- vpc_peer is successful |
| 136 |
- vpc_peer.peering_id == peer_id_1 |
| 137 |
|
| 138 |
- name: Create local account EC2 VPC Peering Connection request with accepter/requester reversed (idempotency check_mode) |
| 139 |
amazon.aws.ec2_vpc_peering: |
| 140 |
vpc_id: "{{ vpc_2 }}" |
| 141 |
peer_vpc_id: "{{ vpc_1 }}" |
| 142 |
state: present |
| 143 |
tags: |
| 144 |
Name: "{{ connection_name }}" |
| 145 |
check_mode: true |
| 146 |
register: vpc_peer |
| 147 |
|
| 148 |
- name: Assert success |
| 149 |
ansible.builtin.assert: |
| 150 |
that: |
| 151 |
- vpc_peer is not changed |
| 152 |
|
| 153 |
- name: Create local account EC2 VPC Peering Connection request with accepter/requester reversed (idempotency) |
| 154 |
amazon.aws.ec2_vpc_peering: |
| 155 |
vpc_id: "{{ vpc_2 }}" |
| 156 |
peer_vpc_id: "{{ vpc_1 }}" |
| 157 |
state: present |
| 158 |
tags: |
| 159 |
Name: "{{ connection_name }}" |
| 160 |
register: vpc_peer |
| 161 |
|
| 162 |
- name: Assert success |
| 163 |
ansible.builtin.assert: |
| 164 |
that: |
| 165 |
- vpc_peer is not changed |
| 166 |
- vpc_peer is successful |
| 167 |
- vpc_peer.peering_id == peer_id_1 |
| 168 |
|
| 169 |
- name: Get details on specific EC2 VPC Peering Connection |
| 170 |
amazon.aws.ec2_vpc_peering_info: |
| 171 |
peer_connection_ids: |
| 172 |
- "{{ peer_id_1 }}" |
| 173 |
register: peer_info |
| 174 |
|
| 175 |
- name: Assert expected values |
| 176 |
ansible.builtin.assert: |
| 177 |
that: |
| 178 |
- peer_info is successful |
| 179 |
- "'vpc_peering_connections' in peer_info" |
| 180 |
- "'accepter_vpc_info' in peer_details" |
| 181 |
- "'requester_vpc_info' in peer_details" |
| 182 |
- "'status' in peer_details" |
| 183 |
- "'code' in peer_details.status" |
| 184 |
- peer_details.status.code == "pending-acceptance" |
| 185 |
- "'message' in peer_details.status" |
| 186 |
- "'tags' in peer_details" |
| 187 |
- "'Name' in peer_details.tags" |
| 188 |
- peer_details.tags.Name == connection_name |
| 189 |
- "'vpc_peering_connection_id' in peer_details" |
| 190 |
- peer_details.vpc_peering_connection_id == peer_id_1 |
| 191 |
# Acceptor info isn't available until the connection has been accepted |
| 192 |
- "'cidr_block' not in acceptor_details" |
| 193 |
- "'cidr_block_set' not in acceptor_details" |
| 194 |
- "'peering_options' not in acceptor_details" |
| 195 |
- "'owner_id' in acceptor_details" |
| 196 |
- acceptor_details.owner_id == account_id |
| 197 |
- "'region' in acceptor_details" |
| 198 |
- acceptor_details.region == aws_region |
| 199 |
- "'vpc_id' in acceptor_details" |
| 200 |
- acceptor_details.vpc_id == vpc_2 |
| 201 |
# Information about the 'requesting' VPC |
| 202 |
- "'cidr_block' in requester_details" |
| 203 |
- requester_details.cidr_block == vpc_1_cidr |
| 204 |
- "'cidr_block_set' in requester_details" |
| 205 |
- requester_details.cidr_block_set | length == 1 |
| 206 |
- "'cidr_block' in requester_details.cidr_block_set[0]" |
| 207 |
- requester_details.cidr_block_set[0].cidr_block == vpc_1_cidr |
| 208 |
- "'peering_options' in requester_details" |
| 209 |
- "'owner_id' in requester_details" |
| 210 |
- requester_details.owner_id == account_id |
| 211 |
- "'region' in requester_details" |
| 212 |
- requester_details.region == aws_region |
| 213 |
- "'vpc_id' in requester_details" |
| 214 |
- requester_details.vpc_id == vpc_1 |
| 215 |
vars: |
| 216 |
peer_details: "{{ peer_info.vpc_peering_connections[0] }}" |
| 217 |
acceptor_details: '{{ peer_details["accepter_vpc_info"] }}' |
| 218 |
requester_details: '{{ peer_details["requester_vpc_info"] }}' |
| 219 |
|
| 220 |
- name: Get all EC2 VPC Peering Connections with specific filters |
| 221 |
amazon.aws.ec2_vpc_peering_info: |
| 222 |
filters: |
| 223 |
status-code: [pending-acceptance] |
| 224 |
register: pending_vpc_peers |
| 225 |
|
| 226 |
- name: Assert expected values |
| 227 |
ansible.builtin.assert: |
| 228 |
that: |
| 229 |
# Not guaranteed to just be us, only assert the shape |
| 230 |
- pending_vpc_peers is successful |
| 231 |
- "'vpc_peering_connections' in peer_info" |
| 232 |
- "'accepter_vpc_info' in peer_details" |
| 233 |
- "'requester_vpc_info' in peer_details" |
| 234 |
- "'status' in peer_details" |
| 235 |
- "'code' in peer_details.status" |
| 236 |
- peer_details.status.code == "pending-acceptance" |
| 237 |
- "'message' in peer_details.status" |
| 238 |
- "'tags' in peer_details" |
| 239 |
- "'vpc_peering_connection_id' in peer_details" |
| 240 |
# Acceptor info isn't available until the connection has been accepted |
| 241 |
- "'cidr_block' not in acceptor_details" |
| 242 |
- "'cidr_block_set' not in acceptor_details" |
| 243 |
- "'peering_options' not in acceptor_details" |
| 244 |
- "'owner_id' in acceptor_details" |
| 245 |
- "'region' in acceptor_details" |
| 246 |
- "'vpc_id' in acceptor_details" |
| 247 |
# Information about the 'requesting' VPC |
| 248 |
- "'cidr_block' in requester_details" |
| 249 |
- "'cidr_block_set' in requester_details" |
| 250 |
- "'cidr_block' in requester_details.cidr_block_set[0]" |
| 251 |
- "'peering_options' in requester_details" |
| 252 |
- "'owner_id' in requester_details" |
| 253 |
- "'region' in requester_details" |
| 254 |
- "'vpc_id' in requester_details" |
| 255 |
vars: |
| 256 |
peer_details: "{{ pending_vpc_peers.vpc_peering_connections[0] }}" |
| 257 |
acceptor_details: '{{ peer_details["accepter_vpc_info"] }}' |
| 258 |
requester_details: '{{ peer_details["requester_vpc_info"] }}' |
| 259 |
|
| 260 |
- name: Update tags on the EC2 VPC Peering Connection (check_mode) |
| 261 |
amazon.aws.ec2_vpc_peering: |
| 262 |
vpc_id: "{{ vpc_1 }}" |
| 263 |
peer_vpc_id: "{{ vpc_2 }}" |
| 264 |
state: present |
| 265 |
tags: |
| 266 |
Name: "{{ connection_name }}" |
| 267 |
testPrefix: "{{ resource_prefix }}" |
| 268 |
check_mode: true |
| 269 |
register: tag_peer |
| 270 |
|
| 271 |
- name: Assert success |
| 272 |
ansible.builtin.assert: |
| 273 |
that: |
| 274 |
- tag_peer is changed |
| 275 |
|
| 276 |
- name: Update tags on the EC2 VPC Peering Connection |
| 277 |
amazon.aws.ec2_vpc_peering: |
| 278 |
vpc_id: "{{ vpc_1 }}" |
| 279 |
peer_vpc_id: "{{ vpc_2 }}" |
| 280 |
state: present |
| 281 |
tags: |
| 282 |
Name: "{{ connection_name }}" |
| 283 |
testPrefix: "{{ resource_prefix }}" |
| 284 |
register: tag_peer |
| 285 |
|
| 286 |
- name: Assert success |
| 287 |
ansible.builtin.assert: |
| 288 |
that: |
| 289 |
- tag_peer is changed |
| 290 |
- tag_peer is successful |
| 291 |
- tag_peer.peering_id == peer_id_1 |
| 292 |
|
| 293 |
- name: Update tags on the EC2 VPC Peering Connection (idempotency check_mode) |
| 294 |
amazon.aws.ec2_vpc_peering: |
| 295 |
vpc_id: "{{ vpc_1 }}" |
| 296 |
peer_vpc_id: "{{ vpc_2 }}" |
| 297 |
state: present |
| 298 |
tags: |
| 299 |
Name: "{{ connection_name }}" |
| 300 |
testPrefix: "{{ resource_prefix }}" |
| 301 |
check_mode: true |
| 302 |
register: tag_peer |
| 303 |
|
| 304 |
- name: Assert success |
| 305 |
ansible.builtin.assert: |
| 306 |
that: |
| 307 |
- tag_peer is not changed |
| 308 |
|
| 309 |
- name: Update tags on the EC2 VPC Peering Connection (idempotency) |
| 310 |
amazon.aws.ec2_vpc_peering: |
| 311 |
vpc_id: "{{ vpc_1 }}" |
| 312 |
peer_vpc_id: "{{ vpc_2 }}" |
| 313 |
state: present |
| 314 |
tags: |
| 315 |
Name: "{{ connection_name }}" |
| 316 |
testPrefix: "{{ resource_prefix }}" |
| 317 |
register: tag_peer |
| 318 |
|
| 319 |
- name: Assert success |
| 320 |
ansible.builtin.assert: |
| 321 |
that: |
| 322 |
- tag_peer is not changed |
| 323 |
- tag_peer is successful |
| 324 |
- tag_peer.peering_id == peer_id_1 |
| 325 |
|
| 326 |
- name: Get details on specific EC2 VPC Peering Connection |
| 327 |
amazon.aws.ec2_vpc_peering_info: |
| 328 |
peer_connection_ids: |
| 329 |
- "{{ peer_id_1 }}" |
| 330 |
register: peer_info |
| 331 |
|
| 332 |
- name: Assert expected tags |
| 333 |
ansible.builtin.assert: |
| 334 |
that: |
| 335 |
- peer_info is successful |
| 336 |
- "'tags' in peer_details" |
| 337 |
- "'Name' in peer_details.tags" |
| 338 |
- "'testPrefix' in peer_details.tags" |
| 339 |
- peer_details.tags.Name == connection_name |
| 340 |
- peer_details.tags.testPrefix == resource_prefix |
| 341 |
vars: |
| 342 |
peer_details: "{{ peer_info.vpc_peering_connections[0] }}" |
| 343 |
|
| 344 |
- name: Accept local EC2 VPC Peering request (check_mode) |
| 345 |
amazon.aws.ec2_vpc_peering: |
| 346 |
peering_id: "{{ vpc_peer.peering_id }}" |
| 347 |
state: accept |
| 348 |
wait: true |
| 349 |
check_mode: true |
| 350 |
register: action_peer |
| 351 |
|
| 352 |
- name: Assert success |
| 353 |
ansible.builtin.assert: |
| 354 |
that: |
| 355 |
- action_peer is changed |
| 356 |
|
| 357 |
- name: Accept local EC2 VPC Peering request |
| 358 |
amazon.aws.ec2_vpc_peering: |
| 359 |
peering_id: "{{ vpc_peer.peering_id }}" |
| 360 |
state: accept |
| 361 |
wait: true |
| 362 |
register: action_peer |
| 363 |
|
| 364 |
- name: Assert success |
| 365 |
ansible.builtin.assert: |
| 366 |
that: |
| 367 |
- action_peer is changed |
| 368 |
- action_peer is successful |
| 369 |
- action_peer.peering_id == peer_id_1 |
| 370 |
- action_peer.vpc_peering_connection.accepter_vpc_info.cidr_block == vpc_2_cidr |
| 371 |
- action_peer.vpc_peering_connection.vpc_peering_connection_id == peer_id_1 |
| 372 |
|
| 373 |
- name: Get details on specific EC2 VPC Peering Connection |
| 374 |
amazon.aws.ec2_vpc_peering_info: |
| 375 |
peer_connection_ids: |
| 376 |
- "{{ peer_id_1 }}" |
| 377 |
register: peer_info |
| 378 |
|
| 379 |
- name: Assert expected values |
| 380 |
ansible.builtin.assert: |
| 381 |
that: |
| 382 |
- peer_info is successful |
| 383 |
- "'vpc_peering_connections' in peer_info" |
| 384 |
- "'accepter_vpc_info' in peer_details" |
| 385 |
- "'requester_vpc_info' in peer_details" |
| 386 |
- "'status' in peer_details" |
| 387 |
- "'code' in peer_details.status" |
| 388 |
- peer_details.status.code == "active" |
| 389 |
- "'message' in peer_details.status" |
| 390 |
- "'tags' in peer_details" |
| 391 |
- "'Name' in peer_details.tags" |
| 392 |
- peer_details.tags.Name == connection_name |
| 393 |
- "'testPrefix' in peer_details.tags" |
| 394 |
- peer_details.tags.testPrefix == resource_prefix |
| 395 |
- "'vpc_peering_connection_id' in peer_details" |
| 396 |
- peer_details.vpc_peering_connection_id == peer_id_1 |
| 397 |
# Information about the 'accepting' VPC should be available now |
| 398 |
- "'cidr_block' in acceptor_details" |
| 399 |
- acceptor_details.cidr_block == vpc_2_cidr |
| 400 |
- "'cidr_block_set' in acceptor_details" |
| 401 |
- acceptor_details.cidr_block_set | length == 1 |
| 402 |
- "'cidr_block' in acceptor_details.cidr_block_set[0]" |
| 403 |
- acceptor_details.cidr_block_set[0].cidr_block == vpc_2_cidr |
| 404 |
- "'peering_options' in acceptor_details" |
| 405 |
- "'owner_id' in acceptor_details" |
| 406 |
- acceptor_details.owner_id == account_id |
| 407 |
- "'region' in acceptor_details" |
| 408 |
- acceptor_details.region == aws_region |
| 409 |
- "'vpc_id' in acceptor_details" |
| 410 |
- acceptor_details.vpc_id == vpc_2 |
| 411 |
# Information about the 'requesting' VPC |
| 412 |
- "'cidr_block' in requester_details" |
| 413 |
- requester_details.cidr_block == vpc_1_cidr |
| 414 |
- "'cidr_block_set' in requester_details" |
| 415 |
- requester_details.cidr_block_set | length == 1 |
| 416 |
- "'cidr_block' in requester_details.cidr_block_set[0]" |
| 417 |
- requester_details.cidr_block_set[0].cidr_block == vpc_1_cidr |
| 418 |
- "'peering_options' in requester_details" |
| 419 |
- "'owner_id' in requester_details" |
| 420 |
- requester_details.owner_id == account_id |
| 421 |
- "'region' in requester_details" |
| 422 |
- requester_details.region == aws_region |
| 423 |
- "'vpc_id' in requester_details" |
| 424 |
- requester_details.vpc_id == vpc_1 |
| 425 |
vars: |
| 426 |
peer_details: "{{ peer_info.vpc_peering_connections[0] }}" |
| 427 |
acceptor_details: '{{ peer_details["accepter_vpc_info"] }}' |
| 428 |
requester_details: '{{ peer_details["requester_vpc_info"] }}' |
| 429 |
|
| 430 |
- name: Accept local EC2 VPC Peering request (idempotency check_mode) |
| 431 |
amazon.aws.ec2_vpc_peering: |
| 432 |
peering_id: "{{ vpc_peer.peering_id }}" |
| 433 |
state: accept |
| 434 |
check_mode: true |
| 435 |
register: action_peer |
| 436 |
|
| 437 |
- name: Assert success |
| 438 |
ansible.builtin.assert: |
| 439 |
that: |
| 440 |
- action_peer is not changed |
| 441 |
|
| 442 |
- name: Accept local EC2 VPC Peering request (idempotency) |
| 443 |
amazon.aws.ec2_vpc_peering: |
| 444 |
peering_id: "{{ vpc_peer.peering_id }}" |
| 445 |
state: accept |
| 446 |
register: action_peer |
| 447 |
|
| 448 |
- name: Assert success |
| 449 |
ansible.builtin.assert: |
| 450 |
that: |
| 451 |
- action_peer is not changed |
| 452 |
- action_peer is successful |
| 453 |
- action_peer.peering_id == peer_id_1 |
| 454 |
- action_peer.vpc_peering_connection.vpc_peering_connection_id == peer_id_1 |
| 455 |
|
| 456 |
- name: Delete a local EC2 VPC Peering Connection (check_mode) |
| 457 |
amazon.aws.ec2_vpc_peering: |
| 458 |
peering_id: "{{ vpc_peer.peering_id }}" |
| 459 |
state: absent |
| 460 |
check_mode: true |
| 461 |
register: delete_peer |
| 462 |
|
| 463 |
- name: Assert success |
| 464 |
ansible.builtin.assert: |
| 465 |
that: |
| 466 |
- delete_peer is changed |
| 467 |
|
| 468 |
- name: Delete a local EC2 VPC Peering Connection |
| 469 |
amazon.aws.ec2_vpc_peering: |
| 470 |
peering_id: "{{ vpc_peer.peering_id }}" |
| 471 |
state: absent |
| 472 |
register: delete_peer |
| 473 |
|
| 474 |
- name: Assert success |
| 475 |
ansible.builtin.assert: |
| 476 |
that: |
| 477 |
- delete_peer is changed |
| 478 |
- delete_peer is successful |
| 479 |
- "'peering_id' in delete_peer" |
| 480 |
|
| 481 |
- name: Get details on specific EC2 VPC Peering Connection |
| 482 |
amazon.aws.ec2_vpc_peering_info: |
| 483 |
peer_connection_ids: |
| 484 |
- "{{ peer_id_1 }}" |
| 485 |
register: peer_info |
| 486 |
|
| 487 |
- name: Assert expected values |
| 488 |
ansible.builtin.assert: |
| 489 |
that: |
| 490 |
- peer_info is successful |
| 491 |
- "'vpc_peering_connections' in peer_info" |
| 492 |
- "'accepter_vpc_info' in peer_details" |
| 493 |
- "'requester_vpc_info' in peer_details" |
| 494 |
- "'status' in peer_details" |
| 495 |
- "'code' in peer_details.status" |
| 496 |
- peer_details.status.code == "deleted" |
| 497 |
- "'message' in peer_details.status" |
| 498 |
- "'tags' in peer_details" |
| 499 |
- "'Name' in peer_details.tags" |
| 500 |
- peer_details.tags.Name == connection_name |
| 501 |
- "'testPrefix' in peer_details.tags" |
| 502 |
- peer_details.tags.testPrefix == resource_prefix |
| 503 |
- "'vpc_peering_connection_id' in peer_details" |
| 504 |
- peer_details.vpc_peering_connection_id == peer_id_1 |
| 505 |
# Information about the 'accepting' VPC is reduced again |
| 506 |
- "'cidr_block' not in acceptor_details" |
| 507 |
- "'cidr_block_set' not in acceptor_details" |
| 508 |
- "'peering_options' not in acceptor_details" |
| 509 |
- "'owner_id' in acceptor_details" |
| 510 |
- acceptor_details.owner_id == account_id |
| 511 |
- "'region' in acceptor_details" |
| 512 |
- acceptor_details.region == aws_region |
| 513 |
- "'vpc_id' in acceptor_details" |
| 514 |
- acceptor_details.vpc_id == vpc_2 |
| 515 |
# Information about the 'requesting' VPC is reduced once the VPC's deleted |
| 516 |
- "'cidr_block' not in requester_details" |
| 517 |
- "'cidr_block_set' not in requester_details" |
| 518 |
- "'peering_options' not in requester_details" |
| 519 |
- "'owner_id' in requester_details" |
| 520 |
- requester_details.owner_id == account_id |
| 521 |
- "'region' in requester_details" |
| 522 |
- requester_details.region == aws_region |
| 523 |
- "'vpc_id' in requester_details" |
| 524 |
- requester_details.vpc_id == vpc_1 |
| 525 |
vars: |
| 526 |
peer_details: "{{ peer_info.vpc_peering_connections[0] }}" |
| 527 |
acceptor_details: '{{ peer_details["accepter_vpc_info"] }}' |
| 528 |
requester_details: '{{ peer_details["requester_vpc_info"] }}' |
| 529 |
|
| 530 |
- name: Delete a local EC2 VPC Peering Connection (idempotency check_mode) |
| 531 |
amazon.aws.ec2_vpc_peering: |
| 532 |
peering_id: "{{ vpc_peer.peering_id }}" |
| 533 |
state: absent |
| 534 |
check_mode: true |
| 535 |
register: delete_peer |
| 536 |
|
| 537 |
- name: Assert success |
| 538 |
ansible.builtin.assert: |
| 539 |
that: |
| 540 |
- delete_peer is not changed |
| 541 |
|
| 542 |
- name: Delete a local EC2 VPC Peering Connection (idempotency) |
| 543 |
amazon.aws.ec2_vpc_peering: |
| 544 |
peering_id: "{{ vpc_peer.peering_id }}" |
| 545 |
state: absent |
| 546 |
register: delete_peer |
| 547 |
|
| 548 |
- name: Assert success |
| 549 |
ansible.builtin.assert: |
| 550 |
that: |
| 551 |
- delete_peer is not changed |
| 552 |
- delete_peer is successful |
| 553 |
|
| 554 |
- name: Create local account EC2 VPC Peering Connection |
| 555 |
amazon.aws.ec2_vpc_peering: |
| 556 |
vpc_id: "{{ vpc_1 }}" |
| 557 |
peer_vpc_id: "{{ vpc_2 }}" |
| 558 |
state: present |
| 559 |
tags: |
| 560 |
Name: Peering connection for VPC {{ vpc_1 }} to VPC {{ vpc_2 }} |
| 561 |
register: vpc_peer2 |
| 562 |
|
| 563 |
- name: Assert success |
| 564 |
ansible.builtin.assert: |
| 565 |
that: |
| 566 |
- vpc_peer2 is changed |
| 567 |
- vpc_peer2 is successful |
| 568 |
- "'peering_id' in vpc_peer2" |
| 569 |
- vpc_peer2.peering_id.startswith('pcx-') |
| 570 |
|
| 571 |
- name: Store Connection ID |
| 572 |
ansible.builtin.set_fact: |
| 573 |
peer_id_2: "{{ vpc_peer2.peering_id }}" |
| 574 |
|
| 575 |
- name: Reject a local EC2 VPC Peering Connection |
| 576 |
amazon.aws.ec2_vpc_peering: |
| 577 |
peering_id: "{{ vpc_peer2.peering_id }}" |
| 578 |
state: reject |
| 579 |
wait: true |
| 580 |
register: reject_peer |
| 581 |
|
| 582 |
- name: Assert success |
| 583 |
ansible.builtin.assert: |
| 584 |
that: |
| 585 |
- reject_peer is changed |
| 586 |
- reject_peer is successful |
| 587 |
- reject_peer.peering_id == peer_id_2 |
| 588 |
|
| 589 |
- name: Reject a local EC2 VPC Peering Connection (idempotency) |
| 590 |
amazon.aws.ec2_vpc_peering: |
| 591 |
peering_id: "{{ vpc_peer2.peering_id }}" |
| 592 |
state: reject |
| 593 |
register: reject_peer |
| 594 |
|
| 595 |
- name: Assert success |
| 596 |
ansible.builtin.assert: |
| 597 |
that: |
| 598 |
- reject_peer is not changed |
| 599 |
- reject_peer is successful |
| 600 |
- reject_peer.peering_id == peer_id_2 |
| 601 |
- reject_peer.vpc_peering_connection.vpc_peering_connection_id == peer_id_2 |
| 602 |
|
| 603 |
- name: Delete a local EC2 VPC Peering Connections |
| 604 |
amazon.aws.ec2_vpc_peering: |
| 605 |
peering_id: "{{ vpc_peer2.peering_id }}" |
| 606 |
state: absent |
| 607 |
register: delete_peer |
| 608 |
|
| 609 |
- name: Assert success |
| 610 |
ansible.builtin.assert: |
| 611 |
that: |
| 612 |
- delete_peer is not changed |
| 613 |
- delete_peer is successful |
| 614 |
|
| 615 |
always: |
| 616 |
- name: Find all EC2 VPC Peering Connections for our VPCs |
| 617 |
amazon.aws.ec2_vpc_peering_info: |
| 618 |
filters: |
| 619 |
accepter-vpc-info.vpc-id: "{{ item }}" |
| 620 |
register: peering_info |
| 621 |
loop: |
| 622 |
- "{{ vpc_1 }}" |
| 623 |
- "{{ vpc_2 }}" |
| 624 |
|
| 625 |
- ansible.builtin.set_fact: |
| 626 |
vpc_peering_connection_ids: '{{ _vpc_peering_connections | map(attribute="vpc_peering_connection_id") | list }}' |
| 627 |
vars: |
| 628 |
_vpc_peering_connections: '{{ peering_info.results | map(attribute="vpc_peering_connections") | flatten }}' |
| 629 |
ignore_errors: true |
| 630 |
|
| 631 |
# ============================================================ |
| 632 |
|
| 633 |
- name: Delete remaining EC2 VPC Peering Connections |
| 634 |
amazon.aws.ec2_vpc_peering: |
| 635 |
peering_id: "{{ item }}" |
| 636 |
state: absent |
| 637 |
ignore_errors: true |
| 638 |
loop: "{{ vpc_peering_connection_ids }}" |
| 639 |
|
| 640 |
- name: Tidy up VPCs |
| 641 |
amazon.aws.ec2_vpc_net: |
| 642 |
name: "{{ item.name }}" |
| 643 |
state: absent |
| 644 |
cidr_block: "{{ item.cidr }}" |
| 645 |
ignore_errors: true |
| 646 |
loop: |
| 647 |
- { name: "{{ vpc_2_name }}", cidr: "{{ vpc_2_cidr }}" } |
| 648 |
- { name: "{{ vpc_1_name }}", cidr: "{{ vpc_1_cidr }}" } |