| 1 |
--- |
| 2 |
- name: Ec2_vpc_endpoint 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 |
# BEGIN PRE-TEST SETUP |
| 12 |
- name: Create a VPC |
| 13 |
amazon.aws.ec2_vpc_net: |
| 14 |
state: present |
| 15 |
name: "{{ vpc_name }}" |
| 16 |
cidr_block: "{{ vpc_cidr }}" |
| 17 |
tags: |
| 18 |
AnsibleTest: ec2_vpc_endpoint |
| 19 |
AnsibleRun: "{{ resource_prefix }}" |
| 20 |
register: vpc_creation |
| 21 |
- name: Assert success |
| 22 |
ansible.builtin.assert: |
| 23 |
that: |
| 24 |
- vpc_creation is successful |
| 25 |
|
| 26 |
- name: Create an IGW |
| 27 |
amazon.aws.ec2_vpc_igw: |
| 28 |
vpc_id: "{{ vpc_creation.vpc.id }}" |
| 29 |
state: present |
| 30 |
tags: |
| 31 |
Name: "{{ resource_prefix }}" |
| 32 |
AnsibleTest: ec2_vpc_endpoint |
| 33 |
AnsibleRun: "{{ resource_prefix }}" |
| 34 |
register: igw_creation |
| 35 |
- name: Assert success |
| 36 |
ansible.builtin.assert: |
| 37 |
that: |
| 38 |
- igw_creation is successful |
| 39 |
|
| 40 |
- name: Create a minimal route table (no routes) |
| 41 |
amazon.aws.ec2_vpc_route_table: |
| 42 |
vpc_id: "{{ vpc_creation.vpc.id }}" |
| 43 |
tags: |
| 44 |
AnsibleTest: ec2_vpc_endpoint |
| 45 |
AnsibleRun: "{{ resource_prefix }}" |
| 46 |
Name: "{{ resource_prefix }}-empty" |
| 47 |
subnets: [] |
| 48 |
routes: [] |
| 49 |
register: rtb_creation_empty |
| 50 |
|
| 51 |
- name: Create a minimal route table (with IGW) |
| 52 |
amazon.aws.ec2_vpc_route_table: |
| 53 |
vpc_id: "{{ vpc_creation.vpc.id }}" |
| 54 |
tags: |
| 55 |
AnsibleTest: ec2_vpc_endpoint |
| 56 |
AnsibleRun: "{{ resource_prefix }}" |
| 57 |
Name: "{{ resource_prefix }}-igw" |
| 58 |
subnets: [] |
| 59 |
routes: |
| 60 |
- dest: "0.0.0.0/0" |
| 61 |
gateway_id: "{{ igw_creation.gateway_id }}" |
| 62 |
register: rtb_creation_igw |
| 63 |
|
| 64 |
- name: Save VPC info in a fact |
| 65 |
ansible.builtin.set_fact: |
| 66 |
vpc_id: "{{ vpc_creation.vpc.id }}" |
| 67 |
rtb_empty_id: "{{ rtb_creation_empty.route_table.id }}" |
| 68 |
rtb_igw_id: "{{ rtb_creation_igw.route_table.id }}" |
| 69 |
|
| 70 |
# ============================================================ |
| 71 |
# BEGIN TESTS |
| 72 |
|
| 73 |
# Minimal check_mode with _info |
| 74 |
- name: Fetch Endpoints in check_mode |
| 75 |
amazon.aws.ec2_vpc_endpoint_info: |
| 76 |
register: endpoint_info |
| 77 |
check_mode: true |
| 78 |
- name: Assert success |
| 79 |
ansible.builtin.assert: |
| 80 |
that: |
| 81 |
# May be run in parallel, the only thing we can guarantee is |
| 82 |
# - we shouldn't error |
| 83 |
# - we should return 'vpc_endpoints' (even if it's empty) |
| 84 |
- endpoint_info is successful |
| 85 |
- '"vpc_endpoints" in endpoint_info' |
| 86 |
|
| 87 |
# Attempt to create an endpoint |
| 88 |
- name: Create minimal endpoint (check mode) |
| 89 |
amazon.aws.ec2_vpc_endpoint: |
| 90 |
state: present |
| 91 |
vpc_id: "{{ vpc_id }}" |
| 92 |
service: "{{ endpoint_service_a }}" |
| 93 |
register: create_endpoint_check |
| 94 |
check_mode: true |
| 95 |
- name: Assert changed |
| 96 |
ansible.builtin.assert: |
| 97 |
that: |
| 98 |
- create_endpoint_check is changed |
| 99 |
|
| 100 |
- name: Create minimal endpoint |
| 101 |
amazon.aws.ec2_vpc_endpoint: |
| 102 |
state: present |
| 103 |
vpc_id: "{{ vpc_id }}" |
| 104 |
service: "{{ endpoint_service_a }}" |
| 105 |
wait: true |
| 106 |
register: create_endpoint |
| 107 |
- name: Check standard return values |
| 108 |
ansible.builtin.assert: |
| 109 |
that: |
| 110 |
- create_endpoint is changed |
| 111 |
- '"result" in create_endpoint' |
| 112 |
- '"creation_timestamp" in create_endpoint.result' |
| 113 |
- '"dns_entries" in create_endpoint.result' |
| 114 |
- '"groups" in create_endpoint.result' |
| 115 |
- '"network_interface_ids" in create_endpoint.result' |
| 116 |
- '"owner_id" in create_endpoint.result' |
| 117 |
- '"policy_document" in create_endpoint.result' |
| 118 |
- '"private_dns_enabled" in create_endpoint.result' |
| 119 |
- create_endpoint.result.private_dns_enabled == False |
| 120 |
- '"requester_managed" in create_endpoint.result' |
| 121 |
- create_endpoint.result.requester_managed == False |
| 122 |
- '"service_name" in create_endpoint.result' |
| 123 |
- create_endpoint.result.service_name == endpoint_service_a |
| 124 |
- '"state" in create_endpoint.result' |
| 125 |
- create_endpoint.result.state == "available" |
| 126 |
- '"vpc_endpoint_id" in create_endpoint.result' |
| 127 |
- create_endpoint.result.vpc_endpoint_id.startswith("vpce-") |
| 128 |
- '"vpc_endpoint_type" in create_endpoint.result' |
| 129 |
- create_endpoint.result.vpc_endpoint_type == "Gateway" |
| 130 |
- '"vpc_id" in create_endpoint.result' |
| 131 |
- create_endpoint.result.vpc_id == vpc_id |
| 132 |
|
| 133 |
- name: Save Endpoint info in a fact |
| 134 |
ansible.builtin.set_fact: |
| 135 |
endpoint_id: "{{ create_endpoint.result.vpc_endpoint_id }}" |
| 136 |
|
| 137 |
# Pull info about the endpoints |
| 138 |
- name: Fetch Endpoints (all) |
| 139 |
amazon.aws.ec2_vpc_endpoint_info: |
| 140 |
register: endpoint_info |
| 141 |
- name: Assert success |
| 142 |
ansible.builtin.assert: |
| 143 |
that: |
| 144 |
# We're fetching all endpoints, there's no guarantee what the values |
| 145 |
# will be |
| 146 |
- endpoint_info is successful |
| 147 |
- '"vpc_endpoints" in endpoint_info' |
| 148 |
- '"creation_timestamp" in first_endpoint' |
| 149 |
- '"policy_document" in first_endpoint' |
| 150 |
- '"route_table_ids" in first_endpoint' |
| 151 |
- '"service_name" in first_endpoint' |
| 152 |
- '"state" in first_endpoint' |
| 153 |
- '"vpc_endpoint_id" in first_endpoint' |
| 154 |
- '"vpc_id" in first_endpoint' |
| 155 |
# Not yet documented, but returned |
| 156 |
- '"dns_entries" in first_endpoint' |
| 157 |
- '"groups" in first_endpoint' |
| 158 |
- '"network_interface_ids" in first_endpoint' |
| 159 |
- '"owner_id" in first_endpoint' |
| 160 |
- '"private_dns_enabled" in first_endpoint' |
| 161 |
- '"requester_managed" in first_endpoint' |
| 162 |
- '"subnet_ids" in first_endpoint' |
| 163 |
- '"tags" in first_endpoint' |
| 164 |
- '"vpc_endpoint_type" in first_endpoint' |
| 165 |
# Make sure our endpoint is included |
| 166 |
- endpoint_id in ( endpoint_info | community.general.json_query("vpc_endpoints[*].vpc_endpoint_id") | list | flatten ) |
| 167 |
vars: |
| 168 |
first_endpoint: "{{ endpoint_info.vpc_endpoints[0] }}" |
| 169 |
|
| 170 |
- name: Fetch Endpoints (targetted by ID) |
| 171 |
amazon.aws.ec2_vpc_endpoint_info: |
| 172 |
vpc_endpoint_ids: "{{ endpoint_id }}" |
| 173 |
register: endpoint_info |
| 174 |
- name: Assert success |
| 175 |
ansible.builtin.assert: |
| 176 |
that: |
| 177 |
- endpoint_info is successful |
| 178 |
- '"vpc_endpoints" in endpoint_info' |
| 179 |
- '"creation_timestamp" in first_endpoint' |
| 180 |
- '"policy_document" in first_endpoint' |
| 181 |
- '"route_table_ids" in first_endpoint' |
| 182 |
- first_endpoint.route_table_ids | length == 0 |
| 183 |
- '"service_name" in first_endpoint' |
| 184 |
- first_endpoint.service_name == endpoint_service_a |
| 185 |
- '"state" in first_endpoint' |
| 186 |
- first_endpoint.state == "available" |
| 187 |
- '"vpc_endpoint_id" in first_endpoint' |
| 188 |
- first_endpoint.vpc_endpoint_id == endpoint_id |
| 189 |
- '"vpc_id" in first_endpoint' |
| 190 |
- first_endpoint.vpc_id == vpc_id |
| 191 |
# Not yet documented, but returned |
| 192 |
- '"dns_entries" in first_endpoint' |
| 193 |
- '"groups" in first_endpoint' |
| 194 |
- '"network_interface_ids" in first_endpoint' |
| 195 |
- '"owner_id" in first_endpoint' |
| 196 |
- '"private_dns_enabled" in first_endpoint' |
| 197 |
- first_endpoint.private_dns_enabled == False |
| 198 |
- '"requester_managed" in first_endpoint' |
| 199 |
- first_endpoint.requester_managed == False |
| 200 |
- '"subnet_ids" in first_endpoint' |
| 201 |
- '"tags" in first_endpoint' |
| 202 |
- '"vpc_endpoint_type" in first_endpoint' |
| 203 |
vars: |
| 204 |
first_endpoint: "{{ endpoint_info.vpc_endpoints[0] }}" |
| 205 |
|
| 206 |
- name: Fetch Endpoints (targetted by VPC) |
| 207 |
amazon.aws.ec2_vpc_endpoint_info: |
| 208 |
filters: |
| 209 |
vpc-id: |
| 210 |
- "{{ vpc_id }}" |
| 211 |
register: endpoint_info |
| 212 |
- name: Assert success |
| 213 |
ansible.builtin.assert: |
| 214 |
that: |
| 215 |
- endpoint_info is successful |
| 216 |
- '"vpc_endpoints" in endpoint_info' |
| 217 |
- '"creation_timestamp" in first_endpoint' |
| 218 |
- '"policy_document" in first_endpoint' |
| 219 |
- '"route_table_ids" in first_endpoint' |
| 220 |
- '"service_name" in first_endpoint' |
| 221 |
- first_endpoint.service_name == endpoint_service_a |
| 222 |
- '"state" in first_endpoint' |
| 223 |
- first_endpoint.state == "available" |
| 224 |
- '"vpc_endpoint_id" in first_endpoint' |
| 225 |
- first_endpoint.vpc_endpoint_id == endpoint_id |
| 226 |
- '"vpc_id" in first_endpoint' |
| 227 |
- first_endpoint.vpc_id == vpc_id |
| 228 |
# Not yet documented, but returned |
| 229 |
- '"dns_entries" in first_endpoint' |
| 230 |
- '"groups" in first_endpoint' |
| 231 |
- '"network_interface_ids" in first_endpoint' |
| 232 |
- '"owner_id" in first_endpoint' |
| 233 |
- '"private_dns_enabled" in first_endpoint' |
| 234 |
- first_endpoint.private_dns_enabled == False |
| 235 |
- '"requester_managed" in first_endpoint' |
| 236 |
- first_endpoint.requester_managed == False |
| 237 |
- '"subnet_ids" in first_endpoint' |
| 238 |
- '"tags" in first_endpoint' |
| 239 |
- '"vpc_endpoint_type" in first_endpoint' |
| 240 |
vars: |
| 241 |
first_endpoint: "{{ endpoint_info.vpc_endpoints[0] }}" |
| 242 |
|
| 243 |
# matches on parameters without explicitly passing the endpoint ID |
| 244 |
- name: Create minimal endpoint - idempotency (check mode) |
| 245 |
amazon.aws.ec2_vpc_endpoint: |
| 246 |
state: present |
| 247 |
vpc_id: "{{ vpc_id }}" |
| 248 |
service: "{{ endpoint_service_a }}" |
| 249 |
register: create_endpoint_idem_check |
| 250 |
check_mode: true |
| 251 |
- ansible.builtin.assert: |
| 252 |
that: |
| 253 |
- create_endpoint_idem_check is not changed |
| 254 |
|
| 255 |
- name: Create minimal endpoint - idempotency |
| 256 |
amazon.aws.ec2_vpc_endpoint: |
| 257 |
state: present |
| 258 |
vpc_id: "{{ vpc_id }}" |
| 259 |
service: "{{ endpoint_service_a }}" |
| 260 |
register: create_endpoint_idem |
| 261 |
- ansible.builtin.assert: |
| 262 |
that: |
| 263 |
- create_endpoint_idem is not changed |
| 264 |
|
| 265 |
- name: Delete minimal endpoint by ID (check_mode) |
| 266 |
amazon.aws.ec2_vpc_endpoint: |
| 267 |
state: absent |
| 268 |
vpc_endpoint_id: "{{ endpoint_id }}" |
| 269 |
check_mode: true |
| 270 |
register: endpoint_delete_check |
| 271 |
- ansible.builtin.assert: |
| 272 |
that: |
| 273 |
- endpoint_delete_check is changed |
| 274 |
|
| 275 |
- name: Delete minimal endpoint by ID |
| 276 |
amazon.aws.ec2_vpc_endpoint: |
| 277 |
state: absent |
| 278 |
vpc_endpoint_id: "{{ endpoint_id }}" |
| 279 |
register: endpoint_delete_check |
| 280 |
- ansible.builtin.assert: |
| 281 |
that: |
| 282 |
- endpoint_delete_check is changed |
| 283 |
|
| 284 |
- name: Delete minimal endpoint by ID - idempotency (check_mode) |
| 285 |
amazon.aws.ec2_vpc_endpoint: |
| 286 |
state: absent |
| 287 |
vpc_endpoint_id: "{{ endpoint_id }}" |
| 288 |
check_mode: true |
| 289 |
register: endpoint_delete_check |
| 290 |
- ansible.builtin.assert: |
| 291 |
that: |
| 292 |
- endpoint_delete_check is not changed |
| 293 |
|
| 294 |
- name: Delete minimal endpoint by ID - idempotency |
| 295 |
amazon.aws.ec2_vpc_endpoint: |
| 296 |
state: absent |
| 297 |
vpc_endpoint_id: "{{ endpoint_id }}" |
| 298 |
register: endpoint_delete_check |
| 299 |
- ansible.builtin.assert: |
| 300 |
that: |
| 301 |
- endpoint_delete_check is not changed |
| 302 |
|
| 303 |
- name: Fetch Endpoints by ID (expect failed) |
| 304 |
amazon.aws.ec2_vpc_endpoint_info: |
| 305 |
vpc_endpoint_ids: "{{ endpoint_id }}" |
| 306 |
ignore_errors: true |
| 307 |
register: endpoint_info |
| 308 |
- name: Assert endpoint does not exist |
| 309 |
ansible.builtin.assert: |
| 310 |
that: |
| 311 |
- endpoint_info is successful |
| 312 |
- '"does not exist" in endpoint_info.msg' |
| 313 |
- endpoint_info.vpc_endpoints | length == 0 |
| 314 |
|
| 315 |
# Attempt to create an endpoint with a route table |
| 316 |
- name: Create an endpoint with route table (check mode) |
| 317 |
amazon.aws.ec2_vpc_endpoint: |
| 318 |
state: present |
| 319 |
vpc_id: "{{ vpc_id }}" |
| 320 |
service: "{{ endpoint_service_a }}" |
| 321 |
route_table_ids: |
| 322 |
- "{{ rtb_empty_id }}" |
| 323 |
register: create_endpoint_check |
| 324 |
check_mode: true |
| 325 |
- name: Assert changed |
| 326 |
ansible.builtin.assert: |
| 327 |
that: |
| 328 |
- create_endpoint_check is changed |
| 329 |
|
| 330 |
- name: Create an endpoint with route table |
| 331 |
amazon.aws.ec2_vpc_endpoint: |
| 332 |
state: present |
| 333 |
vpc_id: "{{ vpc_id }}" |
| 334 |
service: "{{ endpoint_service_a }}" |
| 335 |
route_table_ids: |
| 336 |
- "{{ rtb_empty_id }}" |
| 337 |
wait: true |
| 338 |
register: create_rtb_endpoint |
| 339 |
- name: Check standard return values |
| 340 |
ansible.builtin.assert: |
| 341 |
that: |
| 342 |
- create_rtb_endpoint is changed |
| 343 |
- '"result" in create_rtb_endpoint' |
| 344 |
- '"creation_timestamp" in create_rtb_endpoint.result' |
| 345 |
- '"dns_entries" in create_rtb_endpoint.result' |
| 346 |
- '"groups" in create_rtb_endpoint.result' |
| 347 |
- '"network_interface_ids" in create_rtb_endpoint.result' |
| 348 |
- '"owner_id" in create_rtb_endpoint.result' |
| 349 |
- '"policy_document" in create_rtb_endpoint.result' |
| 350 |
- '"private_dns_enabled" in create_rtb_endpoint.result' |
| 351 |
- '"route_table_ids" in create_rtb_endpoint.result' |
| 352 |
- create_rtb_endpoint.result.route_table_ids | length == 1 |
| 353 |
- create_rtb_endpoint.result.route_table_ids[0] == rtb_empty_id |
| 354 |
- create_rtb_endpoint.result.private_dns_enabled == False |
| 355 |
- '"requester_managed" in create_rtb_endpoint.result' |
| 356 |
- create_rtb_endpoint.result.requester_managed == False |
| 357 |
- '"service_name" in create_rtb_endpoint.result' |
| 358 |
- create_rtb_endpoint.result.service_name == endpoint_service_a |
| 359 |
- '"state" in create_endpoint.result' |
| 360 |
- create_rtb_endpoint.result.state == "available" |
| 361 |
- '"vpc_endpoint_id" in create_rtb_endpoint.result' |
| 362 |
- create_rtb_endpoint.result.vpc_endpoint_id.startswith("vpce-") |
| 363 |
- '"vpc_endpoint_type" in create_rtb_endpoint.result' |
| 364 |
- create_rtb_endpoint.result.vpc_endpoint_type == "Gateway" |
| 365 |
- '"vpc_id" in create_rtb_endpoint.result' |
| 366 |
- create_rtb_endpoint.result.vpc_id == vpc_id |
| 367 |
|
| 368 |
- name: Save Endpoint info in a fact |
| 369 |
ansible.builtin.set_fact: |
| 370 |
rtb_endpoint_id: "{{ create_rtb_endpoint.result.vpc_endpoint_id }}" |
| 371 |
|
| 372 |
- name: Create an endpoint with route table - idempotency (check mode) |
| 373 |
amazon.aws.ec2_vpc_endpoint: |
| 374 |
state: present |
| 375 |
vpc_id: "{{ vpc_id }}" |
| 376 |
service: "{{ endpoint_service_a }}" |
| 377 |
route_table_ids: |
| 378 |
- "{{ rtb_empty_id }}" |
| 379 |
register: create_endpoint_check |
| 380 |
check_mode: true |
| 381 |
- name: Assert changed |
| 382 |
ansible.builtin.assert: |
| 383 |
that: |
| 384 |
- create_endpoint_check is not changed |
| 385 |
|
| 386 |
- name: Create an endpoint with route table - idempotency |
| 387 |
amazon.aws.ec2_vpc_endpoint: |
| 388 |
state: present |
| 389 |
vpc_id: "{{ vpc_id }}" |
| 390 |
service: "{{ endpoint_service_a }}" |
| 391 |
route_table_ids: |
| 392 |
- "{{ rtb_empty_id }}" |
| 393 |
register: create_endpoint_check |
| 394 |
check_mode: true |
| 395 |
- name: Assert changed |
| 396 |
ansible.builtin.assert: |
| 397 |
that: |
| 398 |
- create_endpoint_check is not changed |
| 399 |
|
| 400 |
# # Endpoint modifications are not yet supported by the module |
| 401 |
# # A Change the route table for the endpoint |
| 402 |
# - name: Change the route table for the endpoint (check_mode) |
| 403 |
# amazon.aws.ec2_vpc_endpoint: |
| 404 |
# state: present |
| 405 |
# vpc_id: '{{ vpc_id }}' |
| 406 |
# vpc_endpoint_id: "{{ rtb_endpoint_id }}" |
| 407 |
# service: '{{ endpoint_service_a }}' |
| 408 |
# route_table_ids: |
| 409 |
# - '{{ rtb_igw_id }}' |
| 410 |
# check_mode: True |
| 411 |
# register: check_two_rtbs_endpoint |
| 412 |
# |
| 413 |
# - name: Assert second route table would be added |
| 414 |
# assert: |
| 415 |
# that: |
| 416 |
# - check_two_rtbs_endpoint.changed |
| 417 |
# |
| 418 |
# - name: Change the route table for the endpoint |
| 419 |
# amazon.aws.ec2_vpc_endpoint: |
| 420 |
# state: present |
| 421 |
# vpc_id: '{{ vpc_id }}' |
| 422 |
# vpc_endpoint_id: "{{ rtb_endpoint_id }}" |
| 423 |
# service: '{{ endpoint_service_a }}' |
| 424 |
# route_table_ids: |
| 425 |
# - '{{ rtb_igw_id }}' |
| 426 |
# register: two_rtbs_endpoint |
| 427 |
# |
| 428 |
# - name: Assert second route table would be added |
| 429 |
# assert: |
| 430 |
# that: |
| 431 |
# - check_two_rtbs_endpoint.changed |
| 432 |
# - two_rtbs_endpoint.result.route_table_ids | length == 1 |
| 433 |
# - two_rtbs_endpoint.result.route_table_ids[0] == '{{ rtb_igw_id }}' |
| 434 |
# |
| 435 |
# - name: Change the route table for the endpoint - idempotency (check_mode) |
| 436 |
# amazon.aws.ec2_vpc_endpoint: |
| 437 |
# state: present |
| 438 |
# vpc_id: '{{ vpc_id }}' |
| 439 |
# vpc_endpoint_id: "{{ rtb_endpoint_id }}" |
| 440 |
# service: '{{ endpoint_service_a }}' |
| 441 |
# route_table_ids: |
| 442 |
# - '{{ rtb_igw_id }}' |
| 443 |
# check_mode: True |
| 444 |
# register: check_two_rtbs_endpoint |
| 445 |
# |
| 446 |
# - name: Assert route table would not change |
| 447 |
# assert: |
| 448 |
# that: |
| 449 |
# - not check_two_rtbs_endpoint.changed |
| 450 |
# |
| 451 |
# - name: Change the route table for the endpoint - idempotency |
| 452 |
# amazon.aws.ec2_vpc_endpoint: |
| 453 |
# state: present |
| 454 |
# vpc_id: '{{ vpc_id }}' |
| 455 |
# vpc_endpoint_id: "{{ rtb_endpoint_id }}" |
| 456 |
# service: '{{ endpoint_service_a }}' |
| 457 |
# route_table_ids: |
| 458 |
# - '{{ rtb_igw_id }}' |
| 459 |
# register: two_rtbs_endpoint |
| 460 |
# |
| 461 |
# - name: Assert route table would not change |
| 462 |
# assert: |
| 463 |
# that: |
| 464 |
# - not check_two_rtbs_endpoint.changed |
| 465 |
|
| 466 |
- name: Tag the endpoint (check_mode) |
| 467 |
amazon.aws.ec2_vpc_endpoint: |
| 468 |
state: present |
| 469 |
vpc_id: "{{ vpc_id }}" |
| 470 |
vpc_endpoint_id: "{{ rtb_endpoint_id }}" |
| 471 |
service: "{{ endpoint_service_a }}" |
| 472 |
route_table_ids: |
| 473 |
- "{{ rtb_empty_id }}" |
| 474 |
tags: |
| 475 |
camelCase: helloWorld |
| 476 |
PascalCase: HelloWorld |
| 477 |
snake_case: hello_world |
| 478 |
Title Case: Hello World |
| 479 |
lowercase spaced: hello world |
| 480 |
check_mode: true |
| 481 |
register: check_tag_vpc_endpoint |
| 482 |
|
| 483 |
- name: Assert tags would have changed |
| 484 |
ansible.builtin.assert: |
| 485 |
that: |
| 486 |
- check_tag_vpc_endpoint.changed |
| 487 |
|
| 488 |
- name: Tag the endpoint |
| 489 |
amazon.aws.ec2_vpc_endpoint: |
| 490 |
state: present |
| 491 |
vpc_id: "{{ vpc_id }}" |
| 492 |
vpc_endpoint_id: "{{ rtb_endpoint_id }}" |
| 493 |
service: "{{ endpoint_service_a }}" |
| 494 |
route_table_ids: |
| 495 |
- "{{ rtb_igw_id }}" |
| 496 |
tags: |
| 497 |
testPrefix: "{{ resource_prefix }}" |
| 498 |
camelCase: helloWorld |
| 499 |
PascalCase: HelloWorld |
| 500 |
snake_case: hello_world |
| 501 |
Title Case: Hello World |
| 502 |
lowercase spaced: hello world |
| 503 |
register: tag_vpc_endpoint |
| 504 |
|
| 505 |
- name: Assert tags are successful |
| 506 |
ansible.builtin.assert: |
| 507 |
that: |
| 508 |
- tag_vpc_endpoint.changed |
| 509 |
- tag_vpc_endpoint.result.tags | length == 6 |
| 510 |
- endpoint_tags["testPrefix"] == resource_prefix |
| 511 |
- endpoint_tags["camelCase"] == "helloWorld" |
| 512 |
- endpoint_tags["PascalCase"] == "HelloWorld" |
| 513 |
- endpoint_tags["snake_case"] == "hello_world" |
| 514 |
- endpoint_tags["Title Case"] == "Hello World" |
| 515 |
- endpoint_tags["lowercase spaced"] == "hello world" |
| 516 |
vars: |
| 517 |
endpoint_tags: "{{ tag_vpc_endpoint.result.tags | items2dict(key_name='Key', value_name='Value') }}" |
| 518 |
|
| 519 |
- name: Query by tag |
| 520 |
amazon.aws.ec2_vpc_endpoint_info: |
| 521 |
filters: |
| 522 |
tag:testPrefix: |
| 523 |
- "{{ resource_prefix }}" |
| 524 |
register: tag_result |
| 525 |
|
| 526 |
- name: Assert tag lookup found endpoint |
| 527 |
ansible.builtin.assert: |
| 528 |
that: |
| 529 |
- tag_result is successful |
| 530 |
- '"vpc_endpoints" in tag_result' |
| 531 |
- first_endpoint.vpc_endpoint_id == rtb_endpoint_id |
| 532 |
vars: |
| 533 |
first_endpoint: "{{ tag_result.vpc_endpoints[0] }}" |
| 534 |
|
| 535 |
- name: Tag the endpoint - idempotency (check_mode) |
| 536 |
amazon.aws.ec2_vpc_endpoint: |
| 537 |
state: present |
| 538 |
vpc_id: "{{ vpc_id }}" |
| 539 |
vpc_endpoint_id: "{{ rtb_endpoint_id }}" |
| 540 |
service: "{{ endpoint_service_a }}" |
| 541 |
route_table_ids: |
| 542 |
- "{{ rtb_igw_id }}" |
| 543 |
tags: |
| 544 |
testPrefix: "{{ resource_prefix }}" |
| 545 |
camelCase: helloWorld |
| 546 |
PascalCase: HelloWorld |
| 547 |
snake_case: hello_world |
| 548 |
Title Case: Hello World |
| 549 |
lowercase spaced: hello world |
| 550 |
register: tag_vpc_endpoint_again |
| 551 |
|
| 552 |
- name: Assert tags would not change |
| 553 |
ansible.builtin.assert: |
| 554 |
that: |
| 555 |
- not tag_vpc_endpoint_again.changed |
| 556 |
|
| 557 |
- name: Tag the endpoint - idempotency |
| 558 |
amazon.aws.ec2_vpc_endpoint: |
| 559 |
state: present |
| 560 |
vpc_id: "{{ vpc_id }}" |
| 561 |
vpc_endpoint_id: "{{ rtb_endpoint_id }}" |
| 562 |
service: "{{ endpoint_service_a }}" |
| 563 |
route_table_ids: |
| 564 |
- "{{ rtb_igw_id }}" |
| 565 |
tags: |
| 566 |
testPrefix: "{{ resource_prefix }}" |
| 567 |
camelCase: helloWorld |
| 568 |
PascalCase: HelloWorld |
| 569 |
snake_case: hello_world |
| 570 |
Title Case: Hello World |
| 571 |
lowercase spaced: hello world |
| 572 |
register: tag_vpc_endpoint_again |
| 573 |
|
| 574 |
- name: Assert tags would not change |
| 575 |
ansible.builtin.assert: |
| 576 |
that: |
| 577 |
- not tag_vpc_endpoint_again.changed |
| 578 |
|
| 579 |
- name: Add a tag (check_mode) |
| 580 |
amazon.aws.ec2_vpc_endpoint: |
| 581 |
state: present |
| 582 |
vpc_id: "{{ vpc_id }}" |
| 583 |
vpc_endpoint_id: "{{ rtb_endpoint_id }}" |
| 584 |
service: "{{ endpoint_service_a }}" |
| 585 |
route_table_ids: |
| 586 |
- "{{ rtb_igw_id }}" |
| 587 |
tags: |
| 588 |
new_tag: ANewTag |
| 589 |
check_mode: true |
| 590 |
register: check_tag_vpc_endpoint |
| 591 |
|
| 592 |
- name: Assert tags would have changed |
| 593 |
ansible.builtin.assert: |
| 594 |
that: |
| 595 |
- check_tag_vpc_endpoint.changed |
| 596 |
|
| 597 |
- name: Add a tag (purge_tags=False) |
| 598 |
amazon.aws.ec2_vpc_endpoint: |
| 599 |
state: present |
| 600 |
vpc_id: "{{ vpc_id }}" |
| 601 |
vpc_endpoint_id: "{{ rtb_endpoint_id }}" |
| 602 |
service: "{{ endpoint_service_a }}" |
| 603 |
route_table_ids: |
| 604 |
- "{{ rtb_igw_id }}" |
| 605 |
purge_tags: false |
| 606 |
tags: |
| 607 |
new_tag: ANewTag |
| 608 |
register: add_tag_vpc_endpoint |
| 609 |
|
| 610 |
- name: Assert tags changed |
| 611 |
ansible.builtin.assert: |
| 612 |
that: |
| 613 |
- add_tag_vpc_endpoint.changed |
| 614 |
- add_tag_vpc_endpoint.result.tags | length == 7 |
| 615 |
- endpoint_tags["testPrefix"] == resource_prefix |
| 616 |
- endpoint_tags["camelCase"] == "helloWorld" |
| 617 |
- endpoint_tags["PascalCase"] == "HelloWorld" |
| 618 |
- endpoint_tags["snake_case"] == "hello_world" |
| 619 |
- endpoint_tags["Title Case"] == "Hello World" |
| 620 |
- endpoint_tags["lowercase spaced"] == "hello world" |
| 621 |
- endpoint_tags["new_tag"] == "ANewTag" |
| 622 |
vars: |
| 623 |
endpoint_tags: "{{ add_tag_vpc_endpoint.result.tags | items2dict(key_name='Key', value_name='Value') }}" |
| 624 |
|
| 625 |
- name: Add a tag (purge_tags=True) |
| 626 |
amazon.aws.ec2_vpc_endpoint: |
| 627 |
state: present |
| 628 |
vpc_id: "{{ vpc_id }}" |
| 629 |
vpc_endpoint_id: "{{ rtb_endpoint_id }}" |
| 630 |
service: "{{ endpoint_service_a }}" |
| 631 |
route_table_ids: |
| 632 |
- "{{ rtb_igw_id }}" |
| 633 |
tags: |
| 634 |
another_new_tag: AnotherNewTag |
| 635 |
purge_tags: true |
| 636 |
register: purge_tag_vpc_endpoint |
| 637 |
|
| 638 |
- name: Assert tags changed |
| 639 |
ansible.builtin.assert: |
| 640 |
that: |
| 641 |
- purge_tag_vpc_endpoint.changed |
| 642 |
- purge_tag_vpc_endpoint.result.tags | length == 1 |
| 643 |
- endpoint_tags["another_new_tag"] == "AnotherNewTag" |
| 644 |
vars: |
| 645 |
endpoint_tags: "{{ purge_tag_vpc_endpoint.result.tags | items2dict(key_name='Key', value_name='Value') }}" |
| 646 |
|
| 647 |
- name: Delete minimal route table (no routes) |
| 648 |
amazon.aws.ec2_vpc_route_table: |
| 649 |
state: absent |
| 650 |
lookup: id |
| 651 |
route_table_id: "{{ rtb_empty_id }}" |
| 652 |
register: rtb_delete |
| 653 |
- ansible.builtin.assert: |
| 654 |
that: |
| 655 |
- rtb_delete is changed |
| 656 |
|
| 657 |
- name: Delete minimal route table (IGW route) |
| 658 |
amazon.aws.ec2_vpc_route_table: |
| 659 |
state: absent |
| 660 |
lookup: id |
| 661 |
route_table_id: "{{ rtb_igw_id }}" |
| 662 |
- ansible.builtin.assert: |
| 663 |
that: |
| 664 |
- rtb_delete is changed |
| 665 |
|
| 666 |
- name: Delete route table endpoint by ID |
| 667 |
amazon.aws.ec2_vpc_endpoint: |
| 668 |
state: absent |
| 669 |
vpc_endpoint_id: "{{ rtb_endpoint_id }}" |
| 670 |
register: endpoint_delete_check |
| 671 |
- ansible.builtin.assert: |
| 672 |
that: |
| 673 |
- endpoint_delete_check is changed |
| 674 |
|
| 675 |
- name: Delete minimal endpoint by ID - idempotency (check_mode) |
| 676 |
amazon.aws.ec2_vpc_endpoint: |
| 677 |
state: absent |
| 678 |
vpc_endpoint_id: "{{ rtb_endpoint_id }}" |
| 679 |
check_mode: true |
| 680 |
register: endpoint_delete_check |
| 681 |
- ansible.builtin.assert: |
| 682 |
that: |
| 683 |
- endpoint_delete_check is not changed |
| 684 |
|
| 685 |
- name: Delete endpoint by ID - idempotency |
| 686 |
amazon.aws.ec2_vpc_endpoint: |
| 687 |
state: absent |
| 688 |
vpc_endpoint_id: "{{ endpoint_id }}" |
| 689 |
register: endpoint_delete_check |
| 690 |
- ansible.builtin.assert: |
| 691 |
that: |
| 692 |
- endpoint_delete_check is not changed |
| 693 |
|
| 694 |
- name: Create interface endpoint |
| 695 |
amazon.aws.ec2_vpc_endpoint: |
| 696 |
state: present |
| 697 |
vpc_id: "{{ vpc_id }}" |
| 698 |
service: "{{ endpoint_service_a }}" |
| 699 |
vpc_endpoint_type: Interface |
| 700 |
register: create_interface_endpoint |
| 701 |
- name: Check that the interface endpoint was created properly |
| 702 |
ansible.builtin.assert: |
| 703 |
that: |
| 704 |
- create_interface_endpoint is changed |
| 705 |
- create_interface_endpoint.result.vpc_endpoint_type == "Interface" |
| 706 |
- name: Delete interface endpoint |
| 707 |
amazon.aws.ec2_vpc_endpoint: |
| 708 |
state: absent |
| 709 |
vpc_endpoint_id: "{{ create_interface_endpoint.result.vpc_endpoint_id }}" |
| 710 |
register: interface_endpoint_delete_check |
| 711 |
- ansible.builtin.assert: |
| 712 |
that: |
| 713 |
- interface_endpoint_delete_check is changed |
| 714 |
|
| 715 |
- name: Create a subnet |
| 716 |
amazon.aws.ec2_vpc_subnet: |
| 717 |
state: present |
| 718 |
vpc_id: "{{ vpc_id }}" |
| 719 |
az: "{{ aws_region }}a" |
| 720 |
cidr: "{{ vpc_cidr }}" |
| 721 |
register: interface_endpoint_create_subnet_check |
| 722 |
|
| 723 |
- name: Create a security group |
| 724 |
amazon.aws.ec2_security_group: |
| 725 |
name: securitygroup-prodext |
| 726 |
description: security group for Ansible interface endpoint |
| 727 |
state: present |
| 728 |
vpc_id: "{{ vpc_id }}" |
| 729 |
rules: |
| 730 |
- proto: tcp |
| 731 |
from_port: 1 |
| 732 |
to_port: 65535 |
| 733 |
cidr_ip: "0.0.0.0/0" |
| 734 |
register: interface_endpoint_create_sg_check |
| 735 |
|
| 736 |
- name: Create interface endpoint attached to a subnet |
| 737 |
amazon.aws.ec2_vpc_endpoint: |
| 738 |
state: present |
| 739 |
vpc_id: "{{ vpc_id }}" |
| 740 |
service: "{{ endpoint_service_c }}" |
| 741 |
vpc_endpoint_type: Interface |
| 742 |
vpc_endpoint_subnets: "{{ interface_endpoint_create_subnet_check.subnet.id }}" |
| 743 |
vpc_endpoint_security_groups: "{{ interface_endpoint_create_sg_check.group_id }}" |
| 744 |
wait: true |
| 745 |
register: create_interface_endpoint_with_sg_subnets |
| 746 |
- name: Check that the interface endpoint was created properly |
| 747 |
ansible.builtin.assert: |
| 748 |
that: |
| 749 |
- create_interface_endpoint_with_sg_subnets is changed |
| 750 |
- create_interface_endpoint_with_sg_subnets.result.vpc_endpoint_type == "Interface" |
| 751 |
|
| 752 |
- name: Delete interface endpoint |
| 753 |
amazon.aws.ec2_vpc_endpoint: |
| 754 |
state: absent |
| 755 |
vpc_endpoint_id: "{{ create_interface_endpoint_with_sg_subnets.result.vpc_endpoint_id }}" |
| 756 |
wait: true |
| 757 |
register: create_interface_endpoint_with_sg_subnets_delete_check |
| 758 |
- ansible.builtin.assert: |
| 759 |
that: |
| 760 |
- create_interface_endpoint_with_sg_subnets_delete_check is changed |
| 761 |
|
| 762 |
# ============================================================ |
| 763 |
# BEGIN POST-TEST CLEANUP |
| 764 |
always: |
| 765 |
- name: Query any remain endpoints we created |
| 766 |
amazon.aws.ec2_vpc_endpoint_info: |
| 767 |
filters: |
| 768 |
vpc-id: |
| 769 |
- "{{ vpc_id }}" |
| 770 |
register: remaining_endpoints |
| 771 |
|
| 772 |
- name: Delete all endpoints |
| 773 |
amazon.aws.ec2_vpc_endpoint: |
| 774 |
state: absent |
| 775 |
vpc_endpoint_id: "{{ item.vpc_endpoint_id }}" |
| 776 |
wait: true |
| 777 |
loop: "{{ remaining_endpoints.vpc_endpoints }}" |
| 778 |
ignore_errors: true |
| 779 |
register: endpoints_removed |
| 780 |
until: |
| 781 |
- endpoints_removed is not failed |
| 782 |
- endpoints_removed is not changed |
| 783 |
retries: 20 |
| 784 |
delay: 10 |
| 785 |
|
| 786 |
- ansible.builtin.include_role: |
| 787 |
name: setup_ec2_vpc |
| 788 |
tasks_from: cleanup.yml |
| 789 |
vars: |
| 790 |
setup_ec2_vpc_id: "{{ vpc_creation.vpc.id }}" |