From a04f8d25af7c4c80fa003038618342897a361878 Mon Sep 17 00:00:00 2001 From: Jill Rouleau Date: Tue, 27 Jul 2021 14:00:13 -0700 Subject: [PATCH] Remove collection reference inside the tests --- .../targets/ec2_vpc_igw/defaults/main.yml | 3 +- .../targets/ec2_vpc_igw/tasks/main.yml | 531 ++++++++---------- 2 files changed, 249 insertions(+), 285 deletions(-) diff --git a/tests/integration/targets/ec2_vpc_igw/defaults/main.yml b/tests/integration/targets/ec2_vpc_igw/defaults/main.yml index eeda091c81c..a4590b4c0cd 100644 --- a/tests/integration/targets/ec2_vpc_igw/defaults/main.yml +++ b/tests/integration/targets/ec2_vpc_igw/defaults/main.yml @@ -1,4 +1,3 @@ ---- vpc_name: '{{ resource_prefix }}-vpc' vpc_seed: '{{ resource_prefix }}' -vpc_cidr: '10.{{ 256 | random(seed=vpc_seed) }}.0.0/16' +vpc_cidr: 10.{{ 256 | random(seed=vpc_seed) }}.0.0/16 diff --git a/tests/integration/targets/ec2_vpc_igw/tasks/main.yml b/tests/integration/targets/ec2_vpc_igw/tasks/main.yml index 6697493127d..ae49daefd52 100644 --- a/tests/integration/targets/ec2_vpc_igw/tasks/main.yml +++ b/tests/integration/targets/ec2_vpc_igw/tasks/main.yml @@ -1,571 +1,536 @@ ---- - name: ec2_vpc_igw tests - collections: - - amazon.aws - module_defaults: group/aws: - aws_access_key: "{{ aws_access_key }}" - aws_secret_key: "{{ aws_secret_key }}" - security_token: "{{ security_token | default(omit) }}" - region: "{{ aws_region }}" + aws_access_key: '{{ aws_access_key }}' + aws_secret_key: '{{ aws_secret_key }}' + security_token: '{{ security_token | default(omit) }}' + region: '{{ aws_region }}' block: # ============================================================ - name: Fetch IGWs in check_mode ec2_vpc_igw_info: register: igw_info - check_mode: True - + check_mode: true - name: Assert success assert: that: - - igw_info is successful - - '"internet_gateways" in igw_info' + - igw_info is successful + - '"internet_gateways" in igw_info' # ============================================================ - name: create a VPC ec2_vpc_net: - name: "{{ vpc_name }}" + name: '{{ vpc_name }}' state: present - cidr_block: "{{ vpc_cidr }}" + cidr_block: '{{ vpc_cidr }}' tags: - Name: "{{ resource_prefix }}-vpc" - Description: "Created by ansible-test" + Name: '{{ resource_prefix }}-vpc' + Description: Created by ansible-test register: vpc_result - - name: Assert success assert: that: - - vpc_result is successful - - '"vpc" in vpc_result' - - '"id" in vpc_result.vpc' - - vpc_result.vpc.state == 'available' - - '"tags" in vpc_result.vpc' - - vpc_result.vpc.tags | length == 2 - - vpc_result.vpc.tags["Name"] == "{{ resource_prefix }}-vpc" - - vpc_result.vpc.tags["Description"] == "Created by ansible-test" + - vpc_result is successful + - '"vpc" in vpc_result' + - '"id" in vpc_result.vpc' + - vpc_result.vpc.state == 'available' + - '"tags" in vpc_result.vpc' + - vpc_result.vpc.tags | length == 2 + - vpc_result.vpc.tags["Name"] == "{{ resource_prefix }}-vpc" + - vpc_result.vpc.tags["Description"] == "Created by ansible-test" # ============================================================ - name: Search for internet gateway by VPC - no matches ec2_vpc_igw_info: filters: attachment.vpc-id: '{{ vpc_result.vpc.id }}' - register: igw_info - + register: igw_info - name: Assert success assert: that: - - igw_info is successful - - '"internet_gateways" in igw_info' - - (igw_info.internet_gateways | length) == 0 + - igw_info is successful + - '"internet_gateways" in igw_info' + - (igw_info.internet_gateways | length) == 0 # ============================================================ - name: create internet gateway (expected changed=true) - CHECK_MODE ec2_vpc_igw: state: present - vpc_id: "{{ vpc_result.vpc.id }}" + vpc_id: '{{ vpc_result.vpc.id }}' tags: tag_one: '{{ resource_prefix }} One' - "Tag Two": 'two {{ resource_prefix }}' + Tag Two: two {{ resource_prefix }} register: vpc_igw_create check_mode: yes - - name: assert creation would happen (expected changed=true) - CHECK_MODE assert: that: - - vpc_igw_create is changed + - vpc_igw_create is changed - name: create internet gateway (expected changed=true) ec2_vpc_igw: state: present - vpc_id: "{{ vpc_result.vpc.id }}" + vpc_id: '{{ vpc_result.vpc.id }}' tags: tag_one: '{{ resource_prefix }} One' - "Tag Two": 'two {{ resource_prefix }}' + Tag Two: two {{ resource_prefix }} register: vpc_igw_create - - name: assert creation happened (expected changed=true) assert: that: - - vpc_igw_create is changed - - 'vpc_igw_create.gateway_id.startswith("igw-")' - - 'vpc_igw_create.vpc_id == vpc_result.vpc.id' - - '"tags" in vpc_igw_create' - - vpc_igw_create.tags | length == 2 - - vpc_igw_create.tags["tag_one"] == '{{ resource_prefix }} One' - - vpc_igw_create.tags["Tag Two"] == 'two {{ resource_prefix }}' - - '"gateway_id" in vpc_igw_create' + - vpc_igw_create is changed + - vpc_igw_create.gateway_id.startswith("igw-") + - vpc_igw_create.vpc_id == vpc_result.vpc.id + - '"tags" in vpc_igw_create' + - vpc_igw_create.tags | length == 2 + - vpc_igw_create.tags["tag_one"] == '{{ resource_prefix }} One' + - vpc_igw_create.tags["Tag Two"] == 'two {{ resource_prefix }}' + - '"gateway_id" in vpc_igw_create' # ============================================================ - name: Save IDs for later set_fact: igw_id: '{{ vpc_igw_create.gateway_id }}' vpc_id: '{{ vpc_result.vpc.id }}' - - # ============================================================ - name: Search for internet gateway by VPC ec2_vpc_igw_info: filters: attachment.vpc-id: '{{ vpc_id }}' - register: igw_info - - - name: 'Check standard IGW details' + register: igw_info + - name: Check standard IGW details assert: that: - - '"internet_gateways" in igw_info' - - igw_info.internet_gateways | length == 1 - - '"attachments" in current_igw' - - current_igw.attachments | length == 1 - - '"state" in current_igw.attachments[0]' - - current_igw.attachments[0].state == "available" - - '"vpc_id" in current_igw.attachments[0]' - - current_igw.attachments[0].vpc_id == vpc_id - - '"internet_gateway_id" in current_igw' - - current_igw.internet_gateway_id == igw_id - - '"tags" in current_igw' - - current_igw.tags | length == 2 - - '"key" in current_igw.tags[0]' - - '"value" in current_igw.tags[0]' - - '"key" in current_igw.tags[1]' - - '"value" in current_igw.tags[1]' + - '"internet_gateways" in igw_info' + - igw_info.internet_gateways | length == 1 + - '"attachments" in current_igw' + - current_igw.attachments | length == 1 + - '"state" in current_igw.attachments[0]' + - current_igw.attachments[0].state == "available" + - '"vpc_id" in current_igw.attachments[0]' + - current_igw.attachments[0].vpc_id == vpc_id + - '"internet_gateway_id" in current_igw' + - current_igw.internet_gateway_id == igw_id + - '"tags" in current_igw' + - current_igw.tags | length == 2 + - '"key" in current_igw.tags[0]' + - '"value" in current_igw.tags[0]' + - '"key" in current_igw.tags[1]' + - '"value" in current_igw.tags[1]' # Order isn't guaranteed in boto3 style, so just check the keys and # values we expect are in there. - - current_igw.tags[0].key in ["tag_one", "Tag Two"] - - current_igw.tags[1].key in ["tag_one", "Tag Two"] - - current_igw.tags[0].value in [resource_prefix + " One", "two " + resource_prefix] - - current_igw.tags[1].value in [resource_prefix + " One", "two " + resource_prefix] + - current_igw.tags[0].key in ["tag_one", "Tag Two"] + - current_igw.tags[1].key in ["tag_one", "Tag Two"] + - current_igw.tags[0].value in [resource_prefix + " One", "two " + resource_prefix] + - current_igw.tags[1].value in [resource_prefix + " One", "two " + resource_prefix] vars: current_igw: '{{ igw_info.internet_gateways[0] }}' - - # ============================================================ - name: Fetch IGW by ID ec2_vpc_igw_info: internet_gateway_ids: '{{ igw_id }}' convert_tags: yes - register: igw_info - - - name: 'Check standard IGW details' + register: igw_info + - name: Check standard IGW details assert: that: - - '"internet_gateways" in igw_info' - - igw_info.internet_gateways | length == 1 - - '"attachments" in current_igw' - - current_igw.attachments | length == 1 - - '"state" in current_igw.attachments[0]' - - current_igw.attachments[0].state == "available" - - '"vpc_id" in current_igw.attachments[0]' - - current_igw.attachments[0].vpc_id == vpc_id - - '"internet_gateway_id" in current_igw' - - current_igw.internet_gateway_id == igw_id - - '"tags" in current_igw' - - current_igw.tags | length == 2 - - '"tag_one" in current_igw.tags' - - '"Tag Two" in current_igw.tags' - - current_igw.tags["tag_one"] == '{{ resource_prefix }} One' - - current_igw.tags["Tag Two"] == 'two {{ resource_prefix }}' + - '"internet_gateways" in igw_info' + - igw_info.internet_gateways | length == 1 + - '"attachments" in current_igw' + - current_igw.attachments | length == 1 + - '"state" in current_igw.attachments[0]' + - current_igw.attachments[0].state == "available" + - '"vpc_id" in current_igw.attachments[0]' + - current_igw.attachments[0].vpc_id == vpc_id + - '"internet_gateway_id" in current_igw' + - current_igw.internet_gateway_id == igw_id + - '"tags" in current_igw' + - current_igw.tags | length == 2 + - '"tag_one" in current_igw.tags' + - '"Tag Two" in current_igw.tags' + - current_igw.tags["tag_one"] == '{{ resource_prefix }} One' + - current_igw.tags["Tag Two"] == 'two {{ resource_prefix }}' vars: current_igw: '{{ igw_info.internet_gateways[0] }}' - - # ============================================================ - name: Fetch IGW by ID (list) ec2_vpc_igw_info: internet_gateway_ids: - '{{ igw_id }}' - register: igw_info - - - name: 'Check standard IGW details' + register: igw_info + - name: Check standard IGW details assert: that: - - '"internet_gateways" in igw_info' - - igw_info.internet_gateways | length == 1 - - '"attachments" in current_igw' - - current_igw.attachments | length == 1 - - '"state" in current_igw.attachments[0]' - - current_igw.attachments[0].state == "available" - - '"vpc_id" in current_igw.attachments[0]' - - current_igw.attachments[0].vpc_id == vpc_id - - '"internet_gateway_id" in current_igw' - - current_igw.internet_gateway_id == igw_id - - '"tags" in current_igw' + - '"internet_gateways" in igw_info' + - igw_info.internet_gateways | length == 1 + - '"attachments" in current_igw' + - current_igw.attachments | length == 1 + - '"state" in current_igw.attachments[0]' + - current_igw.attachments[0].state == "available" + - '"vpc_id" in current_igw.attachments[0]' + - current_igw.attachments[0].vpc_id == vpc_id + - '"internet_gateway_id" in current_igw' + - current_igw.internet_gateway_id == igw_id + - '"tags" in current_igw' vars: current_igw: '{{ igw_info.internet_gateways[0] }}' - - # ============================================================ - name: attempt to recreate internet gateway on VPC (expected changed=false) - CHECK_MODE ec2_vpc_igw: state: present - vpc_id: "{{ vpc_result.vpc.id }}" + vpc_id: '{{ vpc_result.vpc.id }}' register: vpc_igw_recreate check_mode: yes - - name: assert recreation would do nothing (expected changed=false) - CHECK_MODE assert: that: - - vpc_igw_recreate is not changed - - vpc_igw_recreate.gateway_id == igw_id - - vpc_igw_recreate.vpc_id == vpc_id - - '"tags" in vpc_igw_create' - - vpc_igw_create.tags | length == 2 - - vpc_igw_create.tags["tag_one"] == '{{ resource_prefix }} One' - - vpc_igw_create.tags["Tag Two"] == 'two {{ resource_prefix }}' + - vpc_igw_recreate is not changed + - vpc_igw_recreate.gateway_id == igw_id + - vpc_igw_recreate.vpc_id == vpc_id + - '"tags" in vpc_igw_create' + - vpc_igw_create.tags | length == 2 + - vpc_igw_create.tags["tag_one"] == '{{ resource_prefix }} One' + - vpc_igw_create.tags["Tag Two"] == 'two {{ resource_prefix }}' - name: attempt to recreate internet gateway on VPC (expected changed=false) ec2_vpc_igw: state: present - vpc_id: "{{ vpc_result.vpc.id }}" + vpc_id: '{{ vpc_result.vpc.id }}' register: vpc_igw_recreate - - name: assert recreation did nothing (expected changed=false) assert: that: - - vpc_igw_recreate is not changed - - vpc_igw_recreate.gateway_id == igw_id - - vpc_igw_recreate.vpc_id == vpc_id - - '"tags" in vpc_igw_create' - - vpc_igw_create.tags | length == 2 - - vpc_igw_create.tags["tag_one"] == '{{ resource_prefix }} One' - - vpc_igw_create.tags["Tag Two"] == 'two {{ resource_prefix }}' + - vpc_igw_recreate is not changed + - vpc_igw_recreate.gateway_id == igw_id + - vpc_igw_recreate.vpc_id == vpc_id + - '"tags" in vpc_igw_create' + - vpc_igw_create.tags | length == 2 + - vpc_igw_create.tags["tag_one"] == '{{ resource_prefix }} One' + - vpc_igw_create.tags["Tag Two"] == 'two {{ resource_prefix }}' # ============================================================ - name: Update the tags (no change) - CHECK_MODE ec2_vpc_igw: state: present - vpc_id: "{{ vpc_result.vpc.id }}" + vpc_id: '{{ vpc_result.vpc.id }}' tags: tag_one: '{{ resource_prefix }} One' - "Tag Two": 'two {{ resource_prefix }}' + Tag Two: two {{ resource_prefix }} register: vpc_igw_recreate check_mode: yes - - name: assert tag update would do nothing (expected changed=false) - CHECK_MODE assert: that: - - vpc_igw_recreate is not changed - - vpc_igw_recreate.gateway_id == igw_id - - vpc_igw_recreate.vpc_id == vpc_id - - '"tags" in vpc_igw_recreate' - - vpc_igw_recreate.tags | length == 2 - - vpc_igw_recreate.tags["tag_one"] == '{{ resource_prefix }} One' - - vpc_igw_recreate.tags["Tag Two"] == 'two {{ resource_prefix }}' + - vpc_igw_recreate is not changed + - vpc_igw_recreate.gateway_id == igw_id + - vpc_igw_recreate.vpc_id == vpc_id + - '"tags" in vpc_igw_recreate' + - vpc_igw_recreate.tags | length == 2 + - vpc_igw_recreate.tags["tag_one"] == '{{ resource_prefix }} One' + - vpc_igw_recreate.tags["Tag Two"] == 'two {{ resource_prefix }}' - name: Update the tags (no change) ec2_vpc_igw: state: present - vpc_id: "{{ vpc_result.vpc.id }}" + vpc_id: '{{ vpc_result.vpc.id }}' tags: tag_one: '{{ resource_prefix }} One' - "Tag Two": 'two {{ resource_prefix }}' + Tag Two: two {{ resource_prefix }} register: vpc_igw_recreate - - name: assert tag update did nothing (expected changed=false) assert: that: - - vpc_igw_recreate is not changed - - vpc_igw_recreate.gateway_id == igw_id - - vpc_igw_recreate.vpc_id == vpc_id - - '"tags" in vpc_igw_recreate' - - vpc_igw_recreate.tags | length == 2 - - vpc_igw_recreate.tags["tag_one"] == '{{ resource_prefix }} One' - - vpc_igw_recreate.tags["Tag Two"] == 'two {{ resource_prefix }}' + - vpc_igw_recreate is not changed + - vpc_igw_recreate.gateway_id == igw_id + - vpc_igw_recreate.vpc_id == vpc_id + - '"tags" in vpc_igw_recreate' + - vpc_igw_recreate.tags | length == 2 + - vpc_igw_recreate.tags["tag_one"] == '{{ resource_prefix }} One' + - vpc_igw_recreate.tags["Tag Two"] == 'two {{ resource_prefix }}' # ============================================================ - name: Update the tags - remove and add - CHECK_MODE ec2_vpc_igw: state: present - vpc_id: "{{ vpc_result.vpc.id }}" + vpc_id: '{{ vpc_result.vpc.id }}' tags: tag_three: '{{ resource_prefix }} Three' - "Tag Two": 'two {{ resource_prefix }}' + Tag Two: two {{ resource_prefix }} register: vpc_igw_update check_mode: yes - - name: assert tag update would happen (expected changed=true) - CHECK_MODE assert: that: - - vpc_igw_update is changed - - vpc_igw_update.gateway_id == igw_id - - vpc_igw_update.vpc_id == vpc_id - - '"tags" in vpc_igw_update' - - vpc_igw_update.tags | length == 2 - - vpc_igw_update.tags["tag_three"] == '{{ resource_prefix }} Three' - - vpc_igw_update.tags["Tag Two"] == 'two {{ resource_prefix }}' + - vpc_igw_update is changed + - vpc_igw_update.gateway_id == igw_id + - vpc_igw_update.vpc_id == vpc_id + - '"tags" in vpc_igw_update' + - vpc_igw_update.tags | length == 2 + - vpc_igw_update.tags["tag_three"] == '{{ resource_prefix }} Three' + - vpc_igw_update.tags["Tag Two"] == 'two {{ resource_prefix }}' - name: Update the tags - remove and add ec2_vpc_igw: state: present - vpc_id: "{{ vpc_result.vpc.id }}" + vpc_id: '{{ vpc_result.vpc.id }}' tags: tag_three: '{{ resource_prefix }} Three' - "Tag Two": 'two {{ resource_prefix }}' + Tag Two: two {{ resource_prefix }} register: vpc_igw_update - - name: assert tags are updated (expected changed=true) assert: that: - - vpc_igw_update is changed - - vpc_igw_update.gateway_id == igw_id - - vpc_igw_update.vpc_id == vpc_id - - '"tags" in vpc_igw_update' - - vpc_igw_update.tags | length == 2 - - vpc_igw_update.tags["tag_three"] == '{{ resource_prefix }} Three' - - vpc_igw_update.tags["Tag Two"] == 'two {{ resource_prefix }}' + - vpc_igw_update is changed + - vpc_igw_update.gateway_id == igw_id + - vpc_igw_update.vpc_id == vpc_id + - '"tags" in vpc_igw_update' + - vpc_igw_update.tags | length == 2 + - vpc_igw_update.tags["tag_three"] == '{{ resource_prefix }} Three' + - vpc_igw_update.tags["Tag Two"] == 'two {{ resource_prefix }}' # ============================================================ - name: Update the tags add without purge - CHECK_MODE ec2_vpc_igw: state: present - vpc_id: "{{ vpc_result.vpc.id }}" + vpc_id: '{{ vpc_result.vpc.id }}' purge_tags: no tags: tag_one: '{{ resource_prefix }} One' register: vpc_igw_update check_mode: yes - - name: assert tags would be added - CHECK_MODE assert: that: - - vpc_igw_update is changed - - vpc_igw_update.gateway_id == igw_id - - vpc_igw_update.vpc_id == vpc_id - - '"tags" in vpc_igw_update' - - vpc_igw_update.tags | length == 3 - - vpc_igw_update.tags["tag_one"] == '{{ resource_prefix }} One' - - vpc_igw_update.tags["tag_three"] == '{{ resource_prefix }} Three' - - vpc_igw_update.tags["Tag Two"] == 'two {{ resource_prefix }}' + - vpc_igw_update is changed + - vpc_igw_update.gateway_id == igw_id + - vpc_igw_update.vpc_id == vpc_id + - '"tags" in vpc_igw_update' + - vpc_igw_update.tags | length == 3 + - vpc_igw_update.tags["tag_one"] == '{{ resource_prefix }} One' + - vpc_igw_update.tags["tag_three"] == '{{ resource_prefix }} Three' + - vpc_igw_update.tags["Tag Two"] == 'two {{ resource_prefix }}' - name: Update the tags add without purge ec2_vpc_igw: state: present - vpc_id: "{{ vpc_result.vpc.id }}" + vpc_id: '{{ vpc_result.vpc.id }}' purge_tags: no tags: tag_one: '{{ resource_prefix }} One' register: vpc_igw_update - - name: assert tags added assert: that: - - vpc_igw_update is changed - - vpc_igw_update.gateway_id == igw_id - - vpc_igw_update.vpc_id == vpc_id - - '"tags" in vpc_igw_update' - - vpc_igw_update.tags | length == 3 - - vpc_igw_update.tags["tag_one"] == '{{ resource_prefix }} One' - - vpc_igw_update.tags["tag_three"] == '{{ resource_prefix }} Three' - - vpc_igw_update.tags["Tag Two"] == 'two {{ resource_prefix }}' + - vpc_igw_update is changed + - vpc_igw_update.gateway_id == igw_id + - vpc_igw_update.vpc_id == vpc_id + - '"tags" in vpc_igw_update' + - vpc_igw_update.tags | length == 3 + - vpc_igw_update.tags["tag_one"] == '{{ resource_prefix }} One' + - vpc_igw_update.tags["tag_three"] == '{{ resource_prefix }} Three' + - vpc_igw_update.tags["Tag Two"] == 'two {{ resource_prefix }}' # ============================================================ - name: Update with CamelCase tags - CHECK_MODE ec2_vpc_igw: state: present - vpc_id: "{{ vpc_result.vpc.id }}" + vpc_id: '{{ vpc_result.vpc.id }}' tags: - "lowercase spaced": 'hello cruel world ❤️' - "Title Case": 'Hello Cruel World ❤️' - CamelCase: 'SimpleCamelCase ❤️' - snake_case: 'simple_snake_case ❤️' + lowercase spaced: "hello cruel world \u2764\uFE0F" + Title Case: "Hello Cruel World \u2764\uFE0F" + CamelCase: "SimpleCamelCase \u2764\uFE0F" + snake_case: "simple_snake_case \u2764\uFE0F" register: vpc_igw_update check_mode: yes - - name: assert tag update would happen (expected changed=true) - CHECK_MODE assert: that: - - vpc_igw_update is changed - - vpc_igw_update.gateway_id == igw_id - - vpc_igw_update.vpc_id == vpc_id - - '"tags" in vpc_igw_update' - - vpc_igw_update.tags | length == 4 - - vpc_igw_update.tags["lowercase spaced"] == 'hello cruel world ❤️' - - vpc_igw_update.tags["Title Case"] == 'Hello Cruel World ❤️' - - vpc_igw_update.tags["CamelCase"] == 'SimpleCamelCase ❤️' - - vpc_igw_update.tags["snake_case"] == 'simple_snake_case ❤️' - + - vpc_igw_update is changed + - vpc_igw_update.gateway_id == igw_id + - vpc_igw_update.vpc_id == vpc_id + - '"tags" in vpc_igw_update' + - vpc_igw_update.tags | length == 4 + - "vpc_igw_update.tags[\"lowercase spaced\"] == 'hello cruel world \u2764\uFE0F\ + '" + - "vpc_igw_update.tags[\"Title Case\"] == 'Hello Cruel World \u2764\uFE0F'" + - "vpc_igw_update.tags[\"CamelCase\"] == 'SimpleCamelCase \u2764\uFE0F'" + - "vpc_igw_update.tags[\"snake_case\"] == 'simple_snake_case \u2764\uFE0F'" + - name: Update the tags - remove and add ec2_vpc_igw: state: present - vpc_id: "{{ vpc_result.vpc.id }}" + vpc_id: '{{ vpc_result.vpc.id }}' tags: - "lowercase spaced": 'hello cruel world ❤️' - "Title Case": 'Hello Cruel World ❤️' - CamelCase: 'SimpleCamelCase ❤️' - snake_case: 'simple_snake_case ❤️' + lowercase spaced: "hello cruel world \u2764\uFE0F" + Title Case: "Hello Cruel World \u2764\uFE0F" + CamelCase: "SimpleCamelCase \u2764\uFE0F" + snake_case: "simple_snake_case \u2764\uFE0F" register: vpc_igw_update - - name: assert tags are updated (expected changed=true) assert: that: - - vpc_igw_update is changed - - vpc_igw_update.gateway_id == igw_id - - vpc_igw_update.vpc_id == vpc_id - - '"tags" in vpc_igw_update' - - vpc_igw_update.tags | length == 4 - - vpc_igw_update.tags["lowercase spaced"] == 'hello cruel world ❤️' - - vpc_igw_update.tags["Title Case"] == 'Hello Cruel World ❤️' - - vpc_igw_update.tags["CamelCase"] == 'SimpleCamelCase ❤️' - - vpc_igw_update.tags["snake_case"] == 'simple_snake_case ❤️' - + - vpc_igw_update is changed + - vpc_igw_update.gateway_id == igw_id + - vpc_igw_update.vpc_id == vpc_id + - '"tags" in vpc_igw_update' + - vpc_igw_update.tags | length == 4 + - "vpc_igw_update.tags[\"lowercase spaced\"] == 'hello cruel world \u2764\uFE0F\ + '" + - "vpc_igw_update.tags[\"Title Case\"] == 'Hello Cruel World \u2764\uFE0F'" + - "vpc_igw_update.tags[\"CamelCase\"] == 'SimpleCamelCase \u2764\uFE0F'" + - "vpc_igw_update.tags[\"snake_case\"] == 'simple_snake_case \u2764\uFE0F'" + # ============================================================ - name: Gather information about a filtered list of Internet Gateways using tags ec2_vpc_igw_info: filters: - "tag:Title Case": 'Hello Cruel World ❤️' + tag:Title Case: "Hello Cruel World \u2764\uFE0F" register: igw_info - - name: Assert success assert: that: - - igw_info is successful - - '"internet_gateways" in igw_info' - - igw_info.internet_gateways | selectattr("internet_gateway_id",'equalto',"{{ igw_id }}") - - - name: Gather information about a filtered list of Internet Gateways using tags - CHECK_MODE + - igw_info is successful + - '"internet_gateways" in igw_info' + - igw_info.internet_gateways | selectattr("internet_gateway_id",'equalto',"{{ + igw_id }}") + + - name: Gather information about a filtered list of Internet Gateways using tags + - CHECK_MODE ec2_vpc_igw_info: filters: - "tag:Title Case": 'Hello Cruel World ❤️' + tag:Title Case: "Hello Cruel World \u2764\uFE0F" register: igw_info check_mode: yes - - name: Assert success - CHECK_MODE assert: that: - - igw_info is successful - - '"internet_gateways" in igw_info' - - igw_info.internet_gateways | selectattr("internet_gateway_id",'equalto',"{{ igw_id }}") + - igw_info is successful + - '"internet_gateways" in igw_info' + - igw_info.internet_gateways | selectattr("internet_gateway_id",'equalto',"{{ + igw_id }}") # ============================================================ - - name: Gather information about a filtered list of Internet Gateways using tags (no match) + - name: Gather information about a filtered list of Internet Gateways using tags + (no match) ec2_vpc_igw_info: filters: - "tag:tag_one": '{{ resource_prefix }} One' + tag:tag_one: '{{ resource_prefix }} One' register: igw_info - - name: Assert success assert: that: - - igw_info is successful - - '"internet_gateways" in igw_info' - - igw_info.internet_gateways | length == 0 + - igw_info is successful + - '"internet_gateways" in igw_info' + - igw_info.internet_gateways | length == 0 - - name: Gather information about a filtered list of Internet Gateways using tags (no match) - CHECK_MODE + - name: Gather information about a filtered list of Internet Gateways using tags + (no match) - CHECK_MODE ec2_vpc_igw_info: filters: - "tag:tag_one": '{{ resource_prefix }} One' + tag:tag_one: '{{ resource_prefix }} One' register: igw_info check_mode: yes - - name: Assert success - CHECK_MODE assert: that: - - igw_info is successful - - '"internet_gateways" in igw_info' - - igw_info.internet_gateways | length == 0 + - igw_info is successful + - '"internet_gateways" in igw_info' + - igw_info.internet_gateways | length == 0 # ============================================================ - name: Remove all tags - CHECK_MODE ec2_vpc_igw: state: present - vpc_id: "{{ vpc_result.vpc.id }}" + vpc_id: '{{ vpc_result.vpc.id }}' tags: {} register: vpc_igw_update check_mode: yes - - name: assert tags would be removed - CHECK_MODE assert: that: - - vpc_igw_update is changed + - vpc_igw_update is changed - name: Remove all tags ec2_vpc_igw: state: present - vpc_id: "{{ vpc_result.vpc.id }}" + vpc_id: '{{ vpc_result.vpc.id }}' tags: {} register: vpc_igw_update - - name: assert tags removed assert: that: - - vpc_igw_update is changed - - vpc_igw_update.gateway_id == igw_id - - vpc_igw_update.vpc_id == vpc_id - - '"tags" in vpc_igw_update' - - vpc_igw_update.tags | length == 0 - + - vpc_igw_update is changed + - vpc_igw_update.gateway_id == igw_id + - vpc_igw_update.vpc_id == vpc_id + - '"tags" in vpc_igw_update' + - vpc_igw_update.tags | length == 0 + # ============================================================ - name: test state=absent (expected changed=true) - CHECK_MODE ec2_vpc_igw: state: absent - vpc_id: "{{ vpc_result.vpc.id }}" + vpc_id: '{{ vpc_result.vpc.id }}' register: vpc_igw_delete check_mode: yes - - name: assert state=absent (expected changed=true) - CHECK_MODE assert: that: - - vpc_igw_delete is changed + - vpc_igw_delete is changed - name: test state=absent (expected changed=true) ec2_vpc_igw: state: absent - vpc_id: "{{ vpc_result.vpc.id }}" + vpc_id: '{{ vpc_result.vpc.id }}' register: vpc_igw_delete - - name: assert state=absent (expected changed=true) assert: that: - - vpc_igw_delete is changed + - vpc_igw_delete is changed # ============================================================ - name: Fetch IGW by ID (list) ec2_vpc_igw_info: internet_gateway_ids: - '{{ igw_id }}' - register: igw_info - ignore_errors: True - - - name: 'Check IGW does not exist' + register: igw_info + ignore_errors: true + - name: Check IGW does not exist assert: that: # Deliberate choice not to change bevahiour when searching by ID - - igw_info is failed + - igw_info is failed # ============================================================ - name: test state=absent when already deleted (expected changed=false) - CHECK_MODE ec2_vpc_igw: state: absent - vpc_id: "{{ vpc_result.vpc.id }}" + vpc_id: '{{ vpc_result.vpc.id }}' register: vpc_igw_delete check_mode: yes - - name: assert state=absent (expected changed=false) - CHECK_MODE assert: that: - - vpc_igw_delete is not changed + - vpc_igw_delete is not changed - name: test state=absent when already deleted (expected changed=false) ec2_vpc_igw: state: absent - vpc_id: "{{ vpc_result.vpc.id }}" + vpc_id: '{{ vpc_result.vpc.id }}' register: vpc_igw_delete - - name: assert state=absent (expected changed=false) assert: that: - - vpc_igw_delete is not changed + - vpc_igw_delete is not changed always: # ============================================================ - - name: tidy up IGW - ec2_vpc_igw: - state: absent - vpc_id: "{{ vpc_result.vpc.id }}" - ignore_errors: true - - - name: tidy up VPC - ec2_vpc_net: - name: "{{ vpc_name }}" - state: absent - cidr_block: "{{ vpc_cidr }}" - ignore_errors: true + - name: tidy up IGW + ec2_vpc_igw: + state: absent + vpc_id: '{{ vpc_result.vpc.id }}' + ignore_errors: true + - name: tidy up VPC + ec2_vpc_net: + name: '{{ vpc_name }}' + state: absent + cidr_block: '{{ vpc_cidr }}' + ignore_errors: true