From 1bcaaf837a506041206ad1900be7d33b91bad9f4 Mon Sep 17 00:00:00 2001 From: Alina Buzachis <49211501+alinabuzachis@users.noreply.github.com> Date: Wed, 24 Feb 2021 17:51:05 +0100 Subject: [PATCH] ec2_vpc_nat_gateway: increase integration tests coverage (#387) * NAT gateway: increase integration tests coverage * Add additional integration tests for ec2_vpc_nat_gateway_info and ec2_vpc_nat_gatewy modules * Add ec2_vpc_nat_gateway_info in aliases * Fix NAT gateway search Signed-off-by: Alina Buzachis This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/fbfc351e38ec858d6e8c079670b1c9ce00af33fc --- .../targets/ec2_vpc_nat_gateway/aliases | 1 + .../ec2_vpc_nat_gateway/tasks/main.yml | 539 +++++++++++++++++- 2 files changed, 520 insertions(+), 20 deletions(-) diff --git a/tests/integration/targets/ec2_vpc_nat_gateway/aliases b/tests/integration/targets/ec2_vpc_nat_gateway/aliases index 6e3860bee23..e2557d59343 100644 --- a/tests/integration/targets/ec2_vpc_nat_gateway/aliases +++ b/tests/integration/targets/ec2_vpc_nat_gateway/aliases @@ -1,2 +1,3 @@ cloud/aws shippable/aws/group2 +ec2_vpc_nat_gateway_info diff --git a/tests/integration/targets/ec2_vpc_nat_gateway/tasks/main.yml b/tests/integration/targets/ec2_vpc_nat_gateway/tasks/main.yml index 36f035c81d1..f43a3ece55c 100644 --- a/tests/integration/targets/ec2_vpc_nat_gateway/tasks/main.yml +++ b/tests/integration/targets/ec2_vpc_nat_gateway/tasks/main.yml @@ -52,6 +52,7 @@ assert: that: - eip_result is successful + - 'eip_result.allocation_id.startswith("eipalloc-")' - name: "set fact: EIP allocation ID and EIP public IP" set_fact: @@ -71,6 +72,10 @@ assert: that: - subnet_result is successful + - subnet_result.subnet.id.startswith("subnet-") + - subnet_result.subnet.cidr_block == subnet_cidr + - subnet_result.subnet.state == 'available' + - subnet_result.subnet.vpc_id == vpc_id - name: "set fact: VPC subnet ID" set_fact: @@ -93,6 +98,19 @@ - existing_ngws is successful - (existing_ngws.result|length) == 0 + # - name: Search for NAT gateways by subnet (no matches) - CHECK_MODE + # ec2_vpc_nat_gateway_info: + # filters: + # subnet-id: "{{ subnet_id }}" + # state: ['available'] + # register: existing_ngws + # check_mode: yes + + # - name: Assert no NAT gateway found - CHECK_MODE + # assert: + # that: + # - existing_ngws is successful + # - (existing_ngws.result|length) == 0 # ============================================================ @@ -105,6 +123,9 @@ assert: that: - create_igw is successful + - create_igw.gateway_id.startswith("igw-") + - create_igw.vpc_id == vpc_id + - '"gateway_id" in create_igw' # ============================================================ @@ -121,24 +142,105 @@ assert: that: - create_ngw.changed + - '"create_time" in create_ngw' + - '"nat_gateway_addresses" in create_ngw' + - '"nat_gateway_id" in create_ngw' + - create_ngw.nat_gateway_addresses[0].allocation_id == allocation_id + - create_ngw.nat_gateway_id.startswith("nat-") + - '"state" in create_ngw' + - create_ngw.state == 'available' + - '"subnet_id" in create_ngw' + - create_ngw.subnet_id == subnet_id + - '"tags" in create_ngw' + - '"vpc_id" in create_ngw' + - create_ngw.vpc_id == vpc_id - name: "set facts: NAT gateway ID" set_fact: nat_gateway_id: "{{ create_ngw.nat_gateway_id }}" network_interface_id: "{{ create_ngw.nat_gateway_addresses[0].network_interface_id }}" - # - name: Create new NAT gateway with eip allocation-id - CHECK_MODE - # ec2_vpc_nat_gateway: - # subnet_id: "{{ subnet_id }}" - # allocation_id: "{{ allocation_id }}" - # wait: yes - # register: create_ngw - # check_mode: yes - # - # - name: Assert creation happened (expected changed=true) - CHECK_MODE - # assert: - # that: - # - create_ngw.changed + # - name: Create new NAT gateway with eip allocation-id - CHECK_MODE + # ec2_vpc_nat_gateway: + # subnet_id: "{{ subnet_id }}" + # allocation_id: "{{ allocation_id }}" + # wait: yes + # register: create_ngw + # check_mode: yes + # + # - name: Assert creation happened (expected changed=true) - CHECK_MODE + # assert: + # that: + # - create_ngw.changed + # - '"create_time" in create_ngw' + # - '"nat_gateway_addresses" in create_ngw' + # - '"nat_gateway_id" in create_ngw' + # - create_ngw.nat_gateway_addresses[0].allocation_id == allocation_id + # - create_ngw.nat_gateway_id.startswith("nat-") + # - '"state" in create_ngw' + # - create_ngw.state == 'available' + # - '"subnet_id" in create_ngw' + # - create_ngw.subnet_id == subnet_id + # - '"tags" in create_ngw' + # - '"vpc_id" in create_ngw' + # - create_ngw.vpc_id == vpc_id + + + # ============================================================ + - name: Get NAT gateway with specific filters (state and subnet) + ec2_vpc_nat_gateway_info: + filters: + subnet-id: "{{ subnet_id }}" + state: ['available'] + register: avalaible_ngws + retries: 10 + until: avalaible_ngws is not failed + + - name: Assert success + assert: + that: + - avalaible_ngws is successful + - avalaible_ngws.result | length == 1 + - '"create_time" in first_ngw' + - '"nat_gateway_addresses" in first_ngw' + - '"nat_gateway_id" in first_ngw' + - first_ngw.nat_gateway_id == nat_gateway_id + - '"state" in first_ngw' + - first_ngw.state == 'available' + - '"subnet_id" in first_ngw' + - first_ngw.subnet_id == subnet_id + - '"tags" in first_ngw' + - '"vpc_id" in first_ngw' + - first_ngw.vpc_id == vpc_id + vars: + first_ngw: '{{ avalaible_ngws.result[0] }}' + + #- name: Get all NAT gateways with specific filters (state and subnet) - CHECK_MODE + # ec2_vpc_nat_gateway_info: + # filters: + # state: ['available'] + # subnet-id: "{{ subnet_id }}" + # register: avalaible_ngws + + #- name: Assert success - CHECK_MODE + # assert: + # that: + # - avalaible_ngws is successful + # - avalaible_ngws.result | length == 1 + # - '"create_time" in first_ngw' + # - '"nat_gateway_addresses" in first_ngw' + # - '"nat_gateway_id" in first_ngw' + # - first_ngw.nat_gateway_id == nat_gateway_id + # - '"state" in first_ngw' + # - first_ngw.state == 'available' + # - '"subnet_id" in first_ngw' + # - first_ngw.subnet_id == subnet_id + # - '"tags" in first_ngw' + # - '"vpc_id" in first_ngw' + # - first_ngw.vpc_id == vpc_id + # vars: + # first_ngw: '{{ avalaible_ngws.result[0] }}' + # ============================================================ - name: Trying this again for idempotency - create new NAT gateway with eip allocation-id @@ -154,7 +256,19 @@ assert: that: - not create_ngw.changed - + - '"create_time" in create_ngw' + - '"nat_gateway_addresses" in create_ngw' + - '"nat_gateway_id" in create_ngw' + - create_ngw.nat_gateway_addresses[0].allocation_id == allocation_id + - create_ngw.nat_gateway_id.startswith("nat-") + - '"state" in create_ngw' + - create_ngw.state == 'available' + - '"subnet_id" in create_ngw' + - create_ngw.subnet_id == subnet_id + - '"tags" in create_ngw' + - '"vpc_id" in create_ngw' + - create_ngw.vpc_id == vpc_id + # - name: Trying this again for idempotency - create new NAT gateway with eip allocation-id - CHECK_MODE # ec2_vpc_nat_gateway: # subnet_id: "{{ subnet_id }}" @@ -166,7 +280,19 @@ # - name: Assert recreation would do nothing (expected changed=false) - CHECK_MODE # assert: # that: - # - not create_ngw.changed + # - not create_ngw.changed + # - '"create_time" in create_ngw' + # - '"nat_gateway_addresses" in create_ngw' + # - '"nat_gateway_id" in create_ngw' + # - create_ngw.nat_gateway_addresses[0].allocation_id == allocation_id + # - create_ngw.nat_gateway_id.startswith("nat-") + # - '"state" in create_ngw' + # - create_ngw.state == 'available' + # - '"subnet_id" in create_ngw' + # - create_ngw.subnet_id == subnet_id + # - '"tags" in create_ngw' + # - '"vpc_id" in create_ngw' + # - create_ngw.vpc_id == vpc_id # ============================================================ @@ -181,6 +307,18 @@ # assert: # that: # - create_ngw.changed + # - '"create_time" in create_ngw' + # - '"nat_gateway_addresses" in create_ngw' + # - '"nat_gateway_id" in create_ngw' + # - create_ngw.nat_gateway_addresses[0].allocation_id == allocation_id + # - create_ngw.nat_gateway_id.startswith("nat-") + # - '"state" in create_ngw' + # - create_ngw.state == 'available' + # - '"subnet_id" in create_ngw' + # - create_ngw.subnet_id == subnet_id + # - '"tags" in create_ngw' + # - '"vpc_id" in create_ngw' + # - create_ngw.vpc_id == vpc_id # - name: Create new nat gateway with eip address - CHECK_MODE # ec2_vpc_nat_gateway: @@ -194,6 +332,18 @@ # assert: # that: # - create_ngw.changed + # - '"create_time" in create_ngw' + # - '"nat_gateway_addresses" in create_ngw' + # - '"nat_gateway_id" in create_ngw' + # - create_ngw.nat_gateway_addresses[0].allocation_id == allocation_id + # - create_ngw.nat_gateway_id.startswith("nat-") + # - '"state" in create_ngw' + # - create_ngw.state == 'available' + # - '"subnet_id" in create_ngw' + # - create_ngw.subnet_id == subnet_id + # - '"tags" in create_ngw' + # - '"vpc_id" in create_ngw' + # - create_ngw.vpc_id == vpc_id # ============================================================ @@ -208,6 +358,18 @@ # assert: # that: # - not create_ngw.changed + # - '"create_time" in create_ngw' + # - '"nat_gateway_addresses" in create_ngw' + # - '"nat_gateway_id" in create_ngw' + # - create_ngw.nat_gateway_addresses[0].allocation_id == allocation_id + # - create_ngw.nat_gateway_id.startswith("nat-") + # - '"state" in create_ngw' + # - create_ngw.state == 'available' + # - '"subnet_id" in create_ngw' + # - create_ngw.subnet_id == subnet_id + # - '"tags" in create_ngw' + # - '"vpc_id" in create_ngw' + # - create_ngw.vpc_id == vpc_id # - name: Trying this again for idempotency - create new nat gateway with eip address - CHECK_MODE # ec2_vpc_nat_gateway: @@ -221,6 +383,18 @@ # assert: # that: # - not create_ngw.changed + # - '"create_time" in create_ngw' + # - '"nat_gateway_addresses" in create_ngw' + # - '"nat_gateway_id" in create_ngw' + # - create_ngw.nat_gateway_addresses[0].allocation_id == allocation_id + # - create_ngw.nat_gateway_id.startswith("nat-") + # - '"state" in create_ngw' + # - create_ngw.state == 'available' + # - '"subnet_id" in create_ngw' + # - create_ngw.subnet_id == subnet_id + # - '"tags" in create_ngw' + # - '"vpc_id" in create_ngw' + # - create_ngw.vpc_id == vpc_id # ============================================================ @@ -237,6 +411,18 @@ assert: that: - not create_ngw.changed + - '"create_time" in create_ngw' + - '"nat_gateway_addresses" in create_ngw' + - '"nat_gateway_id" in create_ngw' + - create_ngw.nat_gateway_addresses[0].allocation_id == allocation_id + - create_ngw.nat_gateway_id.startswith("nat-") + - '"state" in create_ngw' + - create_ngw.state == 'available' + - '"subnet_id" in create_ngw' + - create_ngw.subnet_id == subnet_id + - '"tags" in create_ngw' + - '"vpc_id" in create_ngw' + - create_ngw.vpc_id == vpc_id # - name: Create new nat gateway only if one does not exist already - CHECK_MODE # ec2_vpc_nat_gateway: @@ -250,7 +436,71 @@ # assert: # that: # - not create_ngw.changed + # - '"create_time" in create_ngw' + # - '"nat_gateway_addresses" in create_ngw' + # - '"nat_gateway_id" in create_ngw' + # - create_ngw.nat_gateway_addresses[0].allocation_id == allocation_id + # - create_ngw.nat_gateway_id.startswith("nat-") + # - '"state" in create_ngw' + # - create_ngw.state == 'available' + # - '"subnet_id" in create_ngw' + # - create_ngw.subnet_id == subnet_id + # - '"tags" in create_ngw' + # - '"vpc_id" in create_ngw' + # - create_ngw.vpc_id == vpc_id + + - name: Fetch NAT gateway by ID (list) + ec2_vpc_nat_gateway_info: + nat_gateway_ids: + - "{{ nat_gateway_id }}" + register: ngw_info + retries: 10 + until: ngw_info is not failed + - name: Check NAT gateway exists + assert: + that: + - ngw_info is successful + - ngw_info.result | length == 1 + - '"create_time" in first_ngw' + - '"nat_gateway_addresses" in first_ngw' + - '"nat_gateway_id" in first_ngw' + - first_ngw.nat_gateway_id == nat_gateway_id + - '"state" in first_ngw' + - first_ngw.state == 'available' + - '"subnet_id" in first_ngw' + - first_ngw.subnet_id == subnet_id + - '"tags" in first_ngw' + - '"vpc_id" in first_ngw' + - first_ngw.vpc_id == vpc_id + vars: + first_ngw: '{{ ngw_info.result[0] }}' + + # - name: Fetch NAT gateway by ID (list) - CHECK_MODE + # ec2_vpc_nat_gateway_info: + # nat_gateway_ids: + # - "{{ nat_gateway_id }}" + # register: ngw_info + # check_mode: yes + + # - name: Check NAT gateway exists - CHECK_MODE + # assert: + # that: + # - '"internet_gateways" in igw_info' + # - avalaible_ngws.result | length == 1 + # - '"create_time" in first_ngw' + # - '"nat_gateway_addresses" in first_ngw' + # - '"nat_gateway_id" in first_ngw' + # - first_ngw.nat_gateway_id == nat_gateway_id + # - '"state" in first_ngw' + # - first_ngw.state == 'available' + # - '"subnet_id" in first_ngw' + # - first_ngw.subnet_id == subnet_id + # - '"tags" in first_ngw' + # - '"vpc_id" in first_ngw' + # - first_ngw.vpc_id == vpc_id + # vars: + # first_ngw: '{{ ngw_info.result[0] }}' # ============================================================ - name: Delete NAT gateway @@ -266,6 +516,17 @@ assert: that: - delete_nat_gateway.changed + - '"delete_time" in delete_nat_gateway' + - '"nat_gateway_addresses" in delete_nat_gateway' + - '"nat_gateway_id" in delete_nat_gateway' + - delete_nat_gateway.nat_gateway_id == nat_gateway_id + - '"state" in delete_nat_gateway' + - delete_nat_gateway.state == 'deleted' + - '"subnet_id" in delete_nat_gateway' + - delete_nat_gateway.subnet_id == subnet_id + - '"tags" in delete_nat_gateway' + - '"vpc_id" in delete_nat_gateway' + - delete_nat_gateway.vpc_id == vpc_id # - name: Delete NAT gateway - CHECK_MODE # ec2_vpc_nat_gateway: @@ -278,7 +539,19 @@ # - name: Assert state=absent (expected changed=true) - CHECK_MODE # assert: # that: - # - delete_nat_gateway.changed + # - delete_nat_gateway.changed + # - '"delete_time" in delete_nat_gateway' + # - '"nat_gateway_addresses" in delete_nat_gateway' + # - '"nat_gateway_id" in delete_nat_gateway' + # - delete_nat_gateway.nat_gateway_id == nat_gateway_id + # - '"state" in delete_nat_gateway' + # - delete_nat_gateway.state == 'deleted' + # - '"subnet_id" in delete_nat_gateway' + # - delete_nat_gateway.subnet_id == subnet_id + # - '"tags" in delete_nat_gateway' + # - '"vpc_id" in delete_nat_gateway' + # - delete_nat_gateway.vpc_id == vpc_id + # ============================================================ - name: Create new NAT gateway with eip allocation-id and tags @@ -295,6 +568,25 @@ assert: that: - create_ngw.changed + - '"create_time" in create_ngw' + - create_ngw.nat_gateway_addresses[0].allocation_id == allocation_id + - '"nat_gateway_id" in create_ngw' + - create_ngw.nat_gateway_id.startswith("nat-") + - '"state" in create_ngw' + - create_ngw.state == 'available' + - '"subnet_id" in create_ngw' + - create_ngw.subnet_id == subnet_id + - '"tags" in create_ngw' + - create_ngw.tags | length == 2 + - create_ngw.tags["tag_one"] == '{{ resource_prefix }} One' + - create_ngw.tags["Tag Two"] == 'two {{ resource_prefix }}' + - '"vpc_id" in create_ngw' + - create_ngw.vpc_id == vpc_id + + + - name: "set facts: NAT gateway ID" + set_fact: + ngw_id: "{{ create_ngw.nat_gateway_id }}" # - name: Create new NAT gateway with eip allocation-id and tags - CHECK_MODE # ec2_vpc_nat_gateway: @@ -310,7 +602,21 @@ # - name: Assert creation happened (expected changed=true) - CHECK_MODE # assert: # that: - # - create_ngw.changed + # - create_ngw.changed + # - '"create_time" in create_ngw' + # - create_ngw.nat_gateway_addresses[0].allocation_id == allocation_id + # - '"nat_gateway_id" in create_ngw' + # - create_ngw.nat_gateway_id.startswith("nat-") + # - '"state" in create_ngw' + # - create_ngw.state == 'available' + # - '"subnet_id" in create_ngw' + # - create_ngw.subnet_id == subnet_id + # - '"tags" in create_ngw' + # - create_ngw.tags | length == 2 + # - create_ngw.tags["tag_one"] == '{{ resource_prefix }} One' + # - create_ngw.tags["Tag Two"] == 'two {{ resource_prefix }}' + # - '"vpc_id" in create_ngw' + # - create_ngw.vpc_id == vpc_id # ============================================================ @@ -328,6 +634,18 @@ assert: that: - not update_tags_ngw.changed + - '"nat_gateway_id" in update_tags_ngw' + - update_tags_ngw.nat_gateway_id == ngw_id + - '"subnet_id" in update_tags_ngw' + - update_tags_ngw.subnet_id == subnet_id + - '"tags" in update_tags_ngw' + - update_tags_ngw.tags | length == 2 + - update_tags_ngw.tags["tag_one"] == '{{ resource_prefix }} One' + - update_tags_ngw.tags["Tag Two"] == 'two {{ resource_prefix }}' + - '"vpc_id" in update_tags_ngw' + - update_tags_ngw.vpc_id == vpc_id + + # - name: Update the tags (no change) - CHECK_MODE # ec2_vpc_nat_gateway: @@ -344,6 +662,82 @@ # assert: # that: # - not update_tags_ngw.changed + # - '"nat_gateway_id" in update_tags_ngw' + # - update_tags_ngw.nat_gateway_id == ngw_id + # - '"subnet_id" in update_tags_ngw' + # - update_tags_ngw.subnet_id == subnet_id + # - '"tags" in update_tags_ngw' + # - update_tags_ngw.tags | length == 2 + # - update_tags_ngw.tags["tag_one"] == '{{ resource_prefix }} One' + # - update_tags_ngw.tags["Tag Two"] == 'two {{ resource_prefix }}' + # - '"vpc_id" in update_tags_ngw' + # - update_tags_ngw.vpc_id == vpc_id + + + # ============================================================ + - name: Gather information about a filtered list of NAT Gateways using tags and state + ec2_vpc_nat_gateway_info: + filters: + "tag:Tag Two": 'two {{ resource_prefix }}' + state: ['available'] + register: ngw_info + + - name: Assert success + assert: + that: + - ngw_info is successful + - ngw_info.result | length == 1 + - '"create_time" in second_ngw' + - '"nat_gateway_addresses" in second_ngw' + - '"nat_gateway_id" in second_ngw' + - second_ngw.nat_gateway_id == ngw_id + - '"state" in second_ngw' + - second_ngw.state == 'available' + - '"subnet_id" in second_ngw' + - second_ngw.subnet_id == subnet_id + - '"tags" in second_ngw' + - second_ngw.tags | length == 2 + - '"tag_one" in second_ngw.tags' + - '"Tag Two" in second_ngw.tags' + - second_ngw.tags["tag_one"] == '{{ resource_prefix }} One' + - second_ngw.tags["Tag Two"] == 'two {{ resource_prefix }}' + - '"vpc_id" in second_ngw' + - second_ngw.vpc_id == vpc_id + vars: + second_ngw: '{{ ngw_info.result[0] }}' + + + #- name: Gather information about a filtered list of NAT Gateways using tags and state - CHECK_MODE + # ec2_vpc_nat_gateway_info: + # filters: + # "tag:Tag Two": 'two {{ resource_prefix }}' + # state: ['available'] + # register: ngw_info + # check_mode: yes + + #- name: Assert success - CHECK_MODE + # assert: + # that: + # - ngw_info is successful + # - ngw_info.result | length == 1 + # - '"create_time" in second_ngw' + # - '"nat_gateway_addresses" in second_ngw' + # - '"nat_gateway_id" in second_ngw' + # - second_ngw.nat_gateway_id == ngw_id + # - '"state" in second_ngw' + # - second_ngw.state == 'available' + # - '"subnet_id" in second_ngw' + # - second_ngw.subnet_id == subnet_id + # - '"tags" in second_ngw' + # - second_ngw.tags | length == 2 + # - '"tag_one" in second_ngw.tags' + # - '"Tag Two" in second_ngw.tags' + # - second_ngw.tags["tag_one"] == '{{ resource_prefix }} One' + # - second_ngw.tags["Tag Two"] == 'two {{ resource_prefix }}' + # - '"vpc_id" in second_ngw' + # - second_ngw.vpc_id == vpc_id + # vars: + # second_ngw: '{{ ngw_info.result[0] }}' # ============================================================ @@ -360,7 +754,18 @@ - name: Assert tag update would happen (expected changed=true) assert: that: - - update_tags_ngw.changed + - update_tags_ngw.changed + - '"nat_gateway_id" in update_tags_ngw' + - update_tags_ngw.nat_gateway_id == ngw_id + - '"subnet_id" in update_tags_ngw' + - update_tags_ngw.subnet_id == subnet_id + - '"tags" in update_tags_ngw' + - update_tags_ngw.tags | length == 2 + - update_tags_ngw.tags["tag_three"] == '{{ resource_prefix }} Three' + - update_tags_ngw.tags["Tag Two"] == 'two {{ resource_prefix }}' + - '"vpc_id" in update_tags_ngw' + - update_tags_ngw.vpc_id == vpc_id + # - name: Update the tags - remove and add - CHECK_MODE # ec2_vpc_nat_gateway: @@ -376,7 +781,44 @@ # - name: Assert tag update would happen (expected changed=true) - CHECK_MODE # assert: # that: - # - update_tags_ngw.changed + # - update_tags_ngw.changed + # - '"nat_gateway_id" in update_tags_ngw' + # - update_tags_ngw.nat_gateway_id == ngw_id + # - '"subnet_id" in update_tags_ngw' + # - update_tags_ngw.subnet_id == subnet_id + # - '"tags" in update_tags_ngw' + # - update_tags_ngw.tags | length == 2 + # - update_tags_ngw.tags["tag_three"] == '{{ resource_prefix }} Three' + # - update_tags_ngw.tags["Tag Two"] == 'two {{ resource_prefix }}' + # - '"vpc_id" in update_tags_ngw' + # - update_tags_ngw.vpc_id == vpc_id + + + # ============================================================ + - name: Gather information about a filtered list of NAT Gateways using tags (no match) + ec2_vpc_nat_gateway_info: + filters: + "tag:tag_one": '{{ resource_prefix }} One' + register: ngw_info + + - name: Assert success + assert: + that: + - ngw_info is successful + - ngw_info.result | length == 0 + + #- name: Gather information about a filtered list of NAT Gateways using tags (no match) - CHECK_MODE + # ec2_vpc_nat_gateway_info: + # filters: + # "tag:tag_one": '{{ resource_prefix }} One' + # register: ngw_info + # check_mode: yes + + #- name: Assert success - CHECK_MODE + # assert: + # that: + # - ngw_info is successful + # - ngw_info.result | length == 0 # ============================================================ @@ -395,6 +837,18 @@ assert: that: - update_tags_ngw.changed + - '"nat_gateway_id" in update_tags_ngw' + - update_tags_ngw.nat_gateway_id == ngw_id + - '"subnet_id" in update_tags_ngw' + - update_tags_ngw.subnet_id == subnet_id + - '"tags" in update_tags_ngw' + - update_tags_ngw.tags | length == 3 + - update_tags_ngw.tags["tag_one"] == '{{ resource_prefix }} One' + - update_tags_ngw.tags["tag_three"] == '{{ resource_prefix }} Three' + - update_tags_ngw.tags["Tag Two"] == 'two {{ resource_prefix }}' + - '"vpc_id" in update_tags_ngw' + - update_tags_ngw.vpc_id == vpc_id + # - name: Update the tags add without purge - CHECK_MODE # ec2_vpc_nat_gateway: @@ -411,7 +865,19 @@ # - name: Assert tags would be added - CHECK_MODE # assert: # that: - # - update_tags_ngw.changed + # - update_tags_ngw.changed + # - '"nat_gateway_id" in update_tags_ngw' + # - update_tags_ngw.nat_gateway_id == ngw_id + # - '"subnet_id" in update_tags_ngw' + # - update_tags_ngw.subnet_id == subnet_id + # - '"tags" in update_tags_ngw' + # - update_tags_ngw.tags | length == 3 + # - update_tags_ngw.tags["tag_one"] == '{{ resource_prefix }} One' + # - update_tags_ngw.tags["tag_three"] == '{{ resource_prefix }} Three' + # - update_tags_ngw.tags["Tag Two"] == 'two {{ resource_prefix }}' + # - '"vpc_id" in update_tags_ngw' + # - update_tags_ngw.vpc_id == vpc_id + # ============================================================ @@ -426,6 +892,14 @@ assert: that: - delete_tags_ngw.changed + - '"nat_gateway_id" in delete_tags_ngw' + - delete_tags_ngw.nat_gateway_id == ngw_id + - '"subnet_id" in delete_tags_ngw' + - delete_tags_ngw.subnet_id == subnet_id + - '"tags" in delete_tags_ngw' + - delete_tags_ngw.tags | length == 0 + - '"vpc_id" in delete_tags_ngw' + - delete_tags_ngw.vpc_id == vpc_id # - name: Remove all tags - CHECK_MODE # ec2_vpc_nat_gateway: @@ -438,7 +912,15 @@ # - name: assert tags would be removed - CHECK_MODE # assert: # that: - # - delete_tags_ngw.changed + # - delete_tags_ngw.changed + # - '"nat_gateway_id" in delete_tags_ngw' + # - delete_tags_ngw.nat_gateway_id == ngw_id + # - '"subnet_id" in delete_tags_ngw' + # - delete_tags_ngw.subnet_id == subnet_id + # - '"tags" in delete_tags_ngw' + # - delete_tags_ngw.tags | length == 0 + # - '"vpc_id" in delete_tags_ngw' + # - delete_tags_ngw.vpc_id == vpc_id @@ -461,10 +943,18 @@ assert: that: - update_tags_ngw.changed + - '"nat_gateway_id" in update_tags_ngw' + - update_tags_ngw.nat_gateway_id == ngw_id + - '"subnet_id" in update_tags_ngw' + - update_tags_ngw.subnet_id == subnet_id + - '"tags" in update_tags_ngw' + - update_tags_ngw.tags | length == 4 - update_tags_ngw.tags["lowercase spaced"] == 'hello cruel world ❤️' - update_tags_ngw.tags["Title Case"] == 'Hello Cruel World ❤️' - update_tags_ngw.tags["CamelCase"] == 'SimpleCamelCase ❤️' - update_tags_ngw.tags["snake_case"] == 'simple_snake_case ❤️' + - '"vpc_id" in update_tags_ngw' + - update_tags_ngw.vpc_id == vpc_id # - name: Update with CamelCase tags - CHECK_MODE @@ -480,15 +970,24 @@ # snake_case: 'simple_snake_case ❤️' # wait: yes # register: update_tags_ngw + # check_mode: yes #- name: Assert tags would be added - CHECK_MODE # assert: # that: # - update_tags_ngw.changed + # - '"nat_gateway_id" in update_tags_ngw' + # - update_tags_ngw.nat_gateway_id == ngw_id + # - '"subnet_id" in update_tags_ngw' + # - update_tags_ngw.subnet_id == subnet_id + # - '"tags" in update_tags_ngw' + # - update_tags_ngw.tags | length == 4 # - update_tags_ngw.tags["lowercase spaced"] == 'hello cruel world ❤️' # - update_tags_ngw.tags["Title Case"] == 'Hello Cruel World ❤️' # - update_tags_ngw.tags["CamelCase"] == 'SimpleCamelCase ❤️' # - update_tags_ngw.tags["snake_case"] == 'simple_snake_case ❤️' + # - '"vpc_id" in update_tags_ngw' + # - update_tags_ngw.vpc_id == vpc_id # ============================================================