From 1890c43623e70d83d2ca6f5fab4cfc5b4aafd64a Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Mon, 2 May 2022 12:25:38 +0200 Subject: [PATCH] New Module: TGW VPC Attachments (#1004) New modules: Transit Gateway VPC attachments SUMMARY Adds support for EC2 Transit Gateway VPC attachments Does not support accepting / rejecting attachments at this time. ISSUE TYPE New Module Pull Request COMPONENT NAME ec2_transit_gateway_vpc_attachment ec2_transit_gateway_vpc_attachment_info ADDITIONAL INFORMATION Reviewed-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/9494e761542478e480831789a77513dba8cadbc0 --- .../ec2_transit_gateway_vpc_attachment.py | 349 ++ ...ec2_transit_gateway_vpc_attachment_info.py | 200 + .../aliases | 3 + .../defaults/main.yml | 26 + .../meta/main.yml | 2 + .../tasks/cleanup.yml | 64 + .../tasks/complex.yml | 443 ++ .../tasks/main.yml | 24 + .../tasks/setup.yml | 101 + .../tasks/simple.yml | 3611 +++++++++++++++++ 10 files changed, 4823 insertions(+) create mode 100644 plugins/modules/ec2_transit_gateway_vpc_attachment.py create mode 100644 plugins/modules/ec2_transit_gateway_vpc_attachment_info.py create mode 100644 tests/integration/targets/ec2_transit_gateway_vpc_attachment/aliases create mode 100644 tests/integration/targets/ec2_transit_gateway_vpc_attachment/defaults/main.yml create mode 100644 tests/integration/targets/ec2_transit_gateway_vpc_attachment/meta/main.yml create mode 100644 tests/integration/targets/ec2_transit_gateway_vpc_attachment/tasks/cleanup.yml create mode 100644 tests/integration/targets/ec2_transit_gateway_vpc_attachment/tasks/complex.yml create mode 100644 tests/integration/targets/ec2_transit_gateway_vpc_attachment/tasks/main.yml create mode 100644 tests/integration/targets/ec2_transit_gateway_vpc_attachment/tasks/setup.yml create mode 100644 tests/integration/targets/ec2_transit_gateway_vpc_attachment/tasks/simple.yml diff --git a/plugins/modules/ec2_transit_gateway_vpc_attachment.py b/plugins/modules/ec2_transit_gateway_vpc_attachment.py new file mode 100644 index 00000000000..13518fdbe2a --- /dev/null +++ b/plugins/modules/ec2_transit_gateway_vpc_attachment.py @@ -0,0 +1,349 @@ +#!/usr/bin/python +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + + +DOCUMENTATION = ''' +module: ec2_transit_gateway_vpc_attachment +short_description: Create and delete AWS Transit Gateway VPC attachments +version_added: 4.0.0 +description: + - Creates, Deletes and Updates AWS Transit Gateway VPC Attachments. +options: + transit_gateway: + description: + - The ID of the Transit Gateway that the attachment belongs to. + - When creating a new attachment, I(transit_gateway) must be provided. + - At least one of I(name), I(transit_gateway) and I(id) must be provided. + - I(transit_gateway) is an immutable setting and can not be updated on an + existing attachment. + type: str + required: false + aliases: ['transit_gateway_id'] + id: + description: + - The ID of the Transit Gateway Attachment. + - When I(id) is not set, a search using I(transit_gateway) and I(name) will be + performed. If multiple results are returned, the module will fail. + - At least one of I(name), I(transit_gateway) and I(id) must be provided. + type: str + required: false + aliases: ['attachment_id'] + name: + description: + - The C(Name) tag of the Transit Gateway attachment. + - Providing both I(id) and I(name) will set the C(Name) tag on an existing + attachment the matching I(id). + - Setting the C(Name) tag in I(tags) will also result in the C(Name) tag being + updated. + - At least one of I(name), I(transit_gateway) and I(id) must be provided. + type: str + required: false + state: + description: + - Create or remove the Transit Gateway attachment. + type: str + required: false + choices: ['present', 'absent'] + default: 'present' + subnets: + description: + - The ID of the subnets in which to create the transit gateway VPC attachment. + - Required when creating a new attachment. + type: list + elements: str + required: false + purge_subnets: + description: + - If I(purge_subnets=true), existing subnets will be removed from the + attachment as necessary to match exactly what is defined by I(subnets). + type: bool + required: false + default: true + dns_support: + description: + - Whether DNS support is enabled. + type: bool + required: false + ipv6_support: + description: + - Whether IPv6 support is enabled. + type: bool + required: false + appliance_mode_support: + description: + - Whether the attachment is configured for appliance mode. + - When appliance mode is enabled, Transit Gateway, using 4-tuples of an + IP packet, selects a single Transit Gateway ENI in the Appliance VPC + for the life of a flow to send traffic to. + type: bool + required: false + tags: + description: + - A dictionary representing the tags associated with the Transit Gateway + attachment. + - 'For example C({"Example Tag": "some example value"})' + - Unless I(purge_tags=False) all other tags will be removed from the + attachment. + type: dict + required: false + purge_tags: + description: + - If I(purge_tags=true), existing tags will be purged from the resource + to match exactly what is defined by I(tags) parameter. + type: bool + required: false + default: true + wait: + description: + - Whether to wait for the Transit Gateway attachment to reach the + C(Available) or C(Deleted) state before the module returns. + type: bool + required: false + default: true + wait_timeout: + description: + - Maximum time, in seconds, to wait for the Transit Gateway attachment + to reach the expected state. + - Defaults to 600 seconds. + type: int + required: false +author: "Mark Chappell (@tremble)" +extends_documentation_fragment: + - amazon.aws.aws + - amazon.aws.ec2 +''' + +EXAMPLES = ''' +# Create a Transit Gateway attachment +- community.aws.ec2_transit_gateway_vpc_attachment: + state: present + transit_gateway: 'tgw-123456789abcdef01' + name: AnsibleTest-1 + subnets: + - subnet-00000000000000000 + - subnet-11111111111111111 + - subnet-22222222222222222 + ipv6_support: True + purge_subnets: True + dns_support: True + appliance_mode_support: True + tags: + TestTag: changed data in Test Tag + +# Set sub options on a Transit Gateway attachment +- community.aws.ec2_transit_gateway_vpc_attachment: + state: present + id: 'tgw-attach-0c0c5fd0b0f01d1c9' + name: AnsibleTest-1 + ipv6_support: True + purge_subnets: False + dns_support: False + appliance_mode_support: True + +# Delete the transit gateway +- community.aws.ec2_transit_gateway_vpc_attachment: + state: absent + id: 'tgw-attach-0c0c5fd0b0f01d1c9' +''' + +RETURN = ''' +transit_gateway_attachments: + description: The attributes of the Transit Gateway attachments. + type: list + elements: dict + returned: success + contains: + creation_time: + description: + - An ISO 8601 date time stamp of when the attachment was created. + type: str + returned: success + example: '2022-03-10T16:40:26+00:00' + options: + description: + - Additional VPC attachment options. + type: dict + returned: success + contains: + appliance_mode_support: + description: + - Indicates whether appliance mode support is enabled. + type: str + returned: success + example: 'enable' + dns_support: + description: + - Indicates whether DNS support is enabled. + type: str + returned: success + example: 'disable' + ipv6_support: + description: + - Indicates whether IPv6 support is disabled. + type: str + returned: success + example: 'disable' + state: + description: + - The state of the attachment. + type: str + returned: success + example: 'deleting' + subnet_ids: + description: + - The IDs of the subnets in use by the attachment. + type: list + elements: str + returned: success + example: ['subnet-0123456789abcdef0', 'subnet-11111111111111111'] + tags: + description: + - A dictionary representing the resource tags. + type: dict + returned: success + transit_gateway_attachment_id: + description: + - The ID of the attachment. + type: str + returned: success + example: 'tgw-attach-0c0c5fd0b0f01d1c9' + transit_gateway_id: + description: + - The ID of the transit gateway that the attachment is connected to. + type: str + returned: success + example: 'tgw-0123456789abcdef0' + vpc_id: + description: + - The ID of the VPC that the attachment is connected to. + type: str + returned: success + example: 'vpc-0123456789abcdef0' + vpc_owner_id: + description: + - The ID of the account that the VPC belongs to. + type: str + returned: success + example: '012345678901' +''' + + +from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule + +from ansible_collections.community.aws.plugins.module_utils.transitgateway import TransitGatewayVpcAttachmentManager + + +def main(): + + argument_spec = dict( + state=dict(type='str', required=False, default='present', choices=['absent', 'present']), + transit_gateway=dict(type='str', required=False, aliases=['transit_gateway_id']), + id=dict(type='str', required=False, aliases=['attachment_id']), + name=dict(type='str', required=False), + subnets=dict(type='list', elements='str', required=False), + purge_subnets=dict(type='bool', required=False, default=True), + tags=dict(type='dict', required=False), + purge_tags=dict(type='bool', required=False, default=True), + appliance_mode_support=dict(type='bool', required=False), + dns_support=dict(type='bool', required=False), + ipv6_support=dict(type='bool', required=False), + wait=dict(type='bool', required=False, default=True), + wait_timeout=dict(type='int', required=False), + ) + + one_of = [ + ['id', 'transit_gateway', 'name'], + ] + + module = AnsibleAWSModule( + argument_spec=argument_spec, + supports_check_mode=True, + required_one_of=one_of, + ) + + attach_id = module.params.get('id', None) + tgw = module.params.get('transit_gateway', None) + name = module.params.get('name', None) + tags = module.params.get('tags', None) + purge_tags = module.params.get('purge_tags') + state = module.params.get('state') + subnets = module.params.get('subnets', None) + purge_subnets = module.params.get('purge_subnets') + + # When not provided with an ID see if one exists. + if not attach_id: + search_manager = TransitGatewayVpcAttachmentManager(module=module) + filters = dict() + if tgw: + filters['transit-gateway-id'] = tgw + if name: + filters['tag:Name'] = name + if subnets: + vpc_id = search_manager.subnets_to_vpc(subnets) + filters['vpc-id'] = vpc_id + + # Attachments lurk in a 'deleted' state, for a while, ignore them so we + # can reuse the names + filters['state'] = [ + 'available', 'deleting', 'failed', 'failing', 'initiatingRequest', 'modifying', + 'pendingAcceptance', 'pending', 'rollingBack', 'rejected', 'rejecting' + ] + attachments = search_manager.list(filters=filters) + if len(attachments) > 1: + module.fail_json('Multiple matching attachments found, provide an ID', attachments=attachments) + # If we find a match then we'll modify it by ID, otherwise we'll be + # creating a new RTB. + if attachments: + attach_id = attachments[0]['transit_gateway_attachment_id'] + + manager = TransitGatewayVpcAttachmentManager(module=module, id=attach_id) + manager.set_wait(module.params.get('wait', None)) + manager.set_wait_timeout(module.params.get('wait_timeout', None)) + + if state == 'absent': + manager.delete() + else: + if not attach_id: + if not tgw: + module.fail_json('No existing attachment found. To create a new attachment' + ' the `transit_gateway` parameter must be provided.') + if not subnets: + module.fail_json('No existing attachment found. To create a new attachment' + ' the `subnets` parameter must be provided.') + + # name is just a special case of tags. + if name: + new_tags = dict(Name=name) + if tags is None: + purge_tags = False + else: + new_tags.update(tags) + tags = new_tags + + manager.set_transit_gateway(tgw) + manager.set_subnets(subnets, purge_subnets) + manager.set_tags(tags, purge_tags) + manager.set_dns_support(module.params.get('dns_support', None)) + manager.set_ipv6_support(module.params.get('ipv6_support', None)) + manager.set_appliance_mode_support(module.params.get('appliance_mode_support', None)) + manager.flush_changes() + + results = dict( + changed=manager.changed, + attachments=[manager.updated_resource], + ) + if manager.changed: + results['diff'] = dict( + before=manager.original_resource, + after=manager.updated_resource, + ) + + module.exit_json(**results) + + +if __name__ == '__main__': + main() diff --git a/plugins/modules/ec2_transit_gateway_vpc_attachment_info.py b/plugins/modules/ec2_transit_gateway_vpc_attachment_info.py new file mode 100644 index 00000000000..a0a07ce87d7 --- /dev/null +++ b/plugins/modules/ec2_transit_gateway_vpc_attachment_info.py @@ -0,0 +1,200 @@ +#!/usr/bin/python +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + + +DOCUMENTATION = ''' +module: ec2_transit_gateway_vpc_attachment_info +short_description: describes AWS Transit Gateway VPC attachments +version_added: 4.0.0 +description: + - Describes AWS Transit Gateway VPC Attachments. +options: + id: + description: + - The ID of the Transit Gateway Attachment. + - Mutually exclusive with I(name) and I(filters) + type: str + required: false + aliases: ['attachment_id'] + name: + description: + - The C(Name) tag of the Transit Gateway attachment. + type: str + required: false + filters: + description: + - A dictionary of filters to apply. Each dict item consists of a filter key and a filter value. + - Setting a C(tag:Name) filter will override the I(name) parameter. + type: dict + required: false + include_deleted: + description: + - If I(include_deleted=True), then attachments in a deleted state will + also be returned. + - Setting a C(state) filter will override the I(include_deleted) parameter. + type: bool + required: false + default: false +author: "Mark Chappell (@tremble)" +extends_documentation_fragment: + - amazon.aws.aws + - amazon.aws.ec2 +''' + +EXAMPLES = ''' +# Describe a specific Transit Gateway attachment. +- community.aws.ec2_transit_gateway_vpc_attachment_info: + state: present + id: 'tgw-attach-0123456789abcdef0' + +# Describe all attachments attached to a transit gateway. +- community.aws.ec2_transit_gateway_vpc_attachment_info: + state: present + filters: + transit-gateway-id: tgw-0fedcba9876543210' + +# Describe all attachments in an account. +- community.aws.ec2_transit_gateway_vpc_attachment_info: + state: present + filters: + transit-gateway-id: tgw-0fedcba9876543210' +''' + +RETURN = ''' +transit_gateway_attachments: + description: The attributes of the Transit Gateway attachments. + type: list + elements: dict + returned: success + contains: + creation_time: + description: + - An ISO 8601 date time stamp of when the attachment was created. + type: str + returned: success + example: '2022-03-10T16:40:26+00:00' + options: + description: + - Additional VPC attachment options. + type: dict + returned: success + contains: + appliance_mode_support: + description: + - Indicates whether appliance mode support is enabled. + type: str + returned: success + example: 'enable' + dns_support: + description: + - Indicates whether DNS support is enabled. + type: str + returned: success + example: 'disable' + ipv6_support: + description: + - Indicates whether IPv6 support is disabled. + type: str + returned: success + example: 'disable' + state: + description: + - The state of the attachment. + type: str + returned: success + example: 'deleting' + subnet_ids: + description: + - The IDs of the subnets in use by the attachment. + type: list + elements: str + returned: success + example: ['subnet-0123456789abcdef0', 'subnet-11111111111111111'] + tags: + description: + - A dictionary representing the resource tags. + type: dict + returned: success + transit_gateway_attachment_id: + description: + - The ID of the attachment. + type: str + returned: success + example: 'tgw-attach-0c0c5fd0b0f01d1c9' + transit_gateway_id: + description: + - The ID of the transit gateway that the attachment is connected to. + type: str + returned: success + example: 'tgw-0123456789abcdef0' + vpc_id: + description: + - The ID of the VPC that the attachment is connected to. + type: str + returned: success + example: 'vpc-0123456789abcdef0' + vpc_owner_id: + description: + - The ID of the account that the VPC belongs to. + type: str + returned: success + example: '012345678901' +''' + + +from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule + +from ansible_collections.community.aws.plugins.module_utils.transitgateway import TransitGatewayVpcAttachmentManager + + +def main(): + + argument_spec = dict( + id=dict(type='str', required=False, aliases=['attachment_id']), + name=dict(type='str', required=False), + filters=dict(type='dict', required=False), + include_deleted=dict(type='bool', required=False, default=False) + ) + + mutually_exclusive = [ + ['id', 'name'], + ['id', 'filters'], + ] + + module = AnsibleAWSModule( + argument_spec=argument_spec, + supports_check_mode=True, + ) + + name = module.params.get('name', None) + id = module.params.get('id', None) + opt_filters = module.params.get('filters', None) + + search_manager = TransitGatewayVpcAttachmentManager(module=module) + filters = dict() + + if name: + filters['tag:Name'] = name + + if not module.params.get('include_deleted'): + # Attachments lurk in a 'deleted' state, for a while, ignore them so we + # can reuse the names + filters['state'] = [ + 'available', 'deleting', 'failed', 'failing', 'initiatingRequest', 'modifying', + 'pendingAcceptance', 'pending', 'rollingBack', 'rejected', 'rejecting' + ] + + if opt_filters: + filters.update(opt_filters) + + attachments = search_manager.list(filters=filters, id=id) + + module.exit_json(changed=False, attachments=attachments, filters=filters) + + +if __name__ == '__main__': + main() diff --git a/tests/integration/targets/ec2_transit_gateway_vpc_attachment/aliases b/tests/integration/targets/ec2_transit_gateway_vpc_attachment/aliases new file mode 100644 index 00000000000..fb58dd5786f --- /dev/null +++ b/tests/integration/targets/ec2_transit_gateway_vpc_attachment/aliases @@ -0,0 +1,3 @@ +cloud/aws + +# ec2_transit_gateway_vpc_attachment_info diff --git a/tests/integration/targets/ec2_transit_gateway_vpc_attachment/defaults/main.yml b/tests/integration/targets/ec2_transit_gateway_vpc_attachment/defaults/main.yml new file mode 100644 index 00000000000..c9727746555 --- /dev/null +++ b/tests/integration/targets/ec2_transit_gateway_vpc_attachment/defaults/main.yml @@ -0,0 +1,26 @@ +_resource_prefix: 'AnsibleTest' +#_resource_prefix: 'AnsibleTest-{{ tiny_prefix }}-TGW-Attach' +cidr_prefix: '10.{{ 255 | random(seed=_resource_prefix) }}' +tgw_name: '{{ _resource_prefix }}' +tgw_name_2: '{{ _resource_prefix }}-2' +vpc_name_a: '{{ _resource_prefix }}-1' +vpc_name_b: '{{ _resource_prefix }}-2' +vpc_cidr_a: '{{ cidr_prefix }}.1.0/24' +vpc_cidr_b: '{{ cidr_prefix }}.2.0/24' + +subnet_cidr_a_1: '{{ cidr_prefix }}.1.0/26' +subnet_cidr_a_2: '{{ cidr_prefix }}.1.64/26' +subnet_cidr_a_3: '{{ cidr_prefix }}.1.128/26' +subnet_cidr_a_1a: '{{ cidr_prefix }}.1.192/26' +subnet_cidr_b_1: '{{ cidr_prefix }}.2.0/26' +subnet_cidr_b_2: '{{ cidr_prefix }}.2.64/26' + +subnet_name_a_1: '{{ _resource_prefix }}-a-1' +subnet_name_a_1a: '{{ _resource_prefix }}-a-1a' +subnet_name_a_2: '{{ _resource_prefix }}-a-2' +subnet_name_a_3: '{{ _resource_prefix }}-a-3' +subnet_name_b_1: '{{ _resource_prefix }}-b-1' +subnet_name_b_2: '{{ _resource_prefix }}-b-2' + +attachment_name: '{{ _resource_prefix }}' +attachment_name_complex: '{{ _resource_prefix }}-complex' diff --git a/tests/integration/targets/ec2_transit_gateway_vpc_attachment/meta/main.yml b/tests/integration/targets/ec2_transit_gateway_vpc_attachment/meta/main.yml new file mode 100644 index 00000000000..aef5ca0ee57 --- /dev/null +++ b/tests/integration/targets/ec2_transit_gateway_vpc_attachment/meta/main.yml @@ -0,0 +1,2 @@ +dependencies: + - role: setup_ec2_facts diff --git a/tests/integration/targets/ec2_transit_gateway_vpc_attachment/tasks/cleanup.yml b/tests/integration/targets/ec2_transit_gateway_vpc_attachment/tasks/cleanup.yml new file mode 100644 index 00000000000..e59723bdc30 --- /dev/null +++ b/tests/integration/targets/ec2_transit_gateway_vpc_attachment/tasks/cleanup.yml @@ -0,0 +1,64 @@ +--- +- name: 'Describe all attachments on our VPC' + ec2_transit_gateway_vpc_attachment_info: + filters: + transit-gateway-id: '{{ tgw_id }}' + register: info + ignore_errors: True + +- name: 'Start deletion of all attachments' + ec2_transit_gateway_vpc_attachment: + state: absent + id: '{{ item.transit_gateway_attachment_id }}' + wait: False + loop: '{{ info.attachments }}' + ignore_errors: True + +- name: 'Wait for deletion of all attachments' + ec2_transit_gateway_vpc_attachment: + state: absent + id: '{{ item.transit_gateway_attachment_id }}' + wait: True + loop: '{{ info.attachments }}' + ignore_errors: True + +- name: 'Delete subnets' + ec2_vpc_subnet: + state: absent + cidr: '{{ item.cidr }}' + vpc_id: '{{ item.vpc_id }}' + loop: + - cidr: '{{ subnet_cidr_a_1 }}' + vpc_id: '{{ vpc_id_a }}' + - cidr: '{{ subnet_cidr_a_2 }}' + vpc_id: '{{ vpc_id_a }}' + - cidr: '{{ subnet_cidr_a_3 }}' + vpc_id: '{{ vpc_id_a }}' + - cidr: '{{ subnet_cidr_b_1 }}' + vpc_id: '{{ vpc_id_b }}' + - cidr: '{{ subnet_cidr_b_2 }}' + vpc_id: '{{ vpc_id_b }}' + - cidr: '{{ subnet_cidr_a_1a }}' + vpc_id: '{{ vpc_id_a }}' + ignore_errors: True + +- name: 'Create VPCs to attach to TGW' + ec2_vpc_net: + state: absent + cidr_block: '{{ item.cidr }}' + name: '{{ item.name }}' + loop: + - cidr: '{{ vpc_cidr_a }}' + name: '{{ vpc_name_a }}' + - cidr: '{{ vpc_cidr_b }}' + name: '{{ vpc_name_b }}' + ignore_errors: True + +- name: 'Create Transit Gateways' + ec2_transit_gateway: + state: absent + transit_gateway_id: '{{ item.tgw_id }}' + loop: + - tgw_id: '{{ tgw_id }}' + - tgw_id: '{{ tgw_id_2 }}' + ignore_errors: True diff --git a/tests/integration/targets/ec2_transit_gateway_vpc_attachment/tasks/complex.yml b/tests/integration/targets/ec2_transit_gateway_vpc_attachment/tasks/complex.yml new file mode 100644 index 00000000000..eda3ab2ace4 --- /dev/null +++ b/tests/integration/targets/ec2_transit_gateway_vpc_attachment/tasks/complex.yml @@ -0,0 +1,443 @@ +--- +# Tests the setting of most parameters at the same time +# +# Note: Does not delete the attachment, so that there's a second VPC attached to +# the TGW when we run our _info tests in simple.yml +# +# ============================================================================= +# Creation + +- block: + - name: '(CHECK_MODE) Create an attachment - complex parameters' + check_mode: True + ec2_transit_gateway_vpc_attachment: + name: '{{ attachment_name_complex }}' + transit_gateway: '{{ tgw_id }}' + subnets: + - '{{ subnet_id_b_1 }}' + - '{{ subnet_id_b_2 }}' + tags: + tagA: 'example Value' + Tag_B: 'second value' + appliance_mode_support: True + ipv6_support: True + register: complex_attach + + - assert: + that: + - complex_attach is changed + - '"attachments" in complex_attach' + - complex_attach.attachments | length == 1 + - '"options" in attachment' + - '"subnet_ids" in attachment' + - '"tags" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == "enable" + - attachment.options.ipv6_support == "enable" + - attachment.subnet_ids | length == 2 + - subnet_id_b_1 in attachment.subnet_ids + - subnet_id_b_2 in attachment.subnet_ids + - attachment.tags | length == 3 + - '"Name" in attachment.tags' + - '"tagA" in attachment.tags' + - '"Tag_B" in attachment.tags' + - attachment.tags.Name == attachment_name_complex + - attachment.tags.tagA == "example Value" + - attachment.tags.Tag_B == "second value" + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_b + vars: + attachment: '{{ complex_attach.attachments[0] }}' + + - name: 'Create an attachment - complex parameters' + ec2_transit_gateway_vpc_attachment: + name: '{{ attachment_name_complex }}' + transit_gateway: '{{ tgw_id }}' + subnets: + - '{{ subnet_id_b_1 }}' + - '{{ subnet_id_b_2 }}' + tags: + tagA: 'example Value' + Tag_B: 'second value' + appliance_mode_support: True + ipv6_support: True + register: complex_attach + + - assert: + that: + - complex_attach is changed + - '"attachments" in complex_attach' + - complex_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 2 + - subnet_id_b_1 in attachment.subnet_ids + - subnet_id_b_2 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_b + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'enable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'enable' + - attachment.transit_gateway_attachment_id.startswith('tgw-attach-') + - attachment.state == 'available' + - attachment.tags | length == 3 + - '"Name" in attachment.tags' + - '"tagA" in attachment.tags' + - '"Tag_B" in attachment.tags' + - attachment.tags.Name == attachment_name_complex + - attachment.tags.tagA == "example Value" + - attachment.tags.Tag_B == "second value" + - attachment.vpc_owner_id == vpc_owner_b + vars: + attachment: '{{ complex_attach.attachments[0] }}' + + - name: Save Attachment ID + set_fact: + complex_attachment_id: '{{ complex_attach.attachments[0].transit_gateway_attachment_id }}' + + - name: '(CHECK_MODE) Create an attachment - complex parameters -- IDEMPOTENCY' + check_mode: True + ec2_transit_gateway_vpc_attachment: + name: '{{ attachment_name_complex }}' + transit_gateway: '{{ tgw_id }}' + subnets: + - '{{ subnet_id_b_1 }}' + - '{{ subnet_id_b_2 }}' + tags: + tagA: 'example Value' + Tag_B: 'second value' + appliance_mode_support: True + ipv6_support: True + register: complex_attach + + - assert: + that: + - complex_attach is not changed + - '"attachments" in complex_attach' + - complex_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 2 + - subnet_id_b_1 in attachment.subnet_ids + - subnet_id_b_2 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_b + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'enable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'enable' + - attachment.transit_gateway_attachment_id == complex_attachment_id + - attachment.state == 'available' + - attachment.tags | length == 3 + - '"Name" in attachment.tags' + - '"tagA" in attachment.tags' + - '"Tag_B" in attachment.tags' + - attachment.tags.Name == attachment_name_complex + - attachment.tags.tagA == "example Value" + - attachment.tags.Tag_B == "second value" + - attachment.vpc_owner_id == vpc_owner_b + vars: + attachment: '{{ complex_attach.attachments[0] }}' + + - name: 'Create an attachment - complex parameters -- IDEMPOTENCY' + ec2_transit_gateway_vpc_attachment: + name: '{{ attachment_name_complex }}' + transit_gateway: '{{ tgw_id }}' + subnets: + - '{{ subnet_id_b_1 }}' + - '{{ subnet_id_b_2 }}' + tags: + tagA: 'example Value' + Tag_B: 'second value' + appliance_mode_support: True + ipv6_support: True + register: complex_attach + + - assert: + that: + - complex_attach is not changed + - '"attachments" in complex_attach' + - complex_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 2 + - subnet_id_b_1 in attachment.subnet_ids + - subnet_id_b_2 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_b + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'enable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'enable' + - attachment.transit_gateway_attachment_id == complex_attachment_id + - attachment.state == 'available' + - attachment.tags | length == 3 + - '"Name" in attachment.tags' + - '"tagA" in attachment.tags' + - '"Tag_B" in attachment.tags' + - attachment.tags.Name == attachment_name_complex + - attachment.tags.tagA == "example Value" + - attachment.tags.Tag_B == "second value" + - attachment.vpc_owner_id == vpc_owner_b + vars: + attachment: '{{ complex_attach.attachments[0] }}' + +# ============================================================================= +# Update + + - name: '(CHECK_MODE) Update an attachment - complex parameters' + check_mode: True + ec2_transit_gateway_vpc_attachment: + name: '{{ attachment_name_complex }}' + transit_gateway: '{{ tgw_id }}' + subnets: + - '{{ subnet_id_b_1 }}' + purge_subnets: True + tags: + tagC: '3' + Tag_D: 'Hello again dear world' + purge_tags: False + dns_support: False + ipv6_support: False + register: complex_attach + + - assert: + that: + - complex_attach is changed + - '"attachments" in complex_attach' + - complex_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_b_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_b + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'enable' + - attachment.options.dns_support == 'disable' + - attachment.options.ipv6_support == 'disable' + - attachment.transit_gateway_attachment_id == complex_attachment_id + - attachment.state == 'available' + - attachment.tags | length == 5 + - '"Name" in attachment.tags' + - '"tagA" in attachment.tags' + - '"Tag_B" in attachment.tags' + - '"tagC" in attachment.tags' + - '"Tag_D" in attachment.tags' + - attachment.tags.Name == attachment_name_complex + - attachment.tags.tagA == "example Value" + - attachment.tags.Tag_B == "second value" + - attachment.tags.tagC == "3" + - attachment.tags.Tag_D == "Hello again dear world" + - attachment.vpc_owner_id == vpc_owner_b + vars: + attachment: '{{ complex_attach.attachments[0] }}' + + - name: 'Update an attachment - complex parameters' + ec2_transit_gateway_vpc_attachment: + name: '{{ attachment_name_complex }}' + transit_gateway: '{{ tgw_id }}' + subnets: + - '{{ subnet_id_b_1 }}' + purge_subnets: True + tags: + tagC: '3' + Tag_D: 'Hello again dear world' + purge_tags: False + dns_support: False + ipv6_support: False + register: complex_attach + + - assert: + that: + - complex_attach is changed + - '"attachments" in complex_attach' + - complex_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_b_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_b + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'enable' + - attachment.options.dns_support == 'disable' + - attachment.options.ipv6_support == 'disable' + - attachment.transit_gateway_attachment_id == complex_attachment_id + - attachment.state == 'available' + - attachment.tags | length == 5 + - '"Name" in attachment.tags' + - '"tagA" in attachment.tags' + - '"Tag_B" in attachment.tags' + - '"tagC" in attachment.tags' + - '"Tag_D" in attachment.tags' + - attachment.tags.Name == attachment_name_complex + - attachment.tags.tagA == "example Value" + - attachment.tags.Tag_B == "second value" + - attachment.tags.tagC == "3" + - attachment.tags.Tag_D == "Hello again dear world" + - attachment.vpc_owner_id == vpc_owner_b + vars: + attachment: '{{ complex_attach.attachments[0] }}' + + - name: '(CHECK_MODE) Update an attachment - complex parameters -- IDEMPOTENCY' + check_mode: True + ec2_transit_gateway_vpc_attachment: + name: '{{ attachment_name_complex }}' + transit_gateway: '{{ tgw_id }}' + subnets: + - '{{ subnet_id_b_1 }}' + purge_subnets: True + tags: + tagC: '3' + Tag_D: 'Hello again dear world' + purge_tags: False + dns_support: False + ipv6_support: False + register: complex_attach + + - assert: + that: + - complex_attach is not changed + - '"attachments" in complex_attach' + - complex_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_b_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_b + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'enable' + - attachment.options.dns_support == 'disable' + - attachment.options.ipv6_support == 'disable' + - attachment.transit_gateway_attachment_id == complex_attachment_id + - attachment.state == 'available' + - attachment.tags | length == 5 + - '"Name" in attachment.tags' + - '"tagA" in attachment.tags' + - '"Tag_B" in attachment.tags' + - '"tagC" in attachment.tags' + - '"Tag_D" in attachment.tags' + - attachment.tags.Name == attachment_name_complex + - attachment.tags.tagA == "example Value" + - attachment.tags.Tag_B == "second value" + - attachment.tags.tagC == "3" + - attachment.tags.Tag_D == "Hello again dear world" + - attachment.vpc_owner_id == vpc_owner_b + vars: + attachment: '{{ complex_attach.attachments[0] }}' + + - name: 'Update an attachment - complex parameters -- IDEMPOTENCY' + ec2_transit_gateway_vpc_attachment: + name: '{{ attachment_name_complex }}' + transit_gateway: '{{ tgw_id }}' + subnets: + - '{{ subnet_id_b_1 }}' + purge_subnets: True + tags: + tagC: '3' + Tag_D: 'Hello again dear world' + purge_tags: False + dns_support: False + ipv6_support: False + register: complex_attach + + - assert: + that: + - complex_attach is not changed + - '"attachments" in complex_attach' + - complex_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_b_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_b + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'enable' + - attachment.options.dns_support == 'disable' + - attachment.options.ipv6_support == 'disable' + - attachment.transit_gateway_attachment_id == complex_attachment_id + - attachment.state == 'available' + - attachment.tags | length == 5 + - '"Name" in attachment.tags' + - '"tagA" in attachment.tags' + - '"Tag_B" in attachment.tags' + - '"tagC" in attachment.tags' + - '"Tag_D" in attachment.tags' + - attachment.tags.Name == attachment_name_complex + - attachment.tags.tagA == "example Value" + - attachment.tags.Tag_B == "second value" + - attachment.tags.tagC == "3" + - attachment.tags.Tag_D == "Hello again dear world" + - attachment.vpc_owner_id == vpc_owner_b + vars: + attachment: '{{ complex_attach.attachments[0] }}' diff --git a/tests/integration/targets/ec2_transit_gateway_vpc_attachment/tasks/main.yml b/tests/integration/targets/ec2_transit_gateway_vpc_attachment/tasks/main.yml new file mode 100644 index 00000000000..8694b829e7b --- /dev/null +++ b/tests/integration/targets/ec2_transit_gateway_vpc_attachment/tasks/main.yml @@ -0,0 +1,24 @@ +--- +- name: 'ec2_transit_gateway_vpc_attachment integration 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 }}' + + block: + # Prepares various resources + - include_tasks: 'setup.yml' + + # Tests create / update on parameters simulatniously + - include_tasks: 'complex.yml' + + # Tests create / update / delete on individual parameters + - include_tasks: 'simple.yml' + + always: + # Cleanup after ourselves + - include_tasks: 'cleanup.yml' diff --git a/tests/integration/targets/ec2_transit_gateway_vpc_attachment/tasks/setup.yml b/tests/integration/targets/ec2_transit_gateway_vpc_attachment/tasks/setup.yml new file mode 100644 index 00000000000..86d5aa51b5f --- /dev/null +++ b/tests/integration/targets/ec2_transit_gateway_vpc_attachment/tasks/setup.yml @@ -0,0 +1,101 @@ +--- +- name: 'Pick 2 AZs available for use' + set_fact: + subnet_az_a_1: '{{ ec2_availability_zone_names[0] }}' + subnet_az_a_1a: '{{ ec2_availability_zone_names[0] }}' + subnet_az_a_2: '{{ ec2_availability_zone_names[1] }}' + subnet_az_a_3: '{{ ec2_availability_zone_names[2] }}' + subnet_az_b_1: '{{ ec2_availability_zone_names[0] }}' + subnet_az_b_2: '{{ ec2_availability_zone_names[1] }}' + +- name: 'Create Transit Gateways' + ec2_transit_gateway: + description: '{{ item.description }}' + tags: + Name: '{{ item.name }}' + loop: + - description: 'Transit Gateway for testing ec2_transit_gateway_attachment' + name: '{{ tgw_name }}' + - description: 'Second Transit Gateway for testing ec2_transit_gateway_attachment' + name: '{{ tgw_name_2 }}' + register: create_tgws + +- name: 'Create VPCs to attach to TGW' + ec2_vpc_net: + cidr_block: '{{ item.cidr }}' + name: '{{ item.name }}' + ipv6_cidr: True + loop: + - cidr: '{{ vpc_cidr_a }}' + name: '{{ vpc_name_a }}' + - cidr: '{{ vpc_cidr_b }}' + name: '{{ vpc_name_b }}' + register: create_vpcs + +- set_fact: + tgw_id: '{{ create_tgws.results[0].transit_gateway.transit_gateway_id }}' + tgw_id_2: '{{ create_tgws.results[1].transit_gateway.transit_gateway_id }}' + vpc_id_a: '{{ vpc_a.id }}' + vpc_id_b: '{{ vpc_b.id }}' + vpc_owner_a: '{{ vpc_a.owner_id }}' + vpc_owner_b: '{{ vpc_b.owner_id }}' + subnet_ipv6_a_1: '{{ vpc_ipv6_a | replace("0::/56","0::/64") }}' + subnet_ipv6_a_2: '{{ vpc_ipv6_a | replace("0::/56","1::/64") }}' + subnet_ipv6_a_3: '{{ vpc_ipv6_a | replace("0::/56","2::/64") }}' + subnet_ipv6_a_1a: '{{ vpc_ipv6_a | replace("0::/56","3::/64") }}' + subnet_ipv6_b_1: '{{ vpc_ipv6_b | replace("0::/56","0::/64") }}' + subnet_ipv6_b_2: '{{ vpc_ipv6_b | replace("0::/56","1::/64") }}' + vars: + vpc_a: '{{ create_vpcs.results[0].vpc }}' + vpc_b: '{{ create_vpcs.results[1].vpc }}' + vpc_ipv6_a: '{{ vpc_a.ipv6_cidr_block_association_set[0].ipv6_cidr_block }}' + vpc_ipv6_b: '{{ vpc_b.ipv6_cidr_block_association_set[0].ipv6_cidr_block }}' + +- name: 'Create subnets' + ec2_vpc_subnet: + az: '{{ item.az }}' + cidr: '{{ item.cidr }}' + ipv6_cidr: '{{ item.ipv6_cidr }}' + tags: + Name: '{{ item.name }}' + vpc_id: '{{ item.vpc_id }}' + loop: + - az: '{{ subnet_az_a_1 }}' + cidr: '{{ subnet_cidr_a_1 }}' + ipv6_cidr: '{{ subnet_ipv6_a_1 }}' + vpc_id: '{{ vpc_id_a }}' + name: '{{ subnet_name_a_1 }}' + - az: '{{ subnet_az_a_2 }}' + cidr: '{{ subnet_cidr_a_2 }}' + ipv6_cidr: '{{ subnet_ipv6_a_2 }}' + vpc_id: '{{ vpc_id_a }}' + name: '{{ subnet_name_a_2 }}' + - az: '{{ subnet_az_a_3 }}' + cidr: '{{ subnet_cidr_a_3 }}' + ipv6_cidr: '{{ subnet_ipv6_a_3 }}' + vpc_id: '{{ vpc_id_a }}' + name: '{{ subnet_name_a_3 }}' + - az: '{{ subnet_az_b_1 }}' + cidr: '{{ subnet_cidr_b_1 }}' + ipv6_cidr: '{{ subnet_ipv6_b_1 }}' + vpc_id: '{{ vpc_id_b }}' + name: '{{ subnet_name_b_1 }}' + - az: '{{ subnet_az_b_2 }}' + cidr: '{{ subnet_cidr_b_2 }}' + ipv6_cidr: '{{ subnet_ipv6_b_2 }}' + vpc_id: '{{ vpc_id_b }}' + name: '{{ subnet_name_b_2 }}' + - az: '{{ subnet_az_a_1a }}' + cidr: '{{ subnet_cidr_a_1a }}' + ipv6_cidr: '{{ subnet_ipv6_a_1a }}' + vpc_id: '{{ vpc_id_a }}' + name: '{{ subnet_name_a_1a }}' + register: create_subnets + +- set_fact: + subnet_id_a_1: '{{ create_subnets.results[0].subnet.id }}' + subnet_id_a_2: '{{ create_subnets.results[1].subnet.id }}' + subnet_id_a_3: '{{ create_subnets.results[2].subnet.id }}' + subnet_id_b_1: '{{ create_subnets.results[3].subnet.id }}' + subnet_id_b_2: '{{ create_subnets.results[4].subnet.id }}' + subnet_id_a_1a: '{{ create_subnets.results[5].subnet.id }}' diff --git a/tests/integration/targets/ec2_transit_gateway_vpc_attachment/tasks/simple.yml b/tests/integration/targets/ec2_transit_gateway_vpc_attachment/tasks/simple.yml new file mode 100644 index 00000000000..0085813a322 --- /dev/null +++ b/tests/integration/targets/ec2_transit_gateway_vpc_attachment/tasks/simple.yml @@ -0,0 +1,3611 @@ +--- +# ============================================================================= +# Creation +- block: + - name: '(CHECK_MODE) Create an attachment - minimal parameters' + check_mode: True + ec2_transit_gateway_vpc_attachment: + transit_gateway: '{{ tgw_id }}' + subnets: + - '{{ subnet_id_a_1 }}' + register: simple_attach + + - assert: + that: + - simple_attach is changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: 'Create an attachment - minimal parameters' + ec2_transit_gateway_vpc_attachment: + transit_gateway: '{{ tgw_id }}' + subnets: + - '{{ subnet_id_a_1 }}' + register: simple_attach + + - assert: + that: + - simple_attach is changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.transit_gateway_attachment_id.startswith('tgw-attach-') + - attachment.state == 'available' + - attachment.tags | length == 0 + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: Save Attachment ID + set_fact: + simple_attachment_id: '{{ simple_attach.attachments[0].transit_gateway_attachment_id }}' + + - name: '(CHECK_MODE) Create an attachment - minimal parameters -- IDEMPOTENCY' + check_mode: True + ec2_transit_gateway_vpc_attachment: + transit_gateway: '{{ tgw_id }}' + subnets: + - '{{ subnet_id_a_1 }}' + register: simple_attach + + - assert: + that: + - simple_attach is not changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 0 + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: 'Create an attachment - minimal parameters -- IDEMPOTENCY' + ec2_transit_gateway_vpc_attachment: + transit_gateway: '{{ tgw_id }}' + subnets: + - '{{ subnet_id_a_1 }}' + register: simple_attach + + - assert: + that: + - simple_attach is not changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 0 + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + +# ===== + + - name: '(CHECK_MODE) By Id - minimal parameters -- IDEMPOTENCY' + check_mode: True + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + subnets: + - '{{ subnet_id_a_1 }}' + register: simple_attach + + - assert: + that: + - simple_attach is not changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 0 + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: 'By Id - minimal parameters -- IDEMPOTENCY' + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + subnets: + - '{{ subnet_id_a_1 }}' + register: simple_attach + + - assert: + that: + - simple_attach is not changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 0 + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + +# ============================================================================= +# Set a name + + - name: '(CHECK_MODE) Set name' + check_mode: True + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + name: '{{ attachment_name }}' + register: simple_attach + + - assert: + that: + - simple_attach is changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 1 + - '"Name" in attachment.tags' + - attachment.tags.Name == attachment_name + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: 'Set name' + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + name: '{{ attachment_name }}' + register: simple_attach + + - assert: + that: + - simple_attach is changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 1 + - '"Name" in attachment.tags' + - attachment.tags.Name == attachment_name + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: '(CHECK_MODE) Set name -- IDEMPOTENCY' + check_mode: True + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + name: '{{ attachment_name }}' + register: simple_attach + + - assert: + that: + - simple_attach is not changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 1 + - '"Name" in attachment.tags' + - attachment.tags.Name == attachment_name + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: 'Set name -- IDEMPOTENCY' + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + name: '{{ attachment_name }}' + register: simple_attach + + - assert: + that: + - simple_attach is not changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 1 + - '"Name" in attachment.tags' + - attachment.tags.Name == attachment_name + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + +# ===== + + - name: '(CHECK_MODE) By Name - minimal parameters -- IDEMPOTENCY' + check_mode: True + ec2_transit_gateway_vpc_attachment: + name: '{{ attachment_name }}' + subnets: + - '{{ subnet_id_a_1 }}' + register: simple_attach + + - assert: + that: + - simple_attach is not changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 1 + - '"Name" in attachment.tags' + - attachment.tags.Name == attachment_name + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: 'By Name - minimal parameters -- IDEMPOTENCY' + ec2_transit_gateway_vpc_attachment: + name: '{{ attachment_name }}' + subnets: + - '{{ subnet_id_a_1 }}' + register: simple_attach + + - assert: + that: + - simple_attach is not changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 1 + - '"Name" in attachment.tags' + - attachment.tags.Name == attachment_name + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + +# ============================================================================= +# Describe + + - name: 'Describe all attachments' + ec2_transit_gateway_vpc_attachment_info: + register: info + + - assert: + that: + - info is not changed + - '"attachments" in info' + - info.attachments | length >= 2 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length >= 1 + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - '"Name" in attachment.tags' + vars: + attachment: '{{ info.attachments[0] }}' + + - name: 'Describe attachments on a specific VPC' + ec2_transit_gateway_vpc_attachment_info: + filters: + transit-gateway-id: '{{ tgw_id }}' + register: info + + - assert: + that: + - info is not changed + - '"attachments" in info' + - info.attachments | length == 2 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length >= 1 + - attachment.transit_gateway_id == tgw_id + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - '"Name" in attachment.tags' + vars: + attachment: '{{ info.attachments[0] }}' + + - name: 'Describe attachment with a specific name' + ec2_transit_gateway_vpc_attachment_info: + name: '{{ attachment_name }}' + register: info + + - assert: + that: + - info is not changed + - '"attachments" in info' + - info.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 1 + - '"Name" in attachment.tags' + - attachment.tags.Name == attachment_name + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ info.attachments[0] }}' + + - name: 'Describe attachment by ID' + ec2_transit_gateway_vpc_attachment_info: + id: '{{ simple_attachment_id }}' + register: info + + - assert: + that: + - info is not changed + - '"attachments" in info' + - info.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 1 + - '"Name" in attachment.tags' + - attachment.tags.Name == attachment_name + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ info.attachments[0] }}' + +# ============================================================================= +# Tag attachment + + - name: '(CHECK_MODE) Set tags' + check_mode: True + ec2_transit_gateway_vpc_attachment: + name: '{{ attachment_name }}' + tags: + CamelCase: CamelCaseValue + pascalCase: pascalCaseValue + snake_case: snake_case_value + "Tag with Space": value with space + register: simple_attach + + - assert: + that: + - simple_attach is changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 5 + - '"Name" in attachment.tags' + - '"CamelCase" in attachment.tags' + - '"pascalCase" in attachment.tags' + - '"snake_case" in attachment.tags' + - '"Tag with Space" in attachment.tags' + - attachment.tags.Name == attachment_name + - attachment.tags.CamelCase == 'CamelCaseValue' + - attachment.tags.pascalCase == 'pascalCaseValue' + - attachment.tags.snake_case == 'snake_case_value' + - attachment.tags['Tag with Space'] == 'value with space' + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: 'Set tags' + ec2_transit_gateway_vpc_attachment: + name: '{{ attachment_name }}' + tags: + CamelCase: CamelCaseValue + pascalCase: pascalCaseValue + snake_case: snake_case_value + "Tag with Space": value with space + register: simple_attach + + - assert: + that: + - simple_attach is changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 5 + - '"Name" in attachment.tags' + - '"CamelCase" in attachment.tags' + - '"pascalCase" in attachment.tags' + - '"snake_case" in attachment.tags' + - '"Tag with Space" in attachment.tags' + - attachment.tags.Name == attachment_name + - attachment.tags.CamelCase == 'CamelCaseValue' + - attachment.tags.pascalCase == 'pascalCaseValue' + - attachment.tags.snake_case == 'snake_case_value' + - attachment.tags['Tag with Space'] == 'value with space' + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: '(CHECK_MODE) Set tags -- IDEMPOTENCY' + check_mode: True + ec2_transit_gateway_vpc_attachment: + name: '{{ attachment_name }}' + tags: + CamelCase: CamelCaseValue + pascalCase: pascalCaseValue + snake_case: snake_case_value + "Tag with Space": value with space + register: simple_attach + + - assert: + that: + - simple_attach is not changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 5 + - '"Name" in attachment.tags' + - '"CamelCase" in attachment.tags' + - '"pascalCase" in attachment.tags' + - '"snake_case" in attachment.tags' + - '"Tag with Space" in attachment.tags' + - attachment.tags.Name == attachment_name + - attachment.tags.CamelCase == 'CamelCaseValue' + - attachment.tags.pascalCase == 'pascalCaseValue' + - attachment.tags.snake_case == 'snake_case_value' + - attachment.tags['Tag with Space'] == 'value with space' + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: 'Set tags -- IDEMPOTENCY' + ec2_transit_gateway_vpc_attachment: + name: '{{ attachment_name }}' + tags: + CamelCase: CamelCaseValue + pascalCase: pascalCaseValue + snake_case: snake_case_value + "Tag with Space": value with space + register: simple_attach + + - assert: + that: + - simple_attach is not changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 5 + - '"Name" in attachment.tags' + - '"CamelCase" in attachment.tags' + - '"pascalCase" in attachment.tags' + - '"snake_case" in attachment.tags' + - '"Tag with Space" in attachment.tags' + - attachment.tags.Name == attachment_name + - attachment.tags.CamelCase == 'CamelCaseValue' + - attachment.tags.pascalCase == 'pascalCaseValue' + - attachment.tags.snake_case == 'snake_case_value' + - attachment.tags['Tag with Space'] == 'value with space' + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: 'Describe attachment with tags set' + ec2_transit_gateway_vpc_attachment_info: + id: '{{ simple_attachment_id }}' + register: info + + - assert: + that: + - info is not changed + - '"attachments" in info' + - info.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 5 + - '"Name" in attachment.tags' + - '"CamelCase" in attachment.tags' + - '"pascalCase" in attachment.tags' + - '"snake_case" in attachment.tags' + - '"Tag with Space" in attachment.tags' + - attachment.tags.Name == attachment_name + - attachment.tags.CamelCase == 'CamelCaseValue' + - attachment.tags.pascalCase == 'pascalCaseValue' + - attachment.tags.snake_case == 'snake_case_value' + - attachment.tags['Tag with Space'] == 'value with space' + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ info.attachments[0] }}' + +# ===== + + - name: '(CHECK_MODE) No change to tags with name set -- IDEMPOTENCY' + check_mode: True + ec2_transit_gateway_vpc_attachment: + name: '{{ attachment_name }}' + register: simple_attach + + - assert: + that: + - simple_attach is not changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 5 + - '"Name" in attachment.tags' + - '"CamelCase" in attachment.tags' + - '"pascalCase" in attachment.tags' + - '"snake_case" in attachment.tags' + - '"Tag with Space" in attachment.tags' + - attachment.tags.Name == attachment_name + - attachment.tags.CamelCase == 'CamelCaseValue' + - attachment.tags.pascalCase == 'pascalCaseValue' + - attachment.tags.snake_case == 'snake_case_value' + - attachment.tags['Tag with Space'] == 'value with space' + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: 'No change to tags with name set -- IDEMPOTENCY' + ec2_transit_gateway_vpc_attachment: + name: '{{ attachment_name }}' + register: simple_attach + + - assert: + that: + - simple_attach is not changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 5 + - '"Name" in attachment.tags' + - '"CamelCase" in attachment.tags' + - '"pascalCase" in attachment.tags' + - '"snake_case" in attachment.tags' + - '"Tag with Space" in attachment.tags' + - attachment.tags.Name == attachment_name + - attachment.tags.CamelCase == 'CamelCaseValue' + - attachment.tags.pascalCase == 'pascalCaseValue' + - attachment.tags.snake_case == 'snake_case_value' + - attachment.tags['Tag with Space'] == 'value with space' + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + +# ===== + + - name: '(CHECK_MODE) Update tags' + check_mode: True + ec2_transit_gateway_vpc_attachment: + name: '{{ attachment_name }}' + purge_tags: False + tags: + snake_case: snake_case_value 2 + "Tag with Space": value with space 2 + register: simple_attach + + - assert: + that: + - simple_attach is changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 5 + - '"Name" in attachment.tags' + - '"CamelCase" in attachment.tags' + - '"pascalCase" in attachment.tags' + - '"snake_case" in attachment.tags' + - '"Tag with Space" in attachment.tags' + - attachment.tags.Name == attachment_name + - attachment.tags.CamelCase == 'CamelCaseValue' + - attachment.tags.pascalCase == 'pascalCaseValue' + - attachment.tags.snake_case == 'snake_case_value 2' + - attachment.tags['Tag with Space'] == 'value with space 2' + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: 'Update tags' + ec2_transit_gateway_vpc_attachment: + name: '{{ attachment_name }}' + purge_tags: False + tags: + snake_case: snake_case_value 2 + "Tag with Space": value with space 2 + register: simple_attach + + - assert: + that: + - simple_attach is changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 5 + - '"Name" in attachment.tags' + - '"CamelCase" in attachment.tags' + - '"pascalCase" in attachment.tags' + - '"snake_case" in attachment.tags' + - '"Tag with Space" in attachment.tags' + - attachment.tags.Name == attachment_name + - attachment.tags.CamelCase == 'CamelCaseValue' + - attachment.tags.pascalCase == 'pascalCaseValue' + - attachment.tags.snake_case == 'snake_case_value 2' + - attachment.tags['Tag with Space'] == 'value with space 2' + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: '(CHECK_MODE) Update tags -- IDEMPOTENCY' + check_mode: True + ec2_transit_gateway_vpc_attachment: + name: '{{ attachment_name }}' + purge_tags: False + tags: + snake_case: snake_case_value 2 + "Tag with Space": value with space 2 + register: simple_attach + + - assert: + that: + - simple_attach is not changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 5 + - '"Name" in attachment.tags' + - '"CamelCase" in attachment.tags' + - '"pascalCase" in attachment.tags' + - '"snake_case" in attachment.tags' + - '"Tag with Space" in attachment.tags' + - attachment.tags.Name == attachment_name + - attachment.tags.CamelCase == 'CamelCaseValue' + - attachment.tags.pascalCase == 'pascalCaseValue' + - attachment.tags.snake_case == 'snake_case_value 2' + - attachment.tags['Tag with Space'] == 'value with space 2' + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: 'Update tags -- IDEMPOTENCY' + ec2_transit_gateway_vpc_attachment: + name: '{{ attachment_name }}' + purge_tags: False + tags: + snake_case: snake_case_value 2 + "Tag with Space": value with space 2 + register: simple_attach + + - assert: + that: + - simple_attach is not changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 5 + - '"Name" in attachment.tags' + - '"CamelCase" in attachment.tags' + - '"pascalCase" in attachment.tags' + - '"snake_case" in attachment.tags' + - '"Tag with Space" in attachment.tags' + - attachment.tags.Name == attachment_name + - attachment.tags.CamelCase == 'CamelCaseValue' + - attachment.tags.pascalCase == 'pascalCaseValue' + - attachment.tags.snake_case == 'snake_case_value 2' + - attachment.tags['Tag with Space'] == 'value with space 2' + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + +# ===== + + - name: '(CHECK_MODE) Remove tags' + check_mode: True + ec2_transit_gateway_vpc_attachment: + name: '{{ attachment_name }}' + tags: + CamelCase: CamelCaseValue + pascalCase: pascalCaseValue + register: simple_attach + + - assert: + that: + - simple_attach is changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 3 + - '"Name" in attachment.tags' + - '"CamelCase" in attachment.tags' + - '"pascalCase" in attachment.tags' + - attachment.tags.Name == attachment_name + - attachment.tags.CamelCase == 'CamelCaseValue' + - attachment.tags.pascalCase == 'pascalCaseValue' + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: 'Remove tags' + ec2_transit_gateway_vpc_attachment: + name: '{{ attachment_name }}' + tags: + CamelCase: CamelCaseValue + pascalCase: pascalCaseValue + register: simple_attach + + - assert: + that: + - simple_attach is changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 3 + - '"Name" in attachment.tags' + - '"CamelCase" in attachment.tags' + - '"pascalCase" in attachment.tags' + - attachment.tags.Name == attachment_name + - attachment.tags.CamelCase == 'CamelCaseValue' + - attachment.tags.pascalCase == 'pascalCaseValue' + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: '(CHECK_MODE) Remove tags -- IDEMPOTENCY' + check_mode: True + ec2_transit_gateway_vpc_attachment: + name: '{{ attachment_name }}' + tags: + CamelCase: CamelCaseValue + pascalCase: pascalCaseValue + register: simple_attach + + - assert: + that: + - simple_attach is not changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 3 + - '"Name" in attachment.tags' + - '"CamelCase" in attachment.tags' + - '"pascalCase" in attachment.tags' + - attachment.tags.Name == attachment_name + - attachment.tags.CamelCase == 'CamelCaseValue' + - attachment.tags.pascalCase == 'pascalCaseValue' + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: 'Remove tags -- IDEMPOTENCY' + ec2_transit_gateway_vpc_attachment: + name: '{{ attachment_name }}' + tags: + CamelCase: CamelCaseValue + pascalCase: pascalCaseValue + register: simple_attach + + - assert: + that: + - simple_attach is not changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 3 + - '"Name" in attachment.tags' + - '"CamelCase" in attachment.tags' + - '"pascalCase" in attachment.tags' + - attachment.tags.Name == attachment_name + - attachment.tags.CamelCase == 'CamelCaseValue' + - attachment.tags.pascalCase == 'pascalCaseValue' + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + +# ===== + + - name: '(CHECK_MODE) Add tags with no purge' + check_mode: True + ec2_transit_gateway_vpc_attachment: + name: '{{ attachment_name }}' + purge_tags: False + tags: + AnotherTag: Another Value + register: simple_attach + + - assert: + that: + - simple_attach is changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 4 + - '"Name" in attachment.tags' + - '"CamelCase" in attachment.tags' + - '"pascalCase" in attachment.tags' + - '"AnotherTag" in attachment.tags' + - attachment.tags.Name == attachment_name + - attachment.tags.CamelCase == 'CamelCaseValue' + - attachment.tags.pascalCase == 'pascalCaseValue' + - attachment.tags.AnotherTag == 'Another Value' + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: 'Add tags with no purge' + ec2_transit_gateway_vpc_attachment: + name: '{{ attachment_name }}' + purge_tags: False + tags: + AnotherTag: Another Value + register: simple_attach + + - assert: + that: + - simple_attach is changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 4 + - '"Name" in attachment.tags' + - '"CamelCase" in attachment.tags' + - '"pascalCase" in attachment.tags' + - '"AnotherTag" in attachment.tags' + - attachment.tags.Name == attachment_name + - attachment.tags.CamelCase == 'CamelCaseValue' + - attachment.tags.pascalCase == 'pascalCaseValue' + - attachment.tags.AnotherTag == 'Another Value' + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: '(CHECK_MODE) Add tags with no purge -- IDEMPOTENCY' + check_mode: True + ec2_transit_gateway_vpc_attachment: + name: '{{ attachment_name }}' + purge_tags: False + tags: + AnotherTag: Another Value + register: simple_attach + + - assert: + that: + - simple_attach is not changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 4 + - '"Name" in attachment.tags' + - '"CamelCase" in attachment.tags' + - '"pascalCase" in attachment.tags' + - '"AnotherTag" in attachment.tags' + - attachment.tags.Name == attachment_name + - attachment.tags.CamelCase == 'CamelCaseValue' + - attachment.tags.pascalCase == 'pascalCaseValue' + - attachment.tags.AnotherTag == 'Another Value' + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: 'Add tags with no purge -- IDEMPOTENCY' + ec2_transit_gateway_vpc_attachment: + name: '{{ attachment_name }}' + purge_tags: False + tags: + AnotherTag: Another Value + register: simple_attach + + - assert: + that: + - simple_attach is not changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 4 + - '"Name" in attachment.tags' + - '"CamelCase" in attachment.tags' + - '"pascalCase" in attachment.tags' + - '"AnotherTag" in attachment.tags' + - attachment.tags.Name == attachment_name + - attachment.tags.CamelCase == 'CamelCaseValue' + - attachment.tags.pascalCase == 'pascalCaseValue' + - attachment.tags.AnotherTag == 'Another Value' + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + +# ===== + + - name: '(CHECK_MODE) Remove all tags with name set' + check_mode: True + ec2_transit_gateway_vpc_attachment: + name: '{{ attachment_name }}' + tags: {} + register: simple_attach + + - assert: + that: + - simple_attach is changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 1 + - '"Name" in attachment.tags' + - attachment.tags.Name == attachment_name + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: 'Remove all tags with name set' + ec2_transit_gateway_vpc_attachment: + name: '{{ attachment_name }}' + tags: {} + register: simple_attach + + - assert: + that: + - simple_attach is changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 1 + - '"Name" in attachment.tags' + - attachment.tags.Name == attachment_name + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: '(CHECK_MODE) Remove all tags with name set -- IDEMPOTENCY' + check_mode: True + ec2_transit_gateway_vpc_attachment: + name: '{{ attachment_name }}' + tags: {} + register: simple_attach + + - assert: + that: + - simple_attach is not changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 1 + - '"Name" in attachment.tags' + - attachment.tags.Name == attachment_name + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: 'Remove all tags with name set -- IDEMPOTENCY' + ec2_transit_gateway_vpc_attachment: + name: '{{ attachment_name }}' + tags: {} + register: simple_attach + + - assert: + that: + - simple_attach is not changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 1 + - '"Name" in attachment.tags' + - attachment.tags.Name == attachment_name + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + +# ===== + + - name: '(CHECK_MODE) Remove all tags including name' + check_mode: True + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + tags: {} + register: simple_attach + + - assert: + that: + - simple_attach is changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 0 + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: 'Remove all tags including name' + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + tags: {} + register: simple_attach + + - assert: + that: + - simple_attach is changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 0 + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: '(CHECK_MODE) Remove all tags including name -- IDEMPOTENCY' + check_mode: True + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + tags: {} + register: simple_attach + + - assert: + that: + - simple_attach is not changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 0 + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: 'Remove all tags including name -- IDEMPOTENCY' + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + tags: {} + register: simple_attach + + - assert: + that: + - simple_attach is not changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 0 + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + +# ============================================================================= +# Options + + - name: '(CHECK_MODE) Set IPv6 support' + check_mode: True + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + ipv6_support: True + register: simple_attach + + - assert: + that: + - simple_attach is changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'enable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 0 + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: 'Set IPv6 support' + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + ipv6_support: True + register: simple_attach + + - assert: + that: + - simple_attach is changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'enable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 0 + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: '(CHECK_MODE) Set IPv6 support -- IDEMPOTENCY' + check_mode: True + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + ipv6_support: True + register: simple_attach + + - assert: + that: + - simple_attach is not changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'enable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 0 + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: 'Set IPv6 support -- IDEMPOTENCY' + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + ipv6_support: True + register: simple_attach + + - assert: + that: + - simple_attach is not changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'enable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 0 + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + +# ===== + + - name: '(CHECK_MODE) Set DNS support' + check_mode: True + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + dns_support: False + register: simple_attach + + - assert: + that: + - simple_attach is changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'disable' + - attachment.options.ipv6_support == 'enable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 0 + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: 'Set DNS support' + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + dns_support: False + register: simple_attach + + - assert: + that: + - simple_attach is changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'disable' + - attachment.options.ipv6_support == 'enable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 0 + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: '(CHECK_MODE) Set DNS support -- IDEMPOTENCY' + check_mode: True + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + dns_support: False + register: simple_attach + + - assert: + that: + - simple_attach is not changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'disable' + - attachment.options.ipv6_support == 'enable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 0 + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: 'Set DNS support -- IDEMPOTENCY' + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + dns_support: False + register: simple_attach + + - assert: + that: + - simple_attach is not changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'disable' + - attachment.options.ipv6_support == 'enable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 0 + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + +# ===== + + - name: '(CHECK_MODE) Set Appliance Mode support' + check_mode: True + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + appliance_mode_support: True + register: simple_attach + + - assert: + that: + - simple_attach is changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'enable' + - attachment.options.dns_support == 'disable' + - attachment.options.ipv6_support == 'enable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 0 + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: 'Set Appliance Mode support' + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + appliance_mode_support: True + register: simple_attach + + - assert: + that: + - simple_attach is changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'enable' + - attachment.options.dns_support == 'disable' + - attachment.options.ipv6_support == 'enable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 0 + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: '(CHECK_MODE) Set Appliance Mode support -- IDEMPOTENCY' + check_mode: True + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + appliance_mode_support: True + register: simple_attach + + - assert: + that: + - simple_attach is not changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'enable' + - attachment.options.dns_support == 'disable' + - attachment.options.ipv6_support == 'enable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 0 + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: 'Set Appliance Mode support -- IDEMPOTENCY' + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + appliance_mode_support: True + register: simple_attach + + - assert: + that: + - simple_attach is not changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'enable' + - attachment.options.dns_support == 'disable' + - attachment.options.ipv6_support == 'enable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 0 + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + +# ===== + + - name: '(CHECK_MODE) Update IPv6 support' + check_mode: True + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + ipv6_support: False + register: simple_attach + + - assert: + that: + - simple_attach is changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'enable' + - attachment.options.dns_support == 'disable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 0 + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: 'Update IPv6 support' + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + ipv6_support: False + register: simple_attach + + - assert: + that: + - simple_attach is changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'enable' + - attachment.options.dns_support == 'disable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 0 + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: '(CHECK_MODE) Update IPv6 support -- IDEMPOTENCY' + check_mode: True + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + ipv6_support: False + register: simple_attach + + - assert: + that: + - simple_attach is not changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'enable' + - attachment.options.dns_support == 'disable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 0 + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: 'Update IPv6 support -- IDEMPOTENCY' + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + ipv6_support: False + register: simple_attach + + - assert: + that: + - simple_attach is not changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'enable' + - attachment.options.dns_support == 'disable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 0 + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + +# ===== + + - name: '(CHECK_MODE) Update DNS support' + check_mode: True + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + dns_support: True + register: simple_attach + + - assert: + that: + - simple_attach is changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'enable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 0 + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: 'Update DNS support' + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + dns_support: True + register: simple_attach + + - assert: + that: + - simple_attach is changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'enable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 0 + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: '(CHECK_MODE) Update DNS support -- IDEMPOTENCY' + check_mode: True + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + dns_support: True + register: simple_attach + + - assert: + that: + - simple_attach is not changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'enable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 0 + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: 'Update DNS support -- IDEMPOTENCY' + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + dns_support: True + register: simple_attach + + - assert: + that: + - simple_attach is not changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'enable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 0 + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + +# ===== + + - name: '(CHECK_MODE) Update Appliance Mode support' + check_mode: True + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + appliance_mode_support: False + register: simple_attach + + - assert: + that: + - simple_attach is changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 0 + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: 'Update Appliance Mode support' + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + appliance_mode_support: False + register: simple_attach + + - assert: + that: + - simple_attach is changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 0 + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: '(CHECK_MODE) Update Appliance Mode support -- IDEMPOTENCY' + check_mode: True + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + appliance_mode_support: False + register: simple_attach + + - assert: + that: + - simple_attach is not changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 0 + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: 'Update Appliance Mode support -- IDEMPOTENCY' + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + appliance_mode_support: False + register: simple_attach + + - assert: + that: + - simple_attach is not changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 1 + - subnet_id_a_1 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 0 + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + +# ============================================================================= +# Subnet Management + + - name: '(CHECK_MODE) Try to add subnet from a different VPC - no purge' + check_mode: True + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + subnets: + - '{{ subnet_id_b_2 }}' + purge_subnets: False + register: simple_attach + ignore_errors: True + + - assert: + that: + - simple_attach is failed + + - name: 'Try to add subnet from a different VPC - no purge' + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + subnets: + - '{{ subnet_id_b_2 }}' + purge_subnets: False + register: simple_attach + ignore_errors: True + + - assert: + that: + - simple_attach is failed + +# ===== + + - name: '(CHECK_MODE) Try to add subnet from a different VPC - with purge' + check_mode: True + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + subnets: + - '{{ subnet_id_a_1 }}' + - '{{ subnet_id_b_2 }}' + purge_subnets: True + register: simple_attach + ignore_errors: True + + - assert: + that: + - simple_attach is failed + + - name: 'Try to add subnet from a different VPC - with purge' + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + subnets: + - '{{ subnet_id_a_1 }}' + - '{{ subnet_id_b_2 }}' + purge_subnets: True + register: simple_attach + ignore_errors: True + + - assert: + that: + - simple_attach is failed + +# ===== + + - name: '(CHECK_MODE) Try to add subnet in the same AZ - no purge' + check_mode: True + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + subnets: + - '{{ subnet_id_b_1a }}' + purge_subnets: False + register: simple_attach + ignore_errors: True + + - assert: + that: + - simple_attach is failed + + - name: 'Try to add subnet in the same AZ - no purge' + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + subnets: + - '{{ subnet_id_a_1a }}' + purge_subnets: False + register: simple_attach + ignore_errors: True + + - assert: + that: + - simple_attach is failed + +# ===== + + - name: '(CHECK_MODE) Try to add subnet in the same AZ - with purge' + check_mode: True + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + subnets: + - '{{ subnet_id_a_1 }}' + - '{{ subnet_id_a_1a }}' + purge_subnets: True + register: simple_attach + ignore_errors: True + + - assert: + that: + - simple_attach is failed + + - name: 'Try to add subnet in the same AZ - with purge' + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + subnets: + - '{{ subnet_id_a_1 }}' + - '{{ subnet_id_a_1a }}' + purge_subnets: True + register: simple_attach + ignore_errors: True + + - assert: + that: + - simple_attach is failed + +# ===== + + - name: '(CHECK_MODE) Add subnet - without purge' + check_mode: True + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + subnets: + - '{{ subnet_id_a_2 }}' + purge_subnets: False + register: simple_attach + + - assert: + that: + - simple_attach is changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 2 + - subnet_id_a_1 in attachment.subnet_ids + - subnet_id_a_2 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 0 + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: 'Add subnet - without purge' + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + subnets: + - '{{ subnet_id_a_2 }}' + purge_subnets: False + register: simple_attach + + - assert: + that: + - simple_attach is changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 2 + - subnet_id_a_1 in attachment.subnet_ids + - subnet_id_a_2 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 0 + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: '(CHECK_MODE) Add subnet - without purge -- IDEMPOTENCY' + check_mode: True + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + subnets: + - '{{ subnet_id_a_2 }}' + purge_subnets: False + register: simple_attach + + - assert: + that: + - simple_attach is not changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 2 + - subnet_id_a_1 in attachment.subnet_ids + - subnet_id_a_2 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 0 + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: 'Add subnet - without purge -- IDEMPOTENCY' + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + subnets: + - '{{ subnet_id_a_2 }}' + purge_subnets: False + register: simple_attach + + - assert: + that: + - simple_attach is not changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 2 + - subnet_id_a_1 in attachment.subnet_ids + - subnet_id_a_2 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 0 + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + +# ===== + + - name: '(CHECK_MODE) Add subnet - with purge' + check_mode: True + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + subnets: + - '{{ subnet_id_a_1 }}' + - '{{ subnet_id_a_2 }}' + - '{{ subnet_id_a_3 }}' + purge_subnets: True + register: simple_attach + + - assert: + that: + - simple_attach is changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 3 + - subnet_id_a_1 in attachment.subnet_ids + - subnet_id_a_2 in attachment.subnet_ids + - subnet_id_a_3 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 0 + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: 'Add subnet - with purge' + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + subnets: + - '{{ subnet_id_a_1 }}' + - '{{ subnet_id_a_2 }}' + - '{{ subnet_id_a_3 }}' + purge_subnets: True + register: simple_attach + + - assert: + that: + - simple_attach is changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 3 + - subnet_id_a_1 in attachment.subnet_ids + - subnet_id_a_2 in attachment.subnet_ids + - subnet_id_a_3 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 0 + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: '(CHECK_MODE) Add subnet - with purge -- IDEMPOTENCY' + check_mode: True + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + subnets: + - '{{ subnet_id_a_1 }}' + - '{{ subnet_id_a_2 }}' + - '{{ subnet_id_a_3 }}' + purge_subnets: True + register: simple_attach + + - assert: + that: + - simple_attach is not changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 3 + - subnet_id_a_1 in attachment.subnet_ids + - subnet_id_a_2 in attachment.subnet_ids + - subnet_id_a_3 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 0 + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: 'Add subnet - with purge -- IDEMPOTENCY' + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + subnets: + - '{{ subnet_id_a_1 }}' + - '{{ subnet_id_a_2 }}' + - '{{ subnet_id_a_3 }}' + purge_subnets: True + register: simple_attach + + - assert: + that: + - simple_attach is not changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 3 + - subnet_id_a_1 in attachment.subnet_ids + - subnet_id_a_2 in attachment.subnet_ids + - subnet_id_a_3 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 0 + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + +# ===== + + - name: '(CHECK_MODE) Remove subnet' + check_mode: True + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + subnets: + - '{{ subnet_id_a_2 }}' + - '{{ subnet_id_a_3 }}' + purge_subnets: True + register: simple_attach + + - assert: + that: + - simple_attach is changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 2 + - subnet_id_a_2 in attachment.subnet_ids + - subnet_id_a_3 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 0 + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: 'Remove subnet' + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + subnets: + - '{{ subnet_id_a_2 }}' + - '{{ subnet_id_a_3 }}' + purge_subnets: True + register: simple_attach + + - assert: + that: + - simple_attach is changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 2 + - subnet_id_a_2 in attachment.subnet_ids + - subnet_id_a_3 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 0 + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: '(CHECK_MODE) Remove subnet -- IDEMPOTENCY' + check_mode: True + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + subnets: + - '{{ subnet_id_a_2 }}' + - '{{ subnet_id_a_3 }}' + purge_subnets: True + register: simple_attach + + - assert: + that: + - simple_attach is not changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 2 + - subnet_id_a_2 in attachment.subnet_ids + - subnet_id_a_3 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 0 + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: 'Remove subnet -- IDEMPOTENCY' + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + subnets: + - '{{ subnet_id_a_2 }}' + - '{{ subnet_id_a_3 }}' + purge_subnets: True + register: simple_attach + + - assert: + that: + - simple_attach is not changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 2 + - subnet_id_a_2 in attachment.subnet_ids + - subnet_id_a_3 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 0 + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + +# ===== + + - name: '(CHECK_MODE) Remove and add subnet' + check_mode: True + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + subnets: + - '{{ subnet_id_a_1 }}' + - '{{ subnet_id_a_2 }}' + purge_subnets: True + register: simple_attach + + - assert: + that: + - simple_attach is changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 2 + - subnet_id_a_1 in attachment.subnet_ids + - subnet_id_a_2 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 0 + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: 'Remove and add subnet' + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + subnets: + - '{{ subnet_id_a_1 }}' + - '{{ subnet_id_a_2 }}' + purge_subnets: True + register: simple_attach + + - assert: + that: + - simple_attach is changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 2 + - subnet_id_a_1 in attachment.subnet_ids + - subnet_id_a_2 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 0 + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: '(CHECK_MODE) Remove and add subnet -- IDEMPOTENCY' + check_mode: True + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + subnets: + - '{{ subnet_id_a_1 }}' + - '{{ subnet_id_a_2 }}' + purge_subnets: True + register: simple_attach + + - assert: + that: + - simple_attach is not changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 2 + - subnet_id_a_1 in attachment.subnet_ids + - subnet_id_a_2 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 0 + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + + - name: 'Remove and add subnet -- IDEMPOTENCY' + ec2_transit_gateway_vpc_attachment: + id: '{{ simple_attachment_id }}' + subnets: + - '{{ subnet_id_a_1 }}' + - '{{ subnet_id_a_2 }}' + purge_subnets: True + register: simple_attach + + - assert: + that: + - simple_attach is not changed + - '"attachments" in simple_attach' + - simple_attach.attachments | length == 1 + - '"subnet_ids" in attachment' + - '"transit_gateway_id" in attachment' + - '"vpc_id" in attachment' + - attachment.subnet_ids | length == 2 + - subnet_id_a_1 in attachment.subnet_ids + - subnet_id_a_2 in attachment.subnet_ids + - attachment.transit_gateway_id == tgw_id + - attachment.vpc_id == vpc_id_a + - '"creation_time" in attachment' + - '"options" in attachment' + - '"state" in attachment' + - '"tags" in attachment' + - '"transit_gateway_attachment_id" in attachment' + - '"vpc_owner_id" in attachment' + - '"appliance_mode_support" in attachment.options' + - '"dns_support" in attachment.options' + - '"ipv6_support" in attachment.options' + - attachment.options.appliance_mode_support == 'disable' + - attachment.options.dns_support == 'enable' + - attachment.options.ipv6_support == 'disable' + - attachment.state == 'available' + - attachment.transit_gateway_attachment_id == simple_attachment_id + - attachment.tags | length == 0 + - attachment.vpc_owner_id == vpc_owner_a + vars: + attachment: '{{ simple_attach.attachments[0] }}' + +# ============================================================================= +# Deletion + + - name: '(CHECK_MODE) Delete an attachment - minimal parameters' + check_mode: True + ec2_transit_gateway_vpc_attachment: + state: absent + id: '{{ simple_attachment_id }}' + wait: False + register: simple_attach + + - assert: + that: + - simple_attach is changed + + - name: 'Delete an attachment - minimal parameters' + ec2_transit_gateway_vpc_attachment: + state: absent + id: '{{ simple_attachment_id }}' + wait: False + register: simple_attach + + - assert: + that: + - simple_attach is changed + + - name: '(CHECK_MODE) Delete an attachment - minimal parameters -- IDEMPOTENCY' + check_mode: True + ec2_transit_gateway_vpc_attachment: + state: absent + id: '{{ simple_attachment_id }}' + wait: False + register: simple_attach + + - assert: + that: + - simple_attach is not changed + + - name: 'Delete an attachment - minimal parameters -- IDEMPOTENCY' + ec2_transit_gateway_vpc_attachment: + state: absent + id: '{{ simple_attachment_id }}' + wait: False + register: simple_attach + + - assert: + that: + - simple_attach is not changed + + always: + - name: 'Delete attachment' + ec2_transit_gateway_vpc_attachment: + state: absent + id: '{{ simple_attachment_id }}' + wait: False + ignore_errors: True