From aa3f28a9b80bdab9c4e8a037d848dbf5bdc9cfc3 Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Mon, 2 May 2022 12:25:38 +0200 Subject: [PATCH 01/25] 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 --- plugins/module_utils/transitgateway.py | 329 ++ .../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 +++++++++++++++++ 11 files changed, 5152 insertions(+) create mode 100644 plugins/module_utils/transitgateway.py 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/module_utils/transitgateway.py b/plugins/module_utils/transitgateway.py new file mode 100644 index 00000000000..e333be82e51 --- /dev/null +++ b/plugins/module_utils/transitgateway.py @@ -0,0 +1,329 @@ +# 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 + +from copy import deepcopy + +from ansible_collections.amazon.aws.plugins.module_utils.core import is_boto3_error_code +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ansible_dict_to_boto3_filter_list + +from ansible_collections.community.aws.plugins.module_utils.ec2 import BaseEc2Manager +from ansible_collections.community.aws.plugins.module_utils.ec2 import Boto3Mixin +from ansible_collections.community.aws.plugins.module_utils.ec2 import Ec2WaiterFactory + + +class TgwWaiterFactory(Ec2WaiterFactory): + @property + def _waiter_model_data(self): + data = super(TgwWaiterFactory, self)._waiter_model_data + # split the TGW waiters so we can keep them close to everything else. + tgw_data = dict( + tgw_attachment_available=dict( + operation='DescribeTransitGatewayAttachments', + delay=5, maxAttempts=120, + acceptors=[ + dict(state='success', matcher='pathAll', expected='available', argument='TransitGatewayAttachments[].State'), + ] + ), + tgw_attachment_deleted=dict( + operation='DescribeTransitGatewayAttachments', + delay=5, maxAttempts=120, + acceptors=[ + dict(state='retry', matcher='pathAll', expected='deleting', argument='TransitGatewayAttachments[].State'), + dict(state='success', matcher='pathAll', expected='deleted', argument='TransitGatewayAttachments[].State'), + dict(state='success', matcher='path', expected=True, argument='length(TransitGatewayAttachments[]) == `0`'), + dict(state='success', matcher='error', expected='InvalidRouteTableID.NotFound'), + ] + ), + ) + data.update(tgw_data) + return data + + +class TGWAttachmentBoto3Mixin(Boto3Mixin): + def __init__(self, module, **kwargs): + self.tgw_waiter_factory = TgwWaiterFactory(module) + super(TGWAttachmentBoto3Mixin, self).__init__(module, **kwargs) + + # Paginators can't be (easily) wrapped, so we wrap this method with the + # retry - retries the full fetch, but better than simply giving up. + @AWSRetry.jittered_backoff() + def _paginated_describe_transit_gateway_vpc_attachments(self, **params): + paginator = self.client.get_paginator('describe_transit_gateway_vpc_attachments') + return paginator.paginate(**params).build_full_result() + + @Boto3Mixin.aws_error_handler('describe transit gateway attachments') + def _describe_vpc_attachments(self, **params): + result = self._paginated_describe_transit_gateway_vpc_attachments(**params) + return result.get('TransitGatewayVpcAttachments', None) + + @Boto3Mixin.aws_error_handler('create transit gateway attachment') + def _create_vpc_attachment(self, **params): + result = self.client.create_transit_gateway_vpc_attachment(aws_retry=True, **params) + return result.get('TransitGatewayVpcAttachment', None) + + @Boto3Mixin.aws_error_handler('modify transit gateway attachment') + def _modify_vpc_attachment(self, **params): + result = self.client.modify_transit_gateway_vpc_attachment(aws_retry=True, **params) + return result.get('TransitGatewayVpcAttachment', None) + + @Boto3Mixin.aws_error_handler('delete transit gateway attachment') + def _delete_vpc_attachment(self, **params): + try: + result = self.client.delete_transit_gateway_vpc_attachment(aws_retry=True, **params) + except is_boto3_error_code('ResourceNotFoundException'): + return None + return result.get('TransitGatewayVpcAttachment', None) + + @Boto3Mixin.aws_error_handler('transit gateway attachment to finish deleting') + def _wait_tgw_attachment_deleted(self, **params): + waiter = self.tgw_waiter_factory.get_waiter('tgw_attachment_deleted') + waiter.wait(**params) + + @Boto3Mixin.aws_error_handler('transit gateway attachment to become available') + def _wait_tgw_attachment_available(self, **params): + waiter = self.tgw_waiter_factory.get_waiter('tgw_attachment_available') + waiter.wait(**params) + + def _normalize_tgw_attachment(self, rtb): + return self._normalize_boto3_resource(rtb) + + def _get_tgw_vpc_attachment(self, **params): + # Only for use with a single attachment, use _describe_vpc_attachments for + # multiple tables. + attachments = self._describe_vpc_attachments(**params) + + if not attachments: + return None + + attachment = attachments[0] + return attachment + + +class TransitGatewayVpcAttachmentManager(TGWAttachmentBoto3Mixin, BaseEc2Manager): + + TAG_RESOURCE_TYPE = 'transit-gateway-attachment' + + def __init__(self, module, id=None): + self._subnet_updates = dict() + super(TransitGatewayVpcAttachmentManager, self).__init__(module=module, id=id) + + def _get_id_params(self, id=None, id_list=False): + if not id: + id = self.resource_id + if not id: + # Users should never see this, but let's cover ourself + self.module.fail_json(msg='Attachment identifier parameter missing') + + if id_list: + return dict(TransitGatewayAttachmentIds=[id]) + return dict(TransitGatewayAttachmentId=id) + + def _extra_error_output(self): + output = super(TransitGatewayVpcAttachmentManager, self)._extra_error_output() + if self.resource_id: + output['TransitGatewayAttachmentId'] = self.resource_id + return output + + def _filter_immutable_resource_attributes(self, resource): + resource = super(TransitGatewayVpcAttachmentManager, self)._filter_immutable_resource_attributes(resource) + resource.pop('TransitGatewayId', None) + resource.pop('VpcId', None) + resource.pop('VpcOwnerId', None) + resource.pop('State', None) + resource.pop('SubnetIds', None) + resource.pop('CreationTime', None) + resource.pop('Tags', None) + return resource + + def _set_option(self, name, value): + if value is None: + return False + # For now VPC Attachment options are all enable/disable + if value: + value = 'enable' + else: + value = 'disable' + + options = deepcopy(self._preupdate_resource.get('Options', dict())) + options.update(self._resource_updates.get('Options', dict())) + options[name] = value + + return self._set_resource_value('Options', options) + + def set_dns_support(self, value): + return self._set_option('DnsSupport', value) + + def set_ipv6_support(self, value): + return self._set_option('Ipv6Support', value) + + def set_appliance_mode_support(self, value): + return self._set_option('ApplianceModeSupport', value) + + def set_transit_gateway(self, tgw_id): + return self._set_resource_value('TransitGatewayId', tgw_id) + + def set_vpc(self, vpc_id): + return self._set_resource_value('VpcId', vpc_id) + + def set_subnets(self, subnets=None, purge=True): + if subnets is None: + return False + + current_subnets = set(self._preupdate_resource.get('SubnetIds', [])) + desired_subnets = set(subnets) + if not purge: + desired_subnets = desired_subnets.union(current_subnets) + + # We'll pull the VPC ID from the subnets, no point asking for + # information we 'know'. + subnet_details = self._describe_subnets(SubnetIds=list(desired_subnets)) + vpc_id = self.subnets_to_vpc(desired_subnets, subnet_details) + self._set_resource_value('VpcId', vpc_id, immutable=True) + + # Only one subnet per-AZ is permitted + azs = [s.get('AvailabilityZoneId') for s in subnet_details] + if len(azs) != len(set(azs)): + self.module.fail_json( + msg='Only one attachment subnet per availability zone may be set.', + availability_zones=azs, subnets=subnet_details) + + subnets_to_add = list(desired_subnets.difference(current_subnets)) + subnets_to_remove = list(current_subnets.difference(desired_subnets)) + if not subnets_to_remove and not subnets_to_add: + return False + self._subnet_updates = dict(add=subnets_to_add, remove=subnets_to_remove) + self._set_resource_value('SubnetIds', list(desired_subnets)) + return True + + def subnets_to_vpc(self, subnets, subnet_details=None): + if not subnets: + return None + + if subnet_details is None: + subnet_details = self._describe_subnets(SubnetIds=list(subnets)) + + vpcs = [s.get('VpcId') for s in subnet_details] + if len(set(vpcs)) > 1: + self.module.fail_json( + msg='Attachment subnets may only be in one VPC, multiple VPCs found', + vpcs=list(set(vpcs)), subnets=subnet_details) + + return vpcs[0] + + def _do_deletion_wait(self, id=None, **params): + all_params = self._get_id_params(id=id, id_list=True) + all_params.update(**params) + return self._wait_tgw_attachment_deleted(**all_params) + + def _do_creation_wait(self, id=None, **params): + all_params = self._get_id_params(id=id, id_list=True) + all_params.update(**params) + return self._wait_tgw_attachment_available(**all_params) + + def _do_update_wait(self, id=None, **params): + all_params = self._get_id_params(id=id, id_list=True) + all_params.update(**params) + return self._wait_tgw_attachment_available(**all_params) + + def _do_create_resource(self): + params = self._merge_resource_changes(filter_immutable=False, creation=True) + response = self._create_vpc_attachment(**params) + if response: + self.resource_id = response.get('TransitGatewayAttachmentId', None) + return response + + def _do_update_resource(self): + if self._preupdate_resource.get('State', None) == 'pending': + # Resources generally don't like it if you try to update before creation + # is complete. If things are in a 'pending' state they'll often throw + # exceptions. + self._wait_for_creation() + elif self._preupdate_resource.get('State', None) == 'deleting': + self.module.fail_json(msg='Deletion in progress, unable to update', + route_tables=[self.original_resource]) + + updates = self._filter_immutable_resource_attributes(self._resource_updates) + subnets_to_add = self._subnet_updates.get('add', []) + subnets_to_remove = self._subnet_updates.get('remove', []) + if subnets_to_add: + updates['AddSubnetIds'] = subnets_to_add + if subnets_to_remove: + updates['RemoveSubnetIds'] = subnets_to_remove + + if not updates: + return False + + if self.module.check_mode: + return True + + updates.update(self._get_id_params(id_list=False)) + self._modify_vpc_attachment(**updates) + return True + + def get_resource(self): + return self.get_attachment() + + def delete(self, id=None): + + if id: + id_params = self._get_id_params(id=id, id_list=True) + result = self._get_tgw_vpc_attachment(**id_params) + else: + result = self._preupdate_resource + + self.updated_resource = dict() + + if not result: + return False + + if result.get('State') == 'deleting': + self._wait_for_deletion() + return False + + if self.module.check_mode: + self.changed = True + return True + + id_params = self._get_id_params(id=id, id_list=False) + + result = self._delete_vpc_attachment(**id_params) + + self.changed |= bool(result) + + self._wait_for_deletion() + return bool(result) + + def list(self, filters=None, id=None): + params = dict() + if id: + params['TransitGatewayAttachmentIds'] = [id] + if filters: + params['Filters'] = ansible_dict_to_boto3_filter_list(filters) + attachments = self._describe_vpc_attachments(**params) + if not attachments: + return list() + + return [self._normalize_tgw_attachment(a) for a in attachments] + + def get_attachment(self, id=None): + + # RouteTable needs a list, Association/Propagation needs a single ID + id_params = self._get_id_params(id=id, id_list=True) + id_param = self._get_id_params(id=id, id_list=False) + result = self._get_tgw_vpc_attachment(**id_params) + + if not result: + return None + + if not id: + self._preupdate_resource = deepcopy(result) + + attachment = self._normalize_tgw_attachment(result) + return attachment + + def _normalize_resource(self, resource): + return self._normalize_tgw_attachment(resource) 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 From 7a85303740566916ee516f953e1f8777c15e0bac Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Tue, 17 May 2022 15:32:10 +0200 Subject: [PATCH 02/25] ec2_transit_gateway_vpc_attachment - retry on IncorrectState (#1147) ec2_transit_gateway_vpc_attachment - retry on IncorrectState SUMMARY Follows on from #1110 - to retry ec2_transit_gateway_vpc_attachment failures Doing this separately because it's not in the stable-3 branch. ISSUE TYPE Bugfix Pull Request COMPONENT NAME ec2_transit_gateway_vpc_attachment 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/3347cb04867e3cfe545a2d2570ae5daf539e8441 --- plugins/module_utils/transitgateway.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/plugins/module_utils/transitgateway.py b/plugins/module_utils/transitgateway.py index e333be82e51..3ec198abdde 100644 --- a/plugins/module_utils/transitgateway.py +++ b/plugins/module_utils/transitgateway.py @@ -103,7 +103,23 @@ def _get_tgw_vpc_attachment(self, **params): return attachment -class TransitGatewayVpcAttachmentManager(TGWAttachmentBoto3Mixin, BaseEc2Manager): +class BaseTGWManager(BaseEc2Manager): + + @Boto3Mixin.aws_error_handler('connect to AWS') + def _create_client(self, client_name='ec2'): + if client_name == 'ec2': + error_codes = ['IncorrectState'] + else: + error_codes = [] + + retry_decorator = AWSRetry.jittered_backoff( + catch_extra_error_codes=error_codes, + ) + client = self.module.client(client_name, retry_decorator=retry_decorator) + return client + + +class TransitGatewayVpcAttachmentManager(TGWAttachmentBoto3Mixin, BaseTGWManager): TAG_RESOURCE_TYPE = 'transit-gateway-attachment' From 4ca1987acf8f89002a827104f119b5c6bdabcfb4 Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Wed, 1 Jun 2022 15:03:38 +0200 Subject: [PATCH 03/25] Tagging fragment - Move simplest cases over to the docs fragment. (#1182) Tagging fragment - Move simplest cases over to the docs fragment. Depends-On: ansible-collections/amazon.aws#844 SUMMARY Migrate simplest cases over to the new docs fragment and add resource_tags as an alias to tags. ISSUE TYPE Docs Pull Request Feature Pull Request COMPONENT NAME changelogs/fragments/1182-tagging.yml plugins/modules/aws_glue_job.py plugins/modules/aws_msk_cluster.py plugins/modules/aws_secret.py plugins/modules/aws_step_functions_state_machine.py plugins/modules/dynamodb_table.py plugins/modules/ec2_eip.py plugins/modules/ec2_transit_gateway_vpc_attachment.py plugins/modules/ec2_vpc_peer.py plugins/modules/elb_application_lb.py plugins/modules/elb_network_lb.py plugins/modules/iam_role.py plugins/modules/iam_user.py plugins/modules/networkfirewall.py plugins/modules/networkfirewall_policy.py plugins/modules/networkfirewall_rule_group.py plugins/modules/rds_cluster.py plugins/modules/rds_instance.py plugins/modules/rds_instance_snapshot.py plugins/modules/rds_option_group.py plugins/modules/rds_subnet_group.py plugins/modules/redshift.py 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/b11ffaed2b3450f6fee9721878090da404401021 --- .../ec2_transit_gateway_vpc_attachment.py | 22 ++++--------------- 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/plugins/modules/ec2_transit_gateway_vpc_attachment.py b/plugins/modules/ec2_transit_gateway_vpc_attachment.py index 13518fdbe2a..7f2fc2988ba 100644 --- a/plugins/modules/ec2_transit_gateway_vpc_attachment.py +++ b/plugins/modules/ec2_transit_gateway_vpc_attachment.py @@ -81,22 +81,6 @@ 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 @@ -111,10 +95,12 @@ - Defaults to 600 seconds. type: int required: false -author: "Mark Chappell (@tremble)" +author: + - "Mark Chappell (@tremble)" extends_documentation_fragment: - amazon.aws.aws - amazon.aws.ec2 + - amazon.aws.tags ''' EXAMPLES = ''' @@ -246,7 +232,7 @@ def main(): 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), + tags=dict(type='dict', required=False, aliases=['resource_tags']), purge_tags=dict(type='bool', required=False, default=True), appliance_mode_support=dict(type='bool', required=False), dns_support=dict(type='bool', required=False), From 2a5b38dadfb2ba32065fd985ec8ba68bc1eb161c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A9ri=20Le=20Bouder?= Date: Fri, 16 Sep 2022 15:35:38 -0400 Subject: [PATCH 04/25] tests/integration: ensure the CI gives more time to some slow targets (#1467) tests/integration: ensure the CI gives more time to some slow targets Depends-On: ansible/ansible-zuul-jobs#1625 Depends-On: #1468 Depends-On: #1473 Reviewed-by: Mark Chappell This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/19a24e51e52e9efdb9cd3ae22f0a86f50683d6c5 --- .../targets/ec2_transit_gateway_vpc_attachment/aliases | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/targets/ec2_transit_gateway_vpc_attachment/aliases b/tests/integration/targets/ec2_transit_gateway_vpc_attachment/aliases index fb58dd5786f..ad75ddab5e0 100644 --- a/tests/integration/targets/ec2_transit_gateway_vpc_attachment/aliases +++ b/tests/integration/targets/ec2_transit_gateway_vpc_attachment/aliases @@ -1,3 +1,3 @@ cloud/aws - +time=21m # ec2_transit_gateway_vpc_attachment_info From 7f26282043235469ef8c799e2918302e9303f986 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A9ri=20Le=20Bouder?= Date: Sat, 17 Sep 2022 17:31:35 -0400 Subject: [PATCH 05/25] tests: dedicate more time to ec2_transit_gateway_vpc_attachment (#1494) tests: dedicate more time to ec2_transit_gateway_vpc_attachment ec2_transit_gateway_vpc_attachment took 0:33:49 during the following buildset: https://ansible.softwarefactory-project.io/zuul/buildset/92340ac9ef144d5ca9e59f7cd3769451 This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/de5b804abaae27421646a13602976b5a52712047 --- .../targets/ec2_transit_gateway_vpc_attachment/aliases | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/targets/ec2_transit_gateway_vpc_attachment/aliases b/tests/integration/targets/ec2_transit_gateway_vpc_attachment/aliases index ad75ddab5e0..94fa60d71f2 100644 --- a/tests/integration/targets/ec2_transit_gateway_vpc_attachment/aliases +++ b/tests/integration/targets/ec2_transit_gateway_vpc_attachment/aliases @@ -1,3 +1,3 @@ cloud/aws -time=21m +time=35m # ec2_transit_gateway_vpc_attachment_info From 6712b0044a8ba0cb4ea3547155e46ff4518f9aca Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Wed, 28 Sep 2022 13:40:43 +0200 Subject: [PATCH 06/25] Make example AWS UUIDS follow a specific pattern (#1539) Make example AWS UUIDS follow a specific pattern SUMMARY Various AWS IAM resources have UUID which follow a specific pattern. Similarly AWS accounts are all 12 digit numbers (text aliases in a couple of cases). To minimize the risk of accidental data leaks use a consistent Account ID in examples (123456789012), and a specific format for the UUIDS: (AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)12345EXAMPLE54321 While this does nothing about historic data, having consistency makes it easier to prevent future leaks. Note: We should follow this up with an update to the developer docs, however I'd like to get this in prior to 5.0.0 ISSUE TYPE Docs Pull Request COMPONENT NAME plugins/modules/acm_certificate_info.py plugins/modules/application_autoscaling_policy.py plugins/modules/autoscaling_launch_config.py plugins/modules/autoscaling_launch_config_info.py plugins/modules/codecommit_repository.py plugins/modules/directconnect_link_aggregation_group.py plugins/modules/dms_endpoint.py plugins/modules/dynamodb_table.py plugins/modules/ec2_transit_gateway_info.py plugins/modules/ec2_transit_gateway_vpc_attachment.py plugins/modules/ec2_transit_gateway_vpc_attachment_info.py plugins/modules/ec2_vpc_peer.py plugins/modules/ec2_vpc_peering_info.py plugins/modules/ec2_vpc_vpn_info.py plugins/modules/ecs_cluster.py plugins/modules/ecs_ecr.py plugins/modules/ecs_service.py plugins/modules/ecs_service_info.py plugins/modules/ecs_task.py plugins/modules/efs.py plugins/modules/efs_info.py plugins/modules/eks_cluster.py plugins/modules/elasticache_subnet_group.py plugins/modules/elb_network_lb.py plugins/modules/elb_target_group.py plugins/modules/elb_target_group_info.py plugins/modules/elb_target_info.py plugins/modules/iam_group.py plugins/modules/iam_managed_policy.py plugins/modules/iam_mfa_device_info.py plugins/modules/iam_server_certificate_info.py plugins/modules/lightsail.py plugins/modules/lightsail_static_ip.py plugins/modules/msk_cluster.py plugins/modules/s3_bucket_notification.py plugins/modules/sns_topic.py plugins/modules/sns_topic_info.py plugins/modules/sqs_queue.py plugins/modules/stepfunctions_state_machine.py plugins/modules/stepfunctions_state_machine_execution.py plugins/modules/storagegateway_info.py plugins/modules/wafv2_web_acl.py ADDITIONAL INFORMATION While the 'secret' nature of these UUIDs is debatable (they're closer to user names than passwords), deliberately mangling them makes it easier for InfoSec teams to spot when their secret counterparts may have been leaked in combination with a real 'public' part. This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/94764225332c869eefa574a8948da680bb668407 --- plugins/modules/ec2_transit_gateway_vpc_attachment.py | 2 +- plugins/modules/ec2_transit_gateway_vpc_attachment_info.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/modules/ec2_transit_gateway_vpc_attachment.py b/plugins/modules/ec2_transit_gateway_vpc_attachment.py index 7f2fc2988ba..20178ed5f19 100644 --- a/plugins/modules/ec2_transit_gateway_vpc_attachment.py +++ b/plugins/modules/ec2_transit_gateway_vpc_attachment.py @@ -214,7 +214,7 @@ - The ID of the account that the VPC belongs to. type: str returned: success - example: '012345678901' + example: '123456789012' ''' diff --git a/plugins/modules/ec2_transit_gateway_vpc_attachment_info.py b/plugins/modules/ec2_transit_gateway_vpc_attachment_info.py index a0a07ce87d7..9e51ad19bda 100644 --- a/plugins/modules/ec2_transit_gateway_vpc_attachment_info.py +++ b/plugins/modules/ec2_transit_gateway_vpc_attachment_info.py @@ -142,7 +142,7 @@ - The ID of the account that the VPC belongs to. type: str returned: success - example: '012345678901' + example: '123456789012' ''' From 9605ba58219b0c24fb759ff58cc0d3d5b79563bc Mon Sep 17 00:00:00 2001 From: Alina Buzachis Date: Wed, 5 Oct 2022 17:04:40 +0200 Subject: [PATCH 07/25] Update extends_documentation_fragment with amazon.aws.boto3 (#1459) Update extends_documentation_fragment with amazon.aws.boto3 Depends-On: ansible/ansible-zuul-jobs#1654 SUMMARY As per ansible-collections/amazon.aws#985 add amazon.aws.boto3. ISSUE TYPE Docs Pull Request COMPONENT NAME several Reviewed-by: Jill R Reviewed-by: Mark Chappell Reviewed-by: Markus Bergholz This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/bd3c03fcba0848f593b86309740fa73e986a9646 --- plugins/modules/ec2_transit_gateway_vpc_attachment.py | 1 + plugins/modules/ec2_transit_gateway_vpc_attachment_info.py | 1 + 2 files changed, 2 insertions(+) diff --git a/plugins/modules/ec2_transit_gateway_vpc_attachment.py b/plugins/modules/ec2_transit_gateway_vpc_attachment.py index 20178ed5f19..5540590219b 100644 --- a/plugins/modules/ec2_transit_gateway_vpc_attachment.py +++ b/plugins/modules/ec2_transit_gateway_vpc_attachment.py @@ -100,6 +100,7 @@ extends_documentation_fragment: - amazon.aws.aws - amazon.aws.ec2 + - amazon.aws.boto3 - amazon.aws.tags ''' diff --git a/plugins/modules/ec2_transit_gateway_vpc_attachment_info.py b/plugins/modules/ec2_transit_gateway_vpc_attachment_info.py index 9e51ad19bda..ea9aec0419c 100644 --- a/plugins/modules/ec2_transit_gateway_vpc_attachment_info.py +++ b/plugins/modules/ec2_transit_gateway_vpc_attachment_info.py @@ -43,6 +43,7 @@ extends_documentation_fragment: - amazon.aws.aws - amazon.aws.ec2 + - amazon.aws.boto3 ''' EXAMPLES = ''' From 54d39f6fc82ac170687004c3da60a58f0eeed872 Mon Sep 17 00:00:00 2001 From: Bikouo Aubin <79859644+abikouo@users.noreply.github.com> Date: Tue, 10 Jan 2023 19:22:13 +0100 Subject: [PATCH 08/25] Ansible User-Agent identification for community.aws (#1632) Ansible User-Agent identification for community.aws SUMMARY The value will be similar to this APN/1.0 Ansible/2.14.1 community.aws/6.0.0-dev0 ISSUE TYPE Feature Pull Request Reviewed-by: Mark Chappell Reviewed-by: Bikouo Aubin 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/a8cbce24071bcc62fe4594c38aff1baf18bd2862 --- plugins/modules/ec2_transit_gateway_vpc_attachment.py | 2 +- plugins/modules/ec2_transit_gateway_vpc_attachment_info.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/modules/ec2_transit_gateway_vpc_attachment.py b/plugins/modules/ec2_transit_gateway_vpc_attachment.py index 5540590219b..55267bc9185 100644 --- a/plugins/modules/ec2_transit_gateway_vpc_attachment.py +++ b/plugins/modules/ec2_transit_gateway_vpc_attachment.py @@ -219,7 +219,7 @@ ''' -from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule +from ansible_collections.community.aws.plugins.module_utils.modules import AnsibleCommunityAWSModule as AnsibleAWSModule from ansible_collections.community.aws.plugins.module_utils.transitgateway import TransitGatewayVpcAttachmentManager diff --git a/plugins/modules/ec2_transit_gateway_vpc_attachment_info.py b/plugins/modules/ec2_transit_gateway_vpc_attachment_info.py index ea9aec0419c..3a8d4dfd4d1 100644 --- a/plugins/modules/ec2_transit_gateway_vpc_attachment_info.py +++ b/plugins/modules/ec2_transit_gateway_vpc_attachment_info.py @@ -147,7 +147,7 @@ ''' -from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule +from ansible_collections.community.aws.plugins.module_utils.modules import AnsibleCommunityAWSModule as AnsibleAWSModule from ansible_collections.community.aws.plugins.module_utils.transitgateway import TransitGatewayVpcAttachmentManager From 2ce901d2b46d91ce06814407e6f33108a90d3418 Mon Sep 17 00:00:00 2001 From: mihai-satmarean <4729542+mihai-satmarean@users.noreply.github.com> Date: Tue, 28 Feb 2023 12:52:07 +0100 Subject: [PATCH 09/25] fixed unneeded `state` in module docs. (#1728) fixed unneeded `state` in module docs. SUMMARY removed state as it does not work in the info part ISSUE TYPE Docs Pull Request COMPONENT NAME ADDITIONAL INFORMATION "Unsupported parameters for (community.aws.ec2_transit_gateway_vpc_attachment_info) module: state. Supported parameters include: access_key, aws_ca_bundle, aws_config, debug_botocore_endpoint_logs, endpoint_url, filters, id, include_deleted, name, profile, region, secret_key, session_token, validate_certs (access_token, attachment_id, aws_access_key, aws_access_key_id, aws_endpoint_url, aws_profile, aws_region, aws_secret_access_key, aws_secret_key, aws_security_token, aws_session_token, ec2_access_key, ec2_region, ec2_secret_key, ec2_url, s3_url, security_token).", Reviewed-by: Mark Chappell This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/b5eefc1693e7529fb222faf2a4c80085ffff3f28 --- plugins/modules/ec2_transit_gateway_vpc_attachment_info.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/plugins/modules/ec2_transit_gateway_vpc_attachment_info.py b/plugins/modules/ec2_transit_gateway_vpc_attachment_info.py index 3a8d4dfd4d1..88f57fefa1b 100644 --- a/plugins/modules/ec2_transit_gateway_vpc_attachment_info.py +++ b/plugins/modules/ec2_transit_gateway_vpc_attachment_info.py @@ -49,18 +49,15 @@ 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' ''' From ac45143d3127fdf5e189590c2616b152cfc4f480 Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Wed, 8 Mar 2023 12:07:26 +0100 Subject: [PATCH 10/25] Cleanup headers and imports (#1738) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cleanup headers and imports SUMMARY Mass update of imports, docs fragments and file headers Many of the amazon.aws module_utils and docs fragments got moved about, update community.aws to reflect this. Consistently apply the comment headers as documented at https://docs.ansible.com/ansible/devel/dev_guide/developing_modules_documenting.html#python-shebang-utf-8-coding ISSUE TYPE Docs Pull Request Feature Pull Request COMPONENT NAME ADDITIONAL INFORMATION Header cleanup based upon: https://docs.ansible.com/ansible/devel/dev_guide/developing_modules_documenting.html#python-shebang-utf-8-coding Begin your Ansible module with #!/usr/bin/python - this “shebang” allows ansible_python_interpreter to work. Follow the shebang immediately with # -*- coding: utf-8 -*- to clarify that the file is UTF-8 encoded. and https://docs.ansible.com/ansible/devel/dev_guide/developing_modules_documenting.html#copyright-and-license After the shebang and UTF-8 coding, add a copyright line with the original copyright holder and a license declaration. The license declaration should be ONLY one line, not the full GPL prefix. ... Additions to the module (for instance, rewrites) are not permitted to add additional copyright lines other than the default copyright statement if missing: 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/a4f20bf114bfab19b1c84c4ecf42efd5614ab80c --- plugins/module_utils/transitgateway.py | 11 ++++---- .../ec2_transit_gateway_vpc_attachment.py | 26 ++++++++---------- ...ec2_transit_gateway_vpc_attachment_info.py | 27 +++++++++---------- 3 files changed, 28 insertions(+), 36 deletions(-) diff --git a/plugins/module_utils/transitgateway.py b/plugins/module_utils/transitgateway.py index 3ec198abdde..fff2ce63ffe 100644 --- a/plugins/module_utils/transitgateway.py +++ b/plugins/module_utils/transitgateway.py @@ -1,14 +1,13 @@ +# -*- coding: utf-8 -*- + # 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 - from copy import deepcopy -from ansible_collections.amazon.aws.plugins.module_utils.core import is_boto3_error_code -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ansible_dict_to_boto3_filter_list +from ansible_collections.amazon.aws.plugins.module_utils.botocore import is_boto3_error_code +from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry +from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list from ansible_collections.community.aws.plugins.module_utils.ec2 import BaseEc2Manager from ansible_collections.community.aws.plugins.module_utils.ec2 import Boto3Mixin diff --git a/plugins/modules/ec2_transit_gateway_vpc_attachment.py b/plugins/modules/ec2_transit_gateway_vpc_attachment.py index 55267bc9185..2878fbf9129 100644 --- a/plugins/modules/ec2_transit_gateway_vpc_attachment.py +++ b/plugins/modules/ec2_transit_gateway_vpc_attachment.py @@ -1,12 +1,10 @@ #!/usr/bin/python +# -*- coding: utf-8 -*- + # 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 = ''' +DOCUMENTATION = r""" module: ec2_transit_gateway_vpc_attachment short_description: Create and delete AWS Transit Gateway VPC attachments version_added: 4.0.0 @@ -98,13 +96,13 @@ author: - "Mark Chappell (@tremble)" extends_documentation_fragment: - - amazon.aws.aws - - amazon.aws.ec2 - - amazon.aws.boto3 + - amazon.aws.common.modules + - amazon.aws.region.modules - amazon.aws.tags -''' + - amazon.aws.boto3 +""" -EXAMPLES = ''' +EXAMPLES = r""" # Create a Transit Gateway attachment - community.aws.ec2_transit_gateway_vpc_attachment: state: present @@ -135,9 +133,9 @@ - community.aws.ec2_transit_gateway_vpc_attachment: state: absent id: 'tgw-attach-0c0c5fd0b0f01d1c9' -''' +""" -RETURN = ''' +RETURN = r""" transit_gateway_attachments: description: The attributes of the Transit Gateway attachments. type: list @@ -216,11 +214,9 @@ type: str returned: success example: '123456789012' -''' - +""" from ansible_collections.community.aws.plugins.module_utils.modules import AnsibleCommunityAWSModule as AnsibleAWSModule - from ansible_collections.community.aws.plugins.module_utils.transitgateway import TransitGatewayVpcAttachmentManager diff --git a/plugins/modules/ec2_transit_gateway_vpc_attachment_info.py b/plugins/modules/ec2_transit_gateway_vpc_attachment_info.py index 88f57fefa1b..49c03ff432c 100644 --- a/plugins/modules/ec2_transit_gateway_vpc_attachment_info.py +++ b/plugins/modules/ec2_transit_gateway_vpc_attachment_info.py @@ -1,12 +1,10 @@ #!/usr/bin/python +# -*- coding: utf-8 -*- + # 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 = ''' +DOCUMENTATION = r""" module: ec2_transit_gateway_vpc_attachment_info short_description: describes AWS Transit Gateway VPC attachments version_added: 4.0.0 @@ -39,14 +37,15 @@ type: bool required: false default: false -author: "Mark Chappell (@tremble)" +author: + - "Mark Chappell (@tremble)" extends_documentation_fragment: - - amazon.aws.aws - - amazon.aws.ec2 + - amazon.aws.common.modules + - amazon.aws.region.modules - amazon.aws.boto3 -''' +""" -EXAMPLES = ''' +EXAMPLES = r""" # Describe a specific Transit Gateway attachment. - community.aws.ec2_transit_gateway_vpc_attachment_info: id: 'tgw-attach-0123456789abcdef0' @@ -60,9 +59,9 @@ - community.aws.ec2_transit_gateway_vpc_attachment_info: filters: transit-gateway-id: tgw-0fedcba9876543210' -''' +""" -RETURN = ''' +RETURN = r""" transit_gateway_attachments: description: The attributes of the Transit Gateway attachments. type: list @@ -141,11 +140,9 @@ type: str returned: success example: '123456789012' -''' - +""" from ansible_collections.community.aws.plugins.module_utils.modules import AnsibleCommunityAWSModule as AnsibleAWSModule - from ansible_collections.community.aws.plugins.module_utils.transitgateway import TransitGatewayVpcAttachmentManager From 6b84c403688ca2ede0cdbe7dab558077b3e1a42e Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Wed, 26 Apr 2023 19:26:07 +0200 Subject: [PATCH 11/25] Big Black PR (#1784) * Black prep * Black * changelog * Fix pylint unused-import in tests * Split SSM connection plugin changes * disable glue tests - bucket's missing * Disable s3_logging and s3_sync tests This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/2c4575c248776c65d66b06cd60fa09b0dae1cd6f --- plugins/module_utils/transitgateway.py | 169 ++++++++++-------- .../ec2_transit_gateway_vpc_attachment.py | 98 +++++----- ...ec2_transit_gateway_vpc_attachment_info.py | 40 +++-- 3 files changed, 174 insertions(+), 133 deletions(-) diff --git a/plugins/module_utils/transitgateway.py b/plugins/module_utils/transitgateway.py index fff2ce63ffe..5f0e934d1f2 100644 --- a/plugins/module_utils/transitgateway.py +++ b/plugins/module_utils/transitgateway.py @@ -21,21 +21,43 @@ def _waiter_model_data(self): # split the TGW waiters so we can keep them close to everything else. tgw_data = dict( tgw_attachment_available=dict( - operation='DescribeTransitGatewayAttachments', - delay=5, maxAttempts=120, + operation="DescribeTransitGatewayAttachments", + delay=5, + maxAttempts=120, acceptors=[ - dict(state='success', matcher='pathAll', expected='available', argument='TransitGatewayAttachments[].State'), - ] + dict( + state="success", + matcher="pathAll", + expected="available", + argument="TransitGatewayAttachments[].State", + ), + ], ), tgw_attachment_deleted=dict( - operation='DescribeTransitGatewayAttachments', - delay=5, maxAttempts=120, + operation="DescribeTransitGatewayAttachments", + delay=5, + maxAttempts=120, acceptors=[ - dict(state='retry', matcher='pathAll', expected='deleting', argument='TransitGatewayAttachments[].State'), - dict(state='success', matcher='pathAll', expected='deleted', argument='TransitGatewayAttachments[].State'), - dict(state='success', matcher='path', expected=True, argument='length(TransitGatewayAttachments[]) == `0`'), - dict(state='success', matcher='error', expected='InvalidRouteTableID.NotFound'), - ] + dict( + state="retry", + matcher="pathAll", + expected="deleting", + argument="TransitGatewayAttachments[].State", + ), + dict( + state="success", + matcher="pathAll", + expected="deleted", + argument="TransitGatewayAttachments[].State", + ), + dict( + state="success", + matcher="path", + expected=True, + argument="length(TransitGatewayAttachments[]) == `0`", + ), + dict(state="success", matcher="error", expected="InvalidRouteTableID.NotFound"), + ], ), ) data.update(tgw_data) @@ -51,40 +73,40 @@ def __init__(self, module, **kwargs): # retry - retries the full fetch, but better than simply giving up. @AWSRetry.jittered_backoff() def _paginated_describe_transit_gateway_vpc_attachments(self, **params): - paginator = self.client.get_paginator('describe_transit_gateway_vpc_attachments') + paginator = self.client.get_paginator("describe_transit_gateway_vpc_attachments") return paginator.paginate(**params).build_full_result() - @Boto3Mixin.aws_error_handler('describe transit gateway attachments') + @Boto3Mixin.aws_error_handler("describe transit gateway attachments") def _describe_vpc_attachments(self, **params): result = self._paginated_describe_transit_gateway_vpc_attachments(**params) - return result.get('TransitGatewayVpcAttachments', None) + return result.get("TransitGatewayVpcAttachments", None) - @Boto3Mixin.aws_error_handler('create transit gateway attachment') + @Boto3Mixin.aws_error_handler("create transit gateway attachment") def _create_vpc_attachment(self, **params): result = self.client.create_transit_gateway_vpc_attachment(aws_retry=True, **params) - return result.get('TransitGatewayVpcAttachment', None) + return result.get("TransitGatewayVpcAttachment", None) - @Boto3Mixin.aws_error_handler('modify transit gateway attachment') + @Boto3Mixin.aws_error_handler("modify transit gateway attachment") def _modify_vpc_attachment(self, **params): result = self.client.modify_transit_gateway_vpc_attachment(aws_retry=True, **params) - return result.get('TransitGatewayVpcAttachment', None) + return result.get("TransitGatewayVpcAttachment", None) - @Boto3Mixin.aws_error_handler('delete transit gateway attachment') + @Boto3Mixin.aws_error_handler("delete transit gateway attachment") def _delete_vpc_attachment(self, **params): try: result = self.client.delete_transit_gateway_vpc_attachment(aws_retry=True, **params) - except is_boto3_error_code('ResourceNotFoundException'): + except is_boto3_error_code("ResourceNotFoundException"): return None - return result.get('TransitGatewayVpcAttachment', None) + return result.get("TransitGatewayVpcAttachment", None) - @Boto3Mixin.aws_error_handler('transit gateway attachment to finish deleting') + @Boto3Mixin.aws_error_handler("transit gateway attachment to finish deleting") def _wait_tgw_attachment_deleted(self, **params): - waiter = self.tgw_waiter_factory.get_waiter('tgw_attachment_deleted') + waiter = self.tgw_waiter_factory.get_waiter("tgw_attachment_deleted") waiter.wait(**params) - @Boto3Mixin.aws_error_handler('transit gateway attachment to become available') + @Boto3Mixin.aws_error_handler("transit gateway attachment to become available") def _wait_tgw_attachment_available(self, **params): - waiter = self.tgw_waiter_factory.get_waiter('tgw_attachment_available') + waiter = self.tgw_waiter_factory.get_waiter("tgw_attachment_available") waiter.wait(**params) def _normalize_tgw_attachment(self, rtb): @@ -103,11 +125,10 @@ def _get_tgw_vpc_attachment(self, **params): class BaseTGWManager(BaseEc2Manager): - - @Boto3Mixin.aws_error_handler('connect to AWS') - def _create_client(self, client_name='ec2'): - if client_name == 'ec2': - error_codes = ['IncorrectState'] + @Boto3Mixin.aws_error_handler("connect to AWS") + def _create_client(self, client_name="ec2"): + if client_name == "ec2": + error_codes = ["IncorrectState"] else: error_codes = [] @@ -119,8 +140,7 @@ def _create_client(self, client_name='ec2'): class TransitGatewayVpcAttachmentManager(TGWAttachmentBoto3Mixin, BaseTGWManager): - - TAG_RESOURCE_TYPE = 'transit-gateway-attachment' + TAG_RESOURCE_TYPE = "transit-gateway-attachment" def __init__(self, module, id=None): self._subnet_updates = dict() @@ -131,7 +151,7 @@ def _get_id_params(self, id=None, id_list=False): id = self.resource_id if not id: # Users should never see this, but let's cover ourself - self.module.fail_json(msg='Attachment identifier parameter missing') + self.module.fail_json(msg="Attachment identifier parameter missing") if id_list: return dict(TransitGatewayAttachmentIds=[id]) @@ -140,18 +160,18 @@ def _get_id_params(self, id=None, id_list=False): def _extra_error_output(self): output = super(TransitGatewayVpcAttachmentManager, self)._extra_error_output() if self.resource_id: - output['TransitGatewayAttachmentId'] = self.resource_id + output["TransitGatewayAttachmentId"] = self.resource_id return output def _filter_immutable_resource_attributes(self, resource): resource = super(TransitGatewayVpcAttachmentManager, self)._filter_immutable_resource_attributes(resource) - resource.pop('TransitGatewayId', None) - resource.pop('VpcId', None) - resource.pop('VpcOwnerId', None) - resource.pop('State', None) - resource.pop('SubnetIds', None) - resource.pop('CreationTime', None) - resource.pop('Tags', None) + resource.pop("TransitGatewayId", None) + resource.pop("VpcId", None) + resource.pop("VpcOwnerId", None) + resource.pop("State", None) + resource.pop("SubnetIds", None) + resource.pop("CreationTime", None) + resource.pop("Tags", None) return resource def _set_option(self, name, value): @@ -159,36 +179,36 @@ def _set_option(self, name, value): return False # For now VPC Attachment options are all enable/disable if value: - value = 'enable' + value = "enable" else: - value = 'disable' + value = "disable" - options = deepcopy(self._preupdate_resource.get('Options', dict())) - options.update(self._resource_updates.get('Options', dict())) + options = deepcopy(self._preupdate_resource.get("Options", dict())) + options.update(self._resource_updates.get("Options", dict())) options[name] = value - return self._set_resource_value('Options', options) + return self._set_resource_value("Options", options) def set_dns_support(self, value): - return self._set_option('DnsSupport', value) + return self._set_option("DnsSupport", value) def set_ipv6_support(self, value): - return self._set_option('Ipv6Support', value) + return self._set_option("Ipv6Support", value) def set_appliance_mode_support(self, value): - return self._set_option('ApplianceModeSupport', value) + return self._set_option("ApplianceModeSupport", value) def set_transit_gateway(self, tgw_id): - return self._set_resource_value('TransitGatewayId', tgw_id) + return self._set_resource_value("TransitGatewayId", tgw_id) def set_vpc(self, vpc_id): - return self._set_resource_value('VpcId', vpc_id) + return self._set_resource_value("VpcId", vpc_id) def set_subnets(self, subnets=None, purge=True): if subnets is None: return False - current_subnets = set(self._preupdate_resource.get('SubnetIds', [])) + current_subnets = set(self._preupdate_resource.get("SubnetIds", [])) desired_subnets = set(subnets) if not purge: desired_subnets = desired_subnets.union(current_subnets) @@ -197,21 +217,23 @@ def set_subnets(self, subnets=None, purge=True): # information we 'know'. subnet_details = self._describe_subnets(SubnetIds=list(desired_subnets)) vpc_id = self.subnets_to_vpc(desired_subnets, subnet_details) - self._set_resource_value('VpcId', vpc_id, immutable=True) + self._set_resource_value("VpcId", vpc_id, immutable=True) # Only one subnet per-AZ is permitted - azs = [s.get('AvailabilityZoneId') for s in subnet_details] + azs = [s.get("AvailabilityZoneId") for s in subnet_details] if len(azs) != len(set(azs)): self.module.fail_json( - msg='Only one attachment subnet per availability zone may be set.', - availability_zones=azs, subnets=subnet_details) + msg="Only one attachment subnet per availability zone may be set.", + availability_zones=azs, + subnets=subnet_details, + ) subnets_to_add = list(desired_subnets.difference(current_subnets)) subnets_to_remove = list(current_subnets.difference(desired_subnets)) if not subnets_to_remove and not subnets_to_add: return False self._subnet_updates = dict(add=subnets_to_add, remove=subnets_to_remove) - self._set_resource_value('SubnetIds', list(desired_subnets)) + self._set_resource_value("SubnetIds", list(desired_subnets)) return True def subnets_to_vpc(self, subnets, subnet_details=None): @@ -221,11 +243,13 @@ def subnets_to_vpc(self, subnets, subnet_details=None): if subnet_details is None: subnet_details = self._describe_subnets(SubnetIds=list(subnets)) - vpcs = [s.get('VpcId') for s in subnet_details] + vpcs = [s.get("VpcId") for s in subnet_details] if len(set(vpcs)) > 1: self.module.fail_json( - msg='Attachment subnets may only be in one VPC, multiple VPCs found', - vpcs=list(set(vpcs)), subnets=subnet_details) + msg="Attachment subnets may only be in one VPC, multiple VPCs found", + vpcs=list(set(vpcs)), + subnets=subnet_details, + ) return vpcs[0] @@ -248,26 +272,25 @@ def _do_create_resource(self): params = self._merge_resource_changes(filter_immutable=False, creation=True) response = self._create_vpc_attachment(**params) if response: - self.resource_id = response.get('TransitGatewayAttachmentId', None) + self.resource_id = response.get("TransitGatewayAttachmentId", None) return response def _do_update_resource(self): - if self._preupdate_resource.get('State', None) == 'pending': + if self._preupdate_resource.get("State", None) == "pending": # Resources generally don't like it if you try to update before creation # is complete. If things are in a 'pending' state they'll often throw # exceptions. self._wait_for_creation() - elif self._preupdate_resource.get('State', None) == 'deleting': - self.module.fail_json(msg='Deletion in progress, unable to update', - route_tables=[self.original_resource]) + elif self._preupdate_resource.get("State", None) == "deleting": + self.module.fail_json(msg="Deletion in progress, unable to update", route_tables=[self.original_resource]) updates = self._filter_immutable_resource_attributes(self._resource_updates) - subnets_to_add = self._subnet_updates.get('add', []) - subnets_to_remove = self._subnet_updates.get('remove', []) + subnets_to_add = self._subnet_updates.get("add", []) + subnets_to_remove = self._subnet_updates.get("remove", []) if subnets_to_add: - updates['AddSubnetIds'] = subnets_to_add + updates["AddSubnetIds"] = subnets_to_add if subnets_to_remove: - updates['RemoveSubnetIds'] = subnets_to_remove + updates["RemoveSubnetIds"] = subnets_to_remove if not updates: return False @@ -283,7 +306,6 @@ def get_resource(self): return self.get_attachment() def delete(self, id=None): - if id: id_params = self._get_id_params(id=id, id_list=True) result = self._get_tgw_vpc_attachment(**id_params) @@ -295,7 +317,7 @@ def delete(self, id=None): if not result: return False - if result.get('State') == 'deleting': + if result.get("State") == "deleting": self._wait_for_deletion() return False @@ -315,9 +337,9 @@ def delete(self, id=None): def list(self, filters=None, id=None): params = dict() if id: - params['TransitGatewayAttachmentIds'] = [id] + params["TransitGatewayAttachmentIds"] = [id] if filters: - params['Filters'] = ansible_dict_to_boto3_filter_list(filters) + params["Filters"] = ansible_dict_to_boto3_filter_list(filters) attachments = self._describe_vpc_attachments(**params) if not attachments: return list() @@ -325,7 +347,6 @@ def list(self, filters=None, id=None): return [self._normalize_tgw_attachment(a) for a in attachments] def get_attachment(self, id=None): - # RouteTable needs a list, Association/Propagation needs a single ID id_params = self._get_id_params(id=id, id_list=True) id_param = self._get_id_params(id=id, id_list=False) diff --git a/plugins/modules/ec2_transit_gateway_vpc_attachment.py b/plugins/modules/ec2_transit_gateway_vpc_attachment.py index 2878fbf9129..301fefb0513 100644 --- a/plugins/modules/ec2_transit_gateway_vpc_attachment.py +++ b/plugins/modules/ec2_transit_gateway_vpc_attachment.py @@ -221,25 +221,24 @@ 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, aliases=['resource_tags']), - 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), + 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, aliases=["resource_tags"]), + 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'], + ["id", "transit_gateway", "name"], ] module = AnsibleAWSModule( @@ -248,55 +247,68 @@ def main(): 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') + 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 + filters["transit-gateway-id"] = tgw if name: - filters['tag:Name'] = name + filters["tag:Name"] = name if subnets: vpc_id = search_manager.subnets_to_vpc(subnets) - filters['vpc-id'] = vpc_id + 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' + 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) + 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'] + 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)) + manager.set_wait(module.params.get("wait", None)) + manager.set_wait_timeout(module.params.get("wait_timeout", None)) - if state == 'absent': + 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.') + 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.') + 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: @@ -310,9 +322,9 @@ def main(): 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.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( @@ -320,7 +332,7 @@ def main(): attachments=[manager.updated_resource], ) if manager.changed: - results['diff'] = dict( + results["diff"] = dict( before=manager.original_resource, after=manager.updated_resource, ) @@ -328,5 +340,5 @@ def main(): module.exit_json(**results) -if __name__ == '__main__': +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 index 49c03ff432c..a665e4080cc 100644 --- a/plugins/modules/ec2_transit_gateway_vpc_attachment_info.py +++ b/plugins/modules/ec2_transit_gateway_vpc_attachment_info.py @@ -147,17 +147,16 @@ 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) + 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'], + ["id", "name"], + ["id", "filters"], ] module = AnsibleAWSModule( @@ -165,22 +164,31 @@ def main(): supports_check_mode=True, ) - name = module.params.get('name', None) - id = module.params.get('id', None) - opt_filters = module.params.get('filters', None) + 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 + filters["tag:Name"] = name - if not module.params.get('include_deleted'): + 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' + filters["state"] = [ + "available", + "deleting", + "failed", + "failing", + "initiatingRequest", + "modifying", + "pendingAcceptance", + "pending", + "rollingBack", + "rejected", + "rejecting", ] if opt_filters: @@ -191,5 +199,5 @@ def main(): module.exit_json(changed=False, attachments=attachments, filters=filters) -if __name__ == '__main__': +if __name__ == "__main__": main() From 87dcdc1717b467bafbd580d85bb7b6034dd142c8 Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Thu, 31 Aug 2023 17:58:59 +0200 Subject: [PATCH 12/25] Mass update of docs and tests (credentials/session tokens) (#1921) Mass update of docs and tests (credentials/session tokens) SUMMARY We had a cleanup of credentials/session parameters which included a batch of deprecations and renames. Ensure that all of our tests and docs are using the 'canonical' names ISSUE TYPE Docs Pull Request COMPONENT NAME plugins/modules/batch_compute_environment.py plugins/modules/cloudformation_exports_info.py plugins/modules/ec2_vpc_vpn.py plugins/modules/elasticache.py plugins/modules/elasticache_parameter_group.py plugins/modules/elasticache_snapshot.py plugins/modules/ses_rule_set.py plugins/modules/sts_assume_role.py plugins/modules/sts_session_token.py tests/integration ADDITIONAL INFORMATION See also ansible-collections/amazon.aws#1172 ansible-collections/amazon.aws#1714 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/4a5b50e9b9c0d6ca1a1f802f3b03d4f503c16885 --- .../ec2_transit_gateway_vpc_attachment/tasks/main.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 index 8694b829e7b..ce9659473f6 100644 --- a/tests/integration/targets/ec2_transit_gateway_vpc_attachment/tasks/main.yml +++ b/tests/integration/targets/ec2_transit_gateway_vpc_attachment/tasks/main.yml @@ -4,9 +4,9 @@ - amazon.aws module_defaults: group/aws: - aws_access_key: '{{ aws_access_key }}' - aws_secret_key: '{{ aws_secret_key }}' - security_token: '{{ security_token | default(omit) }}' + access_key: '{{ aws_access_key }}' + secret_key: '{{ aws_secret_key }}' + session_token: '{{ security_token | default(omit) }}' region: '{{ aws_region }}' block: From 89eb8d7640306dcb79b403c5d9e400a9f8e2ea48 Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Fri, 5 Jan 2024 18:42:41 +0100 Subject: [PATCH 13/25] ansible-lint (documentation) cleanup for plugins/ (#2036) ansible-lint (documentation) cleanup for plugins/ SUMMARY Fixes an array of ansible-lint failures in plugins/ Adds ansible-lint plugins/ to tox -m lint ISSUE TYPE Docs Pull Request COMPONENT NAME plugins/ ADDITIONAL INFORMATION docs changes only (no changelog fragment needed) 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/6dd4a00b8c18fe3499bad04f90c8ac7832ade8bb --- .../ec2_transit_gateway_vpc_attachment.py | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/plugins/modules/ec2_transit_gateway_vpc_attachment.py b/plugins/modules/ec2_transit_gateway_vpc_attachment.py index 301fefb0513..cfb6809a803 100644 --- a/plugins/modules/ec2_transit_gateway_vpc_attachment.py +++ b/plugins/modules/ec2_transit_gateway_vpc_attachment.py @@ -109,13 +109,13 @@ 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 + - 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 @@ -124,10 +124,10 @@ state: present id: 'tgw-attach-0c0c5fd0b0f01d1c9' name: AnsibleTest-1 - ipv6_support: True - purge_subnets: False - dns_support: False - appliance_mode_support: True + ipv6_support: true + purge_subnets: false + dns_support: false + appliance_mode_support: true # Delete the transit gateway - community.aws.ec2_transit_gateway_vpc_attachment: From 7649931628844858224901e6639f431feb8324a8 Mon Sep 17 00:00:00 2001 From: Carlos Schimidt <40364204+cschimid@users.noreply.github.com> Date: Tue, 2 Jul 2024 11:33:10 -0300 Subject: [PATCH 14/25] Add support to enable multicast on transit gateway (#2063) SUMMARY Need to enable multicast while creating transit gateway ISSUE TYPE Feature Pull Request COMPONENT NAME transit_gateway ADDITIONAL INFORMATION Reviewed-by: Alina Buzachis Reviewed-by: Bikouo Aubin Reviewed-by: Carlos Schimidt Reviewed-by: Mark Chappell This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/4752c05c56076e1b904d7ee4dfd6c350601da0af --- plugins/module_utils/transitgateway.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/module_utils/transitgateway.py b/plugins/module_utils/transitgateway.py index 5f0e934d1f2..8a82a839ff1 100644 --- a/plugins/module_utils/transitgateway.py +++ b/plugins/module_utils/transitgateway.py @@ -192,6 +192,9 @@ def _set_option(self, name, value): def set_dns_support(self, value): return self._set_option("DnsSupport", value) + def set_multicast_support(self, value): + return self._set_option("MulticastSupport", value) + def set_ipv6_support(self, value): return self._set_option("Ipv6Support", value) From 1764a31397728e09a21a1007d8786500cce39dd4 Mon Sep 17 00:00:00 2001 From: GomathiselviS Date: Fri, 18 Oct 2024 06:05:47 -0400 Subject: [PATCH 15/25] ec2_transit_gateway_vpc_attachment - Prepare module for migration to amazon.aws (#2157) SUMMARY Refer: https://issues.redhat.com/browse/ACA-1868 This PR refactors and adds necessary documentation to ec2_transit_gateway_vpc_attachment and ec2_transit_gateway_vpc_attachment_info ISSUE TYPE Bugfix Pull Request Docs Pull Request Feature Pull Request New Module Pull Request COMPONENT NAME ADDITIONAL INFORMATION Reviewed-by: Alina Buzachis Reviewed-by: Bikouo Aubin This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/7dabfccc73b77239b95de01069890f3ee7bf95f0 --- plugins/module_utils/transitgateway.py | 718 +++++++++++------- .../ec2_transit_gateway_vpc_attachment.py | 257 +++---- ...ec2_transit_gateway_vpc_attachment_info.py | 122 +-- .../tasks/cleanup.yml | 44 +- .../tasks/complex.yml | 112 +-- .../tasks/setup.yml | 20 +- .../tasks/simple.yml | 655 +++++++++------- 7 files changed, 1092 insertions(+), 836 deletions(-) diff --git a/plugins/module_utils/transitgateway.py b/plugins/module_utils/transitgateway.py index 8a82a839ff1..a3454931205 100644 --- a/plugins/module_utils/transitgateway.py +++ b/plugins/module_utils/transitgateway.py @@ -5,221 +5,234 @@ from copy import deepcopy -from ansible_collections.amazon.aws.plugins.module_utils.botocore import is_boto3_error_code -from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry +try: + from botocore.exceptions import BotoCoreError + from botocore.exceptions import ClientError +except ImportError: + pass + +from typing import Any +from typing import Dict +from typing import List +from typing import Optional +from typing import Tuple + +from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict + +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AnsibleEC2Error +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import create_transit_gateway_vpc_attachment +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import delete_transit_gateway_vpc_attachment +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import describe_subnets +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import describe_transit_gateway_vpc_attachments +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ensure_ec2_tags +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import modify_transit_gateway_vpc_attachment +from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_list_to_ansible_dict +from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_specifications from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list +from ansible_collections.amazon.aws.plugins.module_utils.transformation import boto3_resource_to_ansible_dict +from ansible_collections.amazon.aws.plugins.module_utils.waiters import get_waiter + +from ansible_collections.community.aws.plugins.module_utils.modules import AnsibleCommunityAWSModule as AnsibleAWSModule + + +def get_states() -> List[str]: + return [ + "available", + "deleting", + "failed", + "failing", + "initiatingRequest", + "modifying", + "pendingAcceptance", + "pending", + "rollingBack", + "rejected", + "rejecting", + ] + + +def subnets_to_vpc( + client, module: AnsibleAWSModule, subnets: List[str], subnet_details: Optional[List[Dict[str, Any]]] = None +) -> Optional[str]: + if not subnets: + return None + + if subnet_details is None: + try: + subnet_details = describe_subnets(client, SubnetIds=list(subnets)) + except AnsibleEC2Error as e: + module.fail_json_aws_error(e) + + vpcs = [s.get("VpcId") for s in subnet_details] + if len(set(vpcs)) > 1: + module.fail_json( + msg="Attachment subnets may only be in one VPC, multiple VPCs found", + vpcs=list(set(vpcs)), + subnets=subnet_details, + ) + + return vpcs[0] + + +def find_existing_attachment( + client, module: AnsibleAWSModule, filters: Optional[Dict[str, Any]] = None, attachment_id: Optional[str] = None +) -> Optional[Dict[str, Any]]: + """Find an existing transit gateway attachment based on filters or attachment ID. + + Args: + client: The AWS client used to interact with the EC2 service. + module: The Ansible module instance used for error handling. + filters (Optional[Dict[str, Any]]): A dictionary of filters to apply when searching for attachments. + attachment_id (Optional[str]): The ID of a specific attachment to find. + + Returns: + Optional[Dict[str, Any]]: The found attachment details or None if not found. -from ansible_collections.community.aws.plugins.module_utils.ec2 import BaseEc2Manager -from ansible_collections.community.aws.plugins.module_utils.ec2 import Boto3Mixin -from ansible_collections.community.aws.plugins.module_utils.ec2 import Ec2WaiterFactory + Raises: + ValueError: If multiple attachments match the criteria. + """ + # Find an existing attachment based on filters + params = {} + if attachment_id: + params["TransitGatewayAttachmentIds"] = [attachment_id] + elif filters: + params["Filters"] = ansible_dict_to_boto3_filter_list(filters) + + try: + attachments = describe_transit_gateway_vpc_attachments(client, **params) + except AnsibleEC2Error as e: + module.fail_json_aws_error(e) + + if len(attachments) > 1: + raise ValueError("Multiple matching attachments found, provide an ID.") + + return attachments[0] if attachments else None + + +class TransitGatewayAttachmentStateManager: + def __init__(self, client, module: AnsibleAWSModule, attachment_id: str) -> None: + self.client = client + self.module = module + self.attachment_id = attachment_id -class TgwWaiterFactory(Ec2WaiterFactory): @property - def _waiter_model_data(self): - data = super(TgwWaiterFactory, self)._waiter_model_data - # split the TGW waiters so we can keep them close to everything else. - tgw_data = dict( - tgw_attachment_available=dict( - operation="DescribeTransitGatewayAttachments", - delay=5, - maxAttempts=120, - acceptors=[ - dict( - state="success", - matcher="pathAll", - expected="available", - argument="TransitGatewayAttachments[].State", - ), - ], - ), - tgw_attachment_deleted=dict( - operation="DescribeTransitGatewayAttachments", - delay=5, - maxAttempts=120, - acceptors=[ - dict( - state="retry", - matcher="pathAll", - expected="deleting", - argument="TransitGatewayAttachments[].State", - ), - dict( - state="success", - matcher="pathAll", - expected="deleted", - argument="TransitGatewayAttachments[].State", - ), - dict( - state="success", - matcher="path", - expected=True, - argument="length(TransitGatewayAttachments[]) == `0`", - ), - dict(state="success", matcher="error", expected="InvalidRouteTableID.NotFound"), - ], - ), - ) - data.update(tgw_data) - return data - - -class TGWAttachmentBoto3Mixin(Boto3Mixin): - def __init__(self, module, **kwargs): - self.tgw_waiter_factory = TgwWaiterFactory(module) - super(TGWAttachmentBoto3Mixin, self).__init__(module, **kwargs) - - # Paginators can't be (easily) wrapped, so we wrap this method with the - # retry - retries the full fetch, but better than simply giving up. - @AWSRetry.jittered_backoff() - def _paginated_describe_transit_gateway_vpc_attachments(self, **params): - paginator = self.client.get_paginator("describe_transit_gateway_vpc_attachments") - return paginator.paginate(**params).build_full_result() - - @Boto3Mixin.aws_error_handler("describe transit gateway attachments") - def _describe_vpc_attachments(self, **params): - result = self._paginated_describe_transit_gateway_vpc_attachments(**params) - return result.get("TransitGatewayVpcAttachments", None) - - @Boto3Mixin.aws_error_handler("create transit gateway attachment") - def _create_vpc_attachment(self, **params): - result = self.client.create_transit_gateway_vpc_attachment(aws_retry=True, **params) - return result.get("TransitGatewayVpcAttachment", None) - - @Boto3Mixin.aws_error_handler("modify transit gateway attachment") - def _modify_vpc_attachment(self, **params): - result = self.client.modify_transit_gateway_vpc_attachment(aws_retry=True, **params) - return result.get("TransitGatewayVpcAttachment", None) - - @Boto3Mixin.aws_error_handler("delete transit gateway attachment") - def _delete_vpc_attachment(self, **params): - try: - result = self.client.delete_transit_gateway_vpc_attachment(aws_retry=True, **params) - except is_boto3_error_code("ResourceNotFoundException"): - return None - return result.get("TransitGatewayVpcAttachment", None) + def waiter_config(self) -> Dict[str, Any]: + params: Dict[str, Any] = {} - @Boto3Mixin.aws_error_handler("transit gateway attachment to finish deleting") - def _wait_tgw_attachment_deleted(self, **params): - waiter = self.tgw_waiter_factory.get_waiter("tgw_attachment_deleted") - waiter.wait(**params) + delay = min(5, self.module.params.get("wait_timeout")) + max_attempts = self.module.params.get("wait_timeout") // delay + config = dict(Delay=delay, MaxAttempts=max_attempts) + params["WaiterConfig"] = config - @Boto3Mixin.aws_error_handler("transit gateway attachment to become available") - def _wait_tgw_attachment_available(self, **params): - waiter = self.tgw_waiter_factory.get_waiter("tgw_attachment_available") - waiter.wait(**params) + return params - def _normalize_tgw_attachment(self, rtb): - return self._normalize_boto3_resource(rtb) + def create_attachment(self, params: Dict[str, Any]) -> str: + """ + Create a new transit gateway attachment. - def _get_tgw_vpc_attachment(self, **params): - # Only for use with a single attachment, use _describe_vpc_attachments for - # multiple tables. - attachments = self._describe_vpc_attachments(**params) + Args: + params (Dict[str, Any]): A dictionary containing the parameters needed to + create the transit gateway attachment. - if not attachments: - return None + Returns: + str: The ID of the newly created transit gateway attachment. - attachment = attachments[0] - return attachment + Raises: + AnsibleEC2Error: If there is an error while creating the VPC attachment, + it will fail the module and provide an error message. + """ + try: + tags = params.pop("Tags") + except KeyError: + tags = None + if tags: + params["TagSpecifications"] = boto3_tag_specifications(tags, types=["transit-gateway-attachment"]) -class BaseTGWManager(BaseEc2Manager): - @Boto3Mixin.aws_error_handler("connect to AWS") - def _create_client(self, client_name="ec2"): - if client_name == "ec2": - error_codes = ["IncorrectState"] - else: - error_codes = [] + try: + response = create_transit_gateway_vpc_attachment(self.client, **params) + except AnsibleEC2Error as e: + self.module.fail_json_aws_error(e) - retry_decorator = AWSRetry.jittered_backoff( - catch_extra_error_codes=error_codes, - ) - client = self.module.client(client_name, retry_decorator=retry_decorator) - return client - - -class TransitGatewayVpcAttachmentManager(TGWAttachmentBoto3Mixin, BaseTGWManager): - TAG_RESOURCE_TYPE = "transit-gateway-attachment" - - def __init__(self, module, id=None): - self._subnet_updates = dict() - super(TransitGatewayVpcAttachmentManager, self).__init__(module=module, id=id) - - def _get_id_params(self, id=None, id_list=False): - if not id: - id = self.resource_id - if not id: - # Users should never see this, but let's cover ourself - self.module.fail_json(msg="Attachment identifier parameter missing") - - if id_list: - return dict(TransitGatewayAttachmentIds=[id]) - return dict(TransitGatewayAttachmentId=id) - - def _extra_error_output(self): - output = super(TransitGatewayVpcAttachmentManager, self)._extra_error_output() - if self.resource_id: - output["TransitGatewayAttachmentId"] = self.resource_id - return output - - def _filter_immutable_resource_attributes(self, resource): - resource = super(TransitGatewayVpcAttachmentManager, self)._filter_immutable_resource_attributes(resource) - resource.pop("TransitGatewayId", None) - resource.pop("VpcId", None) - resource.pop("VpcOwnerId", None) - resource.pop("State", None) - resource.pop("SubnetIds", None) - resource.pop("CreationTime", None) - resource.pop("Tags", None) - return resource + self.attachment_id = response["TransitGatewayAttachmentId"] - def _set_option(self, name, value): - if value is None: + return response["TransitGatewayAttachmentId"] + + def delete_attachment(self) -> bool: + # Delete the transit gateway attachment + + if not self.attachment_id: return False - # For now VPC Attachment options are all enable/disable - if value: - value = "enable" - else: - value = "disable" - options = deepcopy(self._preupdate_resource.get("Options", dict())) - options.update(self._resource_updates.get("Options", dict())) - options[name] = value + if not self.module.check_mode: + try: + delete_transit_gateway_vpc_attachment(self.client, self.attachment_id) + except AnsibleEC2Error as e: + self.module.fail_json_aws_error(e) - return self._set_resource_value("Options", options) + return True - def set_dns_support(self, value): - return self._set_option("DnsSupport", value) + def wait_for_state_change(self, desired_state: str) -> None: + # Wait until attachment reaches the desired state + params = {"TransitGatewayAttachmentIds": [self.attachment_id]} + params.update(self.waiter_config) + try: + waiter = get_waiter(self.client, f"transit_gateway_vpc_attachment_{desired_state}") + waiter.wait(**params) + except (BotoCoreError, ClientError) as e: + self.module.fail_json_aws_error(e) - def set_multicast_support(self, value): - return self._set_option("MulticastSupport", value) - def set_ipv6_support(self, value): - return self._set_option("Ipv6Support", value) +class AttachmentConfigurationManager: + def __init__(self, client, module: AnsibleAWSModule, attachment_id: str, existing: Dict[str, Any]) -> None: + self.client = client + self.module = module + self.attachment_id = attachment_id - def set_appliance_mode_support(self, value): - return self._set_option("ApplianceModeSupport", value) + self.existing = existing or {} + self._resource_updates = {} + self._subnets_to_add = [] + self._subnets_to_remove = [] - def set_transit_gateway(self, tgw_id): - return self._set_resource_value("TransitGatewayId", tgw_id) + @property + def resource_updates(self) -> Dict[str, Any]: + return self._resource_updates - def set_vpc(self, vpc_id): - return self._set_resource_value("VpcId", vpc_id) + @property + def subnets_to_add(self) -> List[str]: + return self._subnets_to_add - def set_subnets(self, subnets=None, purge=True): + @property + def subnets_to_remove(self) -> List[str]: + return self._subnets_to_remove + + def set_subnets(self, subnets: Optional[List[str]] = None, purge: bool = True) -> None: + """ + Set or update the subnets associated with the transit gateway attachment. + + Args: + subnets (Optional[List[str]]): A list of subnet IDs to associate with + the attachment. + purge (bool): If True, the existing subnets will be replaced with the + specified subnets. + """ + # Set or update the subnets associated with the attachment if subnets is None: - return False + return - current_subnets = set(self._preupdate_resource.get("SubnetIds", [])) + current_subnets = set(self.existing.get("SubnetIds", [])) desired_subnets = set(subnets) if not purge: desired_subnets = desired_subnets.union(current_subnets) # We'll pull the VPC ID from the subnets, no point asking for # information we 'know'. - subnet_details = self._describe_subnets(SubnetIds=list(desired_subnets)) - vpc_id = self.subnets_to_vpc(desired_subnets, subnet_details) + try: + subnet_details = describe_subnets(self.client, SubnetIds=list(desired_subnets)) + except AnsibleEC2Error as e: + self.module.fail_json_aws_error(e) + vpc_id = subnets_to_vpc(self.client, self.module, desired_subnets, subnet_details) self._set_resource_value("VpcId", vpc_id, immutable=True) # Only one subnet per-AZ is permitted @@ -231,138 +244,269 @@ def set_subnets(self, subnets=None, purge=True): subnets=subnet_details, ) - subnets_to_add = list(desired_subnets.difference(current_subnets)) - subnets_to_remove = list(current_subnets.difference(desired_subnets)) - if not subnets_to_remove and not subnets_to_add: - return False - self._subnet_updates = dict(add=subnets_to_add, remove=subnets_to_remove) + self._subnets_to_add = list(desired_subnets.difference(current_subnets)) + self._subnets_to_remove = list(current_subnets.difference(desired_subnets)) self._set_resource_value("SubnetIds", list(desired_subnets)) - return True - def subnets_to_vpc(self, subnets, subnet_details=None): - if not subnets: - return None + def set_dns_support(self, value): + return self._set_option("DnsSupport", value) - if subnet_details is None: - subnet_details = self._describe_subnets(SubnetIds=list(subnets)) + def set_ipv6_support(self, value): + return self._set_option("Ipv6Support", value) - vpcs = [s.get("VpcId") for s in subnet_details] - if len(set(vpcs)) > 1: - self.module.fail_json( - msg="Attachment subnets may only be in one VPC, multiple VPCs found", - vpcs=list(set(vpcs)), - subnets=subnet_details, - ) + def set_appliance_mode_support(self, value): + return self._set_option("ApplianceModeSupport", value) - return vpcs[0] - - def _do_deletion_wait(self, id=None, **params): - all_params = self._get_id_params(id=id, id_list=True) - all_params.update(**params) - return self._wait_tgw_attachment_deleted(**all_params) - - def _do_creation_wait(self, id=None, **params): - all_params = self._get_id_params(id=id, id_list=True) - all_params.update(**params) - return self._wait_tgw_attachment_available(**all_params) - - def _do_update_wait(self, id=None, **params): - all_params = self._get_id_params(id=id, id_list=True) - all_params.update(**params) - return self._wait_tgw_attachment_available(**all_params) - - def _do_create_resource(self): - params = self._merge_resource_changes(filter_immutable=False, creation=True) - response = self._create_vpc_attachment(**params) - if response: - self.resource_id = response.get("TransitGatewayAttachmentId", None) - return response - - def _do_update_resource(self): - if self._preupdate_resource.get("State", None) == "pending": - # Resources generally don't like it if you try to update before creation - # is complete. If things are in a 'pending' state they'll often throw - # exceptions. - self._wait_for_creation() - elif self._preupdate_resource.get("State", None) == "deleting": - self.module.fail_json(msg="Deletion in progress, unable to update", route_tables=[self.original_resource]) + def set_transit_gateway(self, tgw_id: str): + return self._set_resource_value("TransitGatewayId", tgw_id) - updates = self._filter_immutable_resource_attributes(self._resource_updates) - subnets_to_add = self._subnet_updates.get("add", []) - subnets_to_remove = self._subnet_updates.get("remove", []) - if subnets_to_add: - updates["AddSubnetIds"] = subnets_to_add - if subnets_to_remove: - updates["RemoveSubnetIds"] = subnets_to_remove + def set_vpc(self, vpc_id: str): + return self._set_resource_value("VpcId", vpc_id) + + def set_tags(self, tags, purge_tags): + current_tags = boto3_tag_list_to_ansible_dict(self.existing.get("Tags", None)) - if not updates: + if purge_tags: + desired_tags = deepcopy(tags) + else: + desired_tags = {**current_tags, **tags} + + self._set_resource_value("Tags", desired_tags) + + def _get_resource_value(self, key, default=None): + default_value = self.existing.get(key, default) + return self._resource_updates.get(key, default_value) + + def _set_option(self, name: str, value: Optional[bool]) -> bool: + """ + Set a VPC attachment option to either enable or disable. + + Args: + name (str): The name of the option to be updated. + value (Optional[bool]): A boolean indicating whether to enable (True) + or disable (False) the specified option. If None, no action is + taken. + + Returns: + bool: Returns True if the option was successfully set, or False if + no update was made (because the value was None). + """ + if value is None: return False - if self.module.check_mode: - return True + # For now VPC Attachment options are all enable/disable + value = "enable" if value else "disable" + + options = deepcopy(self.existing.get("Options", dict())) + options.update(self._resource_updates.get("Options", dict())) + options[name] = value + + return self._set_resource_value("Options", options) + + def _set_resource_value(self, key, value, description: Optional[str] = None, immutable: bool = False) -> bool: + """ + Set a value for a resource attribute and track changes. + + Args: + key (str): The attribute key to be updated. + value (Any): The new value to set for the specified key. + description (Optional[str], optional): A human-readable description of the + resource attribute. + immutable (bool, optional): A flag indicating whether the attribute is + immutable. If True, and the resource exists, an error will be raised + if attempting to change the value. Defaults to False. + + Returns: + bool: Returns True if the value was successfully set, or False if no + update was made. + """ + if value is None or value == self._get_resource_value(key): + return False + + if immutable and self.existing: + description = description or key + self.module.fail_json(msg=f"{description} can not be updated after creation") + + self.resource_updates[key] = value - updates.update(self._get_id_params(id_list=False)) - self._modify_vpc_attachment(**updates) return True - def get_resource(self): - return self.get_attachment() + def filter_immutable_resource_attributes(self, resource: Dict[str, Any]) -> Dict[str, Any]: + """ + Filter out immutable resource attributes from the given resource dictionary. - def delete(self, id=None): - if id: - id_params = self._get_id_params(id=id, id_list=True) - result = self._get_tgw_vpc_attachment(**id_params) - else: - result = self._preupdate_resource + Args: + resource (Dict[str, Any]): A dictionary representing the resource, which + may contain various attributes, including both mutable and immutable ones. + + Returns: + Dict[str, Any]: A new dictionary containing only the mutable attributes + of the resource. + """ + immutable_options = ["TransitGatewayId", "VpcId", "VpcOwnerId", "State", "SubnetIds", "CreationTime", "Tags"] + return {key: value for key, value in resource.items() if key not in immutable_options} - self.updated_resource = dict() - if not result: +class TransitGatewayVpcAttachmentManager: + def __init__( + self, client, module: AnsibleAWSModule, existing: Dict[str, Any], attachment_id: Optional[str] = None + ) -> None: + self.client = client + self.module = module + self.attachment_id = attachment_id + self.existing = existing or {} + self.updated = {} + self.changed = False + + self.state_manager = TransitGatewayAttachmentStateManager(client, module, attachment_id) + self.config_manager = AttachmentConfigurationManager(client, module, attachment_id, existing) + + def merge_resource_changes(self, filter_immutable: bool = True) -> Dict[str, Any]: + """Merge existing resource attributes with updates, optionally filtering out immutable attributes. + + Args: + filter_immutable (bool): Whether to filter out immutable resource attributes. Defaults to True. + + Returns: + Dict[str, Any]: The merged resource attributes. + """ + resource = deepcopy(self.existing) + resource.update(self.config_manager.resource_updates) + + if filter_immutable: + resource = self.config_manager.filter_immutable_resource_attributes(resource) + + return resource + + def apply_configuration(self): + """Apply configuration changes to the transit gateway attachment. + + Returns: + bool: True if configuration changes were applied, False otherwise. + """ + # Apply any configuration changes to the attachment + if not self.attachment_id: return False - if result.get("State") == "deleting": - self._wait_for_deletion() + updates = self.config_manager.filter_immutable_resource_attributes(self.config_manager.resource_updates) + + subnets_to_add = self.config_manager.subnets_to_add + subnets_to_remove = self.config_manager.subnets_to_remove + + # Check if there are no changes to apply + if not updates and not subnets_to_add and not subnets_to_remove: return False - if self.module.check_mode: - self.changed = True - return True + if subnets_to_add: + updates["AddSubnetIds"] = subnets_to_add + if subnets_to_remove: + updates["RemoveSubnetIds"] = subnets_to_remove - id_params = self._get_id_params(id=id, id_list=False) + updates["TransitGatewayAttachmentId"] = self.attachment_id - result = self._delete_vpc_attachment(**id_params) + if not self.module.check_mode: + try: + modify_transit_gateway_vpc_attachment(self.client, **updates) + except AnsibleEC2Error as e: + self.module.fail_json_aws_error(e) + return True - self.changed |= bool(result) + def _set_configuration_parameters(self) -> None: + """Set configuration parameters for the transit gateway attachment.""" + self.config_manager.set_transit_gateway(self.module.params.get("transit_gateway")) + self.config_manager.set_subnets(self.module.params["subnets"], self.module.params.get("purge_subnets", True)) + self.config_manager.set_dns_support(self.module.params.get("dns_support")) + self.config_manager.set_ipv6_support(self.module.params.get("ipv6_support")) + self.config_manager.set_appliance_mode_support(self.module.params.get("appliance_mode_support")) + + def _prepare_tags(self) -> Tuple[Optional[Dict[str, str]], bool]: + """Prepare and return the tags and purge flag. + + Returns: + Tuple[Optional[Dict[str, str]], bool]: A tuple containing the tags dictionary and the purge flag. + """ + tags = self.module.params.get("tags") + purge_tags = self.module.params.get("purge_tags") + + if self.module.params.get("name"): + new_tags = {"Name": self.module.params["name"]} + if tags is None: + purge_tags = False + else: + new_tags.update(tags) + tags = new_tags + + return {} if tags is None else tags, purge_tags + + def _create_attachment(self) -> None: + """Create a new transit gateway attachment.""" + if not self.module.check_mode: + params = self.merge_resource_changes(filter_immutable=False) + self.attachment_id = self.state_manager.create_attachment(params) + + if self.module.params.get("wait"): + self.state_manager.wait_for_state_change("available") + + self.changed = True + + def _update_attachment(self, tags: Dict[str, Any], purge_tags: bool) -> None: + """Update an existing transit gateway attachment.""" + if self.existing.get("State") == "pending": + # Wait for resources to finish creating before updating + self.state_manager.wait_for_state_change("available") + elif self.existing.get("State") == "deleting": + self.module.fail_json(msg="Deletion in progress, unable to update", route_tables=[self.original_resource]) - self._wait_for_deletion() - return bool(result) + # Apply the configuration + if self.apply_configuration(): + self.changed = True + if self.module.params.get("wait"): + self.state_manager.wait_for_state_change("available") + + # Ensure tags are applied + self.changed |= ensure_ec2_tags( + self.client, + self.module, + self.attachment_id, + resource_type="transit-gateway-attachment", + tags=tags, + purge_tags=purge_tags, + ) - def list(self, filters=None, id=None): - params = dict() - if id: - params["TransitGatewayAttachmentIds"] = [id] - if filters: - params["Filters"] = ansible_dict_to_boto3_filter_list(filters) - attachments = self._describe_vpc_attachments(**params) - if not attachments: - return list() + def create_or_modify_attachment(self): + """Create or modify a transit gateway attachment based on the provided parameters.""" - return [self._normalize_tgw_attachment(a) for a in attachments] + # Set the configuration parameters + self._set_configuration_parameters() - def get_attachment(self, id=None): - # RouteTable needs a list, Association/Propagation needs a single ID - id_params = self._get_id_params(id=id, id_list=True) - id_param = self._get_id_params(id=id, id_list=False) - result = self._get_tgw_vpc_attachment(**id_params) + # Handle tags + tags, purge_tags = self._prepare_tags() - if not result: - return None + # Set tags in the configuration manager + self.config_manager.set_tags(tags, purge_tags) - if not id: - self._preupdate_resource = deepcopy(result) + if not self.existing: + self._create_attachment() + else: + self._update_attachment(tags, purge_tags) - attachment = self._normalize_tgw_attachment(result) - return attachment + # Handle check mode updates + if self.module.check_mode: + self.updated = camel_dict_to_snake_dict( + self.merge_resource_changes(filter_immutable=False), ignore_list=["Tags"] + ) + else: + self.updated = boto3_resource_to_ansible_dict( + find_existing_attachment(self.client, self.module, attachment_id=self.attachment_id) + ) - def _normalize_resource(self, resource): - return self._normalize_tgw_attachment(resource) + def delete_attachment(self): + """Delete attachment""" + if self.existing.get("State") == "deleting": + if self.module.params.get("wait"): + self.state_manager.wait_for_state_change("deleted") + self.change = False + else: + self.changed |= self.state_manager.delete_attachment() + if self.module.params.get("wait"): + self.state_manager.wait_for_state_change("deleted") diff --git a/plugins/modules/ec2_transit_gateway_vpc_attachment.py b/plugins/modules/ec2_transit_gateway_vpc_attachment.py index cfb6809a803..9ecdeb3b2bb 100644 --- a/plugins/modules/ec2_transit_gateway_vpc_attachment.py +++ b/plugins/modules/ec2_transit_gateway_vpc_attachment.py @@ -14,30 +14,30 @@ 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 + - When creating a new attachment, O(transit_gateway) must be provided. + - At least one of O(name), O(transit_gateway) and O(id) must be provided. + - O(transit_gateway) is an immutable setting and can not be updated on an existing attachment. type: str required: false - aliases: ['transit_gateway_id'] + 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. + - When O(id) is not set, a search using O(transit_gateway) and O(name) will be + performed. If multiple results are returned, the module will fail. + - At least one of O(name), O(transit_gateway) and O(id) must be provided. type: str required: false - aliases: ['attachment_id'] + 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 + - The V(Name) tag of the Transit Gateway attachment. + - Providing both O(id) and O(name) will set the V(Name) tag on an existing + attachment the matching O(id). + - Setting the V(Name) tag in O(tags) will also result in the V(Name) tag being updated. - - At least one of I(name), I(transit_gateway) and I(id) must be provided. + - At least one of O(name), O(transit_gateway) and O(id) must be provided. type: str required: false state: @@ -45,7 +45,7 @@ - Create or remove the Transit Gateway attachment. type: str required: false - choices: ['present', 'absent'] + choices: ["present", "absent"] default: 'present' subnets: description: @@ -56,8 +56,8 @@ 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). + - If O(purge_subnets=true), existing subnets will be removed from the + attachment as necessary to match exactly what is defined by O(subnets). type: bool required: false default: true @@ -92,9 +92,11 @@ to reach the expected state. - Defaults to 600 seconds. type: int + default: 600 required: false author: - - "Mark Chappell (@tremble)" + - Mark Chappell (@tremble) + - Alina Buzachis (@alinabuzachis) extends_documentation_fragment: - amazon.aws.common.modules - amazon.aws.region.modules @@ -103,40 +105,40 @@ """ EXAMPLES = r""" -# Create a Transit Gateway attachment -- community.aws.ec2_transit_gateway_vpc_attachment: - state: present - transit_gateway: 'tgw-123456789abcdef01' - name: AnsibleTest-1 +- name: 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 + - "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 + 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 +- name: 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' +- name: Delete the transit gateway + community.aws.ec2_transit_gateway_vpc_attachment: + state: "absent" + id: "tgw-attach-0c0c5fd0b0f01d1c9" """ RETURN = r""" -transit_gateway_attachments: +attachments: description: The attributes of the Transit Gateway attachments. type: list elements: dict @@ -147,7 +149,7 @@ - An ISO 8601 date time stamp of when the attachment was created. type: str returned: success - example: '2022-03-10T16:40:26+00:00' + sample: "2022-03-10T16:40:26+00:00" options: description: - Additional VPC attachment options. @@ -159,32 +161,38 @@ - Indicates whether appliance mode support is enabled. type: str returned: success - example: 'enable' + sample: "enable" dns_support: description: - Indicates whether DNS support is enabled. type: str returned: success - example: 'disable' + sample: "disable" ipv6_support: description: - Indicates whether IPv6 support is disabled. type: str returned: success - example: 'disable' + sample: "disable" + security_group_referencing_support: + description: + - Indicated weather security group referencing support is disabled. + type: str + returned: success + sample: "enable" state: description: - The state of the attachment. type: str returned: success - example: 'deleting' + sample: "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'] + sample: ["subnet-0123456789abcdef0", "subnet-11111111111111111"] tags: description: - A dictionary representing the resource tags. @@ -195,29 +203,92 @@ - The ID of the attachment. type: str returned: success - example: 'tgw-attach-0c0c5fd0b0f01d1c9' + sample: "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' + sample: "tgw-0123456789abcdef0" vpc_id: description: - The ID of the VPC that the attachment is connected to. type: str returned: success - example: 'vpc-0123456789abcdef0' + sample: "vpc-0123456789abcdef0" vpc_owner_id: description: - The ID of the account that the VPC belongs to. type: str returned: success - example: '123456789012' + sample: "1234567890122" """ +from typing import NoReturn + +from ansible_collections.amazon.aws.plugins.module_utils.transformation import boto3_resource_to_ansible_dict + from ansible_collections.community.aws.plugins.module_utils.modules import AnsibleCommunityAWSModule as AnsibleAWSModule from ansible_collections.community.aws.plugins.module_utils.transitgateway import TransitGatewayVpcAttachmentManager +from ansible_collections.community.aws.plugins.module_utils.transitgateway import find_existing_attachment +from ansible_collections.community.aws.plugins.module_utils.transitgateway import get_states +from ansible_collections.community.aws.plugins.module_utils.transitgateway import subnets_to_vpc + + +def handle_vpc_attachments(client, module: AnsibleAWSModule) -> NoReturn: + """ + Handle the creation, modification, or deletion of VPC attachments + based on the parameters provided in the Ansible module. + + Args: + client: The AWS client to interact with EC2 services. + module: An instance of AnsibleAWSModule. + + Returns: + NoReturn: The function exits by calling module.exit_json() + with the results of the operation. + """ + attach_id = module.params.get("id", None) + attachment = None + + if not attach_id: + filters = {} + if module.params.get("transit_gateway"): + filters["transit-gateway-id"] = module.params["transit_gateway"] + if module.params.get("name"): + filters["tag:Name"] = module.params["name"] + if module.params.get("subnets"): + vpc_id = subnets_to_vpc(client, module, module.params["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"] = get_states() + + attachment = find_existing_attachment(client, module, filters=filters) + if attachment: + attach_id = attachment["TransitGatewayAttachmentId"] + else: + attachment = find_existing_attachment(client, module, attachment_id=attach_id) + + manager = TransitGatewayVpcAttachmentManager(client, module, attachment, attachment_id=attach_id) + + if module.params["state"] == "absent": + manager.delete_attachment() + else: + manager.create_or_modify_attachment() + + results = dict( + changed=manager.changed, + attachments=[manager.updated], + ) + if manager.changed: + results["diff"] = dict( + before=boto3_resource_to_ansible_dict(manager.existing), + after=manager.updated, + ) + + module.exit_json(**results) def main(): @@ -234,7 +305,7 @@ def main(): 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), + wait_timeout=dict(type="int", default=600, required=False), ) one_of = [ @@ -247,97 +318,9 @@ def main(): 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)) + client = module.client("ec2") - 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) + handle_vpc_attachments(client, module) if __name__ == "__main__": diff --git a/plugins/modules/ec2_transit_gateway_vpc_attachment_info.py b/plugins/modules/ec2_transit_gateway_vpc_attachment_info.py index a665e4080cc..2ec87583a94 100644 --- a/plugins/modules/ec2_transit_gateway_vpc_attachment_info.py +++ b/plugins/modules/ec2_transit_gateway_vpc_attachment_info.py @@ -14,31 +14,32 @@ id: description: - The ID of the Transit Gateway Attachment. - - Mutually exclusive with I(name) and I(filters) + - Mutually exclusive with O(name) and O(filters). type: str required: false - aliases: ['attachment_id'] + aliases: ["attachment_id"] name: description: - - The C(Name) tag of the Transit Gateway attachment. + - The V(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. + - Setting a V(tag:Name) filter will override the O(name) parameter. type: dict required: false include_deleted: description: - - If I(include_deleted=True), then attachments in a deleted state will + - If O(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. + - Setting a V(state) filter will override the O(include_deleted) parameter. type: bool required: false default: false author: - - "Mark Chappell (@tremble)" + - Mark Chappell (@tremble) + - Alina Buzachis (@alinabuzachis) extends_documentation_fragment: - amazon.aws.common.modules - amazon.aws.region.modules @@ -46,23 +47,21 @@ """ EXAMPLES = r""" -# Describe a specific Transit Gateway attachment. -- community.aws.ec2_transit_gateway_vpc_attachment_info: - id: 'tgw-attach-0123456789abcdef0' +- name: Describe a specific Transit Gateway attachment + community.aws.ec2_transit_gateway_vpc_attachment_info: + id: "tgw-attach-0123456789abcdef0" -# Describe all attachments attached to a transit gateway. -- community.aws.ec2_transit_gateway_vpc_attachment_info: +- name: Describe all attachments attached to a transit gateway + community.aws.ec2_transit_gateway_vpc_attachment_info: filters: - transit-gateway-id: tgw-0fedcba9876543210' + transit-gateway-id: "tgw-0fedcba9876543210" -# Describe all attachments in an account. -- community.aws.ec2_transit_gateway_vpc_attachment_info: - filters: - transit-gateway-id: tgw-0fedcba9876543210' +- name: Describe all attachments in an account + community.aws.ec2_transit_gateway_vpc_attachment_info: """ RETURN = r""" -transit_gateway_attachments: +attachments: description: The attributes of the Transit Gateway attachments. type: list elements: dict @@ -73,7 +72,7 @@ - An ISO 8601 date time stamp of when the attachment was created. type: str returned: success - example: '2022-03-10T16:40:26+00:00' + sample: "2022-03-10T16:40:26+00:00" options: description: - Additional VPC attachment options. @@ -85,32 +84,38 @@ - Indicates whether appliance mode support is enabled. type: str returned: success - example: 'enable' + sample: "enable" dns_support: description: - Indicates whether DNS support is enabled. type: str returned: success - example: 'disable' + sample: "disable" ipv6_support: description: - Indicates whether IPv6 support is disabled. type: str returned: success - example: 'disable' + sample: "disable" + security_group_referencing_support: + description: + - Indicated weather security group referencing support is disabled. + type: str + returned: success + sample: "enable" state: description: - The state of the attachment. type: str returned: success - example: 'deleting' + sample: "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'] + sample: ["subnet-0123456789abcdef0", "subnet-11111111111111111"] tags: description: - A dictionary representing the resource tags. @@ -121,29 +126,38 @@ - The ID of the attachment. type: str returned: success - example: 'tgw-attach-0c0c5fd0b0f01d1c9' + sample: "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' + sample: "tgw-0123456789abcdef0" vpc_id: description: - The ID of the VPC that the attachment is connected to. type: str returned: success - example: 'vpc-0123456789abcdef0' + sample: "vpc-0123456789abcdef0" vpc_owner_id: description: - The ID of the account that the VPC belongs to. type: str returned: success - example: '123456789012' + sample: "123456789012" """ +from typing import Any +from typing import Dict +from typing import List + +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AnsibleEC2Error +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import describe_transit_gateway_vpc_attachments +from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list +from ansible_collections.amazon.aws.plugins.module_utils.transformation import boto3_resource_to_ansible_dict + from ansible_collections.community.aws.plugins.module_utils.modules import AnsibleCommunityAWSModule as AnsibleAWSModule -from ansible_collections.community.aws.plugins.module_utils.transitgateway import TransitGatewayVpcAttachmentManager +from ansible_collections.community.aws.plugins.module_utils.transitgateway import get_states def main(): @@ -162,39 +176,45 @@ def main(): module = AnsibleAWSModule( argument_spec=argument_spec, supports_check_mode=True, + mutually_exclusive=mutually_exclusive, ) - name = module.params.get("name", None) - id = module.params.get("id", None) - opt_filters = module.params.get("filters", None) + name = module.params.get("name") + attachment_id = module.params.get("id") + opt_filters = module.params.get("filters") + include_deleted = module.params.get("include_deleted") + + client = module.client("ec2") + + params: Dict[str, Any] = {} + filters: Dict[str, Any] = {} + attachments: List[Dict[str, Any]] = [] - search_manager = TransitGatewayVpcAttachmentManager(module=module) - filters = dict() + if attachment_id: + params["TransitGatewayAttachmentIds"] = [attachment_id] + # Add filter by name if provided 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", - ] + # Include only active states if "include_deleted" is False + if not include_deleted: + filters["state"] = get_states() + # Include any additional filters provided by the user if opt_filters: filters.update(opt_filters) - attachments = search_manager.list(filters=filters, id=id) + if filters: + params["Filters"] = ansible_dict_to_boto3_filter_list(filters) + + try: + result = describe_transit_gateway_vpc_attachments(client, **params) + except AnsibleEC2Error as e: + module.fail_json_aws_error(e) + + if result: + attachments = [boto3_resource_to_ansible_dict(attachment) for attachment in result] module.exit_json(changed=False, attachments=attachments, filters=filters) 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 index e59723bdc30..b917be3907a 100644 --- a/tests/integration/targets/ec2_transit_gateway_vpc_attachment/tasks/cleanup.yml +++ b/tests/integration/targets/ec2_transit_gateway_vpc_attachment/tasks/cleanup.yml @@ -1,29 +1,29 @@ --- -- name: 'Describe all attachments on our VPC' - ec2_transit_gateway_vpc_attachment_info: +- name: Describe all attachments on our VPC + community.aws.ec2_transit_gateway_vpc_attachment_info: filters: transit-gateway-id: '{{ tgw_id }}' register: info - ignore_errors: True + ignore_errors: true -- name: 'Start deletion of all attachments' - ec2_transit_gateway_vpc_attachment: +- name: Start deletion of all attachments + community.aws.ec2_transit_gateway_vpc_attachment: state: absent id: '{{ item.transit_gateway_attachment_id }}' - wait: False + wait: false loop: '{{ info.attachments }}' - ignore_errors: True + ignore_errors: true -- name: 'Wait for deletion of all attachments' - ec2_transit_gateway_vpc_attachment: +- name: Wait for deletion of all attachments + community.aws.ec2_transit_gateway_vpc_attachment: state: absent id: '{{ item.transit_gateway_attachment_id }}' - wait: True + wait: true loop: '{{ info.attachments }}' - ignore_errors: True + ignore_errors: true -- name: 'Delete subnets' - ec2_vpc_subnet: +- name: Delete subnets + amazon.aws.ec2_vpc_subnet: state: absent cidr: '{{ item.cidr }}' vpc_id: '{{ item.vpc_id }}' @@ -42,8 +42,8 @@ vpc_id: '{{ vpc_id_a }}' ignore_errors: True -- name: 'Create VPCs to attach to TGW' - ec2_vpc_net: +- name: Delete VPCs to attach to TGW + amazon.aws.ec2_vpc_net: state: absent cidr_block: '{{ item.cidr }}' name: '{{ item.name }}' @@ -52,13 +52,19 @@ name: '{{ vpc_name_a }}' - cidr: '{{ vpc_cidr_b }}' name: '{{ vpc_name_b }}' - ignore_errors: True + ignore_errors: true + +- name: Gather info about all transit gateways + community.aws.ec2_transit_gateway_info: + transit_gateway_ids: + - '{{ tgw_id }}' + - '{{ tgw_id_2 }}' -- name: 'Create Transit Gateways' - ec2_transit_gateway: +- name: Delete Transit Gateways + community.aws.ec2_transit_gateway: state: absent transit_gateway_id: '{{ item.tgw_id }}' loop: - tgw_id: '{{ tgw_id }}' - tgw_id: '{{ tgw_id_2 }}' - ignore_errors: True + 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 index eda3ab2ace4..2a234bb165f 100644 --- a/tests/integration/targets/ec2_transit_gateway_vpc_attachment/tasks/complex.yml +++ b/tests/integration/targets/ec2_transit_gateway_vpc_attachment/tasks/complex.yml @@ -8,9 +8,9 @@ # Creation - block: - - name: '(CHECK_MODE) Create an attachment - complex parameters' - check_mode: True - ec2_transit_gateway_vpc_attachment: + - name: (CHECK_MODE) Create an attachment - complex parameters + check_mode: true + community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name_complex }}' transit_gateway: '{{ tgw_id }}' subnets: @@ -19,11 +19,12 @@ tags: tagA: 'example Value' Tag_B: 'second value' - appliance_mode_support: True - ipv6_support: True + appliance_mode_support: true + ipv6_support: true register: complex_attach - - assert: + - name: Assert that the test is successful + ansible.builtin.assert: that: - complex_attach is changed - '"attachments" in complex_attach' @@ -52,8 +53,8 @@ vars: attachment: '{{ complex_attach.attachments[0] }}' - - name: 'Create an attachment - complex parameters' - ec2_transit_gateway_vpc_attachment: + - name: Create an attachment - complex parameters + community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name_complex }}' transit_gateway: '{{ tgw_id }}' subnets: @@ -62,11 +63,12 @@ tags: tagA: 'example Value' Tag_B: 'second value' - appliance_mode_support: True - ipv6_support: True + appliance_mode_support: true + ipv6_support: true register: complex_attach - - assert: + - name: Assert that the test is successful + ansible.builtin.assert: that: - complex_attach is changed - '"attachments" in complex_attach' @@ -108,9 +110,9 @@ 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: (CHECK_MODE) Create an attachment - complex parameters -- IDEMPOTENCY + check_mode: true + community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name_complex }}' transit_gateway: '{{ tgw_id }}' subnets: @@ -119,11 +121,12 @@ tags: tagA: 'example Value' Tag_B: 'second value' - appliance_mode_support: True - ipv6_support: True + appliance_mode_support: true + ipv6_support: true register: complex_attach - - assert: + - name: Assert that there is no change + ansible.builtin.assert: that: - complex_attach is not changed - '"attachments" in complex_attach' @@ -161,8 +164,8 @@ vars: attachment: '{{ complex_attach.attachments[0] }}' - - name: 'Create an attachment - complex parameters -- IDEMPOTENCY' - ec2_transit_gateway_vpc_attachment: + - name: Create an attachment - complex parameters -- IDEMPOTENCY + community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name_complex }}' transit_gateway: '{{ tgw_id }}' subnets: @@ -171,11 +174,12 @@ tags: tagA: 'example Value' Tag_B: 'second value' - appliance_mode_support: True - ipv6_support: True + appliance_mode_support: true + ipv6_support: true register: complex_attach - - assert: + - name: Assert that there is no change + ansible.builtin.assert: that: - complex_attach is not changed - '"attachments" in complex_attach' @@ -216,23 +220,24 @@ # ============================================================================= # Update - - name: '(CHECK_MODE) Update an attachment - complex parameters' - check_mode: True - ec2_transit_gateway_vpc_attachment: + - name: (CHECK_MODE) Update an attachment - complex parameters + check_mode: true + community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name_complex }}' transit_gateway: '{{ tgw_id }}' subnets: - '{{ subnet_id_b_1 }}' - purge_subnets: True + purge_subnets: true tags: tagC: '3' Tag_D: 'Hello again dear world' - purge_tags: False - dns_support: False - ipv6_support: False + purge_tags: false + dns_support: false + ipv6_support: false register: complex_attach - - assert: + - name: Assert that the test is successful + ansible.builtin.assert: that: - complex_attach is changed - '"attachments" in complex_attach' @@ -273,22 +278,23 @@ vars: attachment: '{{ complex_attach.attachments[0] }}' - - name: 'Update an attachment - complex parameters' - ec2_transit_gateway_vpc_attachment: + - name: Update an attachment - complex parameters + community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name_complex }}' transit_gateway: '{{ tgw_id }}' subnets: - '{{ subnet_id_b_1 }}' - purge_subnets: True + purge_subnets: true tags: tagC: '3' Tag_D: 'Hello again dear world' - purge_tags: False - dns_support: False - ipv6_support: False + purge_tags: false + dns_support: false + ipv6_support: false register: complex_attach - - assert: + - name: Assert that the test is successful + ansible.builtin.assert: that: - complex_attach is changed - '"attachments" in complex_attach' @@ -329,23 +335,24 @@ vars: attachment: '{{ complex_attach.attachments[0] }}' - - name: '(CHECK_MODE) Update an attachment - complex parameters -- IDEMPOTENCY' - check_mode: True - ec2_transit_gateway_vpc_attachment: + - name: (CHECK_MODE) Update an attachment - complex parameters -- IDEMPOTENCY + check_mode: true + community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name_complex }}' transit_gateway: '{{ tgw_id }}' subnets: - '{{ subnet_id_b_1 }}' - purge_subnets: True + purge_subnets: true tags: tagC: '3' Tag_D: 'Hello again dear world' - purge_tags: False - dns_support: False - ipv6_support: False + purge_tags: false + dns_support: false + ipv6_support: false register: complex_attach - - assert: + - name: Assert that there is no change + ansible.builtin.assert: that: - complex_attach is not changed - '"attachments" in complex_attach' @@ -386,22 +393,23 @@ vars: attachment: '{{ complex_attach.attachments[0] }}' - - name: 'Update an attachment - complex parameters -- IDEMPOTENCY' - ec2_transit_gateway_vpc_attachment: + - name: Update an attachment - complex parameters -- IDEMPOTENCY + community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name_complex }}' transit_gateway: '{{ tgw_id }}' subnets: - '{{ subnet_id_b_1 }}' - purge_subnets: True + purge_subnets: true tags: tagC: '3' Tag_D: 'Hello again dear world' - purge_tags: False - dns_support: False - ipv6_support: False + purge_tags: false + dns_support: false + ipv6_support: false register: complex_attach - - assert: + - name: Assert that there is no change + ansible.builtin.assert: that: - complex_attach is not changed - '"attachments" in complex_attach' 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 index 86d5aa51b5f..f3b3e86f387 100644 --- a/tests/integration/targets/ec2_transit_gateway_vpc_attachment/tasks/setup.yml +++ b/tests/integration/targets/ec2_transit_gateway_vpc_attachment/tasks/setup.yml @@ -1,5 +1,5 @@ --- -- name: 'Pick 2 AZs available for use' +- 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] }}' @@ -8,23 +8,23 @@ 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: +- name: Create Transit Gateways + community.aws.ec2_transit_gateway: description: '{{ item.description }}' tags: Name: '{{ item.name }}' loop: - - description: 'Transit Gateway for testing ec2_transit_gateway_attachment' + - description: 'Transit Gateway for testing community.aws.ec2_transit_gateway_attachment' name: '{{ tgw_name }}' - - description: 'Second Transit Gateway for testing ec2_transit_gateway_attachment' + - description: 'Second Transit Gateway for testing community.aws.ec2_transit_gateway_attachment' name: '{{ tgw_name_2 }}' register: create_tgws -- name: 'Create VPCs to attach to TGW' - ec2_vpc_net: +- name: Create VPCs to attach to TGW + amazon.aws.ec2_vpc_net: cidr_block: '{{ item.cidr }}' name: '{{ item.name }}' - ipv6_cidr: True + ipv6_cidr: true loop: - cidr: '{{ vpc_cidr_a }}' name: '{{ vpc_name_a }}' @@ -51,8 +51,8 @@ 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: +- name: Create subnets + amazon.aws.ec2_vpc_subnet: az: '{{ item.az }}' cidr: '{{ item.cidr }}' ipv6_cidr: '{{ item.ipv6_cidr }}' 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 index 0085813a322..2cee6627e2c 100644 --- a/tests/integration/targets/ec2_transit_gateway_vpc_attachment/tasks/simple.yml +++ b/tests/integration/targets/ec2_transit_gateway_vpc_attachment/tasks/simple.yml @@ -2,15 +2,16 @@ # ============================================================================= # Creation - block: - - name: '(CHECK_MODE) Create an attachment - minimal parameters' - check_mode: True - ec2_transit_gateway_vpc_attachment: + - name: (CHECK_MODE) Create an attachment - minimal parameters + check_mode: true + community.aws.ec2_transit_gateway_vpc_attachment: transit_gateway: '{{ tgw_id }}' subnets: - '{{ subnet_id_a_1 }}' register: simple_attach - - assert: + - name: Assert that attachment parameters are returned in CHECK_MODE + ansible.builtin.assert: that: - simple_attach is changed - '"attachments" in simple_attach' @@ -25,14 +26,15 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: 'Create an attachment - minimal parameters' - ec2_transit_gateway_vpc_attachment: + - name: Create an attachment - minimal parameters + community.aws.ec2_transit_gateway_vpc_attachment: transit_gateway: '{{ tgw_id }}' subnets: - '{{ subnet_id_a_1 }}' register: simple_attach - - assert: + - name: Assert that the create attachment is successful + ansible.builtin.assert: that: - simple_attach is changed - '"attachments" in simple_attach' @@ -64,18 +66,19 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: Save Attachment ID - set_fact: + ansible.builtin.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: + - name: (CHECK_MODE) Create an attachment - minimal parameters -- IDEMPOTENCY + check_mode: true + community.aws.ec2_transit_gateway_vpc_attachment: transit_gateway: '{{ tgw_id }}' subnets: - '{{ subnet_id_a_1 }}' register: simple_attach - - assert: + - name: Assert that there is no change + ansible.builtin.assert: that: - simple_attach is not changed - '"attachments" in simple_attach' @@ -107,13 +110,14 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: 'Create an attachment - minimal parameters -- IDEMPOTENCY' - ec2_transit_gateway_vpc_attachment: + community.aws.ec2_transit_gateway_vpc_attachment: transit_gateway: '{{ tgw_id }}' subnets: - '{{ subnet_id_a_1 }}' register: simple_attach - - assert: + - name: Assert that there is no change + ansible.builtin.assert: that: - simple_attach is not changed - '"attachments" in simple_attach' @@ -146,15 +150,16 @@ # ===== - - name: '(CHECK_MODE) By Id - minimal parameters -- IDEMPOTENCY' - check_mode: True - ec2_transit_gateway_vpc_attachment: + - name: (CHECK_MODE) By Id - minimal parameters -- IDEMPOTENCY + check_mode: true + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_a_1 }}' register: simple_attach - - assert: + - name: Assert that there is no change + ansible.builtin.assert: that: - simple_attach is not changed - '"attachments" in simple_attach' @@ -186,13 +191,14 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: 'By Id - minimal parameters -- IDEMPOTENCY' - ec2_transit_gateway_vpc_attachment: + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_a_1 }}' register: simple_attach - - assert: + - name: Assert that there is no change + ansible.builtin.assert: that: - simple_attach is not changed - '"attachments" in simple_attach' @@ -227,13 +233,14 @@ # Set a name - name: '(CHECK_MODE) Set name' - check_mode: True - ec2_transit_gateway_vpc_attachment: + check_mode: true + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' name: '{{ attachment_name }}' register: simple_attach - - assert: + - name: Assert that the attachment parameters are returned in CHECK_MODE + ansible.builtin.assert: that: - simple_attach is changed - '"attachments" in simple_attach' @@ -267,12 +274,13 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: 'Set name' - ec2_transit_gateway_vpc_attachment: + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' name: '{{ attachment_name }}' register: simple_attach - - assert: + - name: Assert that 'Set name' is successful + ansible.builtin.assert: that: - simple_attach is changed - '"attachments" in simple_attach' @@ -306,13 +314,14 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: '(CHECK_MODE) Set name -- IDEMPOTENCY' - check_mode: True - ec2_transit_gateway_vpc_attachment: + check_mode: true + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' name: '{{ attachment_name }}' register: simple_attach - - assert: + - name: Assert that there is no change + ansible.builtin.assert: that: - simple_attach is not changed - '"attachments" in simple_attach' @@ -346,12 +355,13 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: 'Set name -- IDEMPOTENCY' - ec2_transit_gateway_vpc_attachment: + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' name: '{{ attachment_name }}' register: simple_attach - - assert: + - name: Assert that there is no change + ansible.builtin.assert: that: - simple_attach is not changed - '"attachments" in simple_attach' @@ -387,14 +397,15 @@ # ===== - name: '(CHECK_MODE) By Name - minimal parameters -- IDEMPOTENCY' - check_mode: True - ec2_transit_gateway_vpc_attachment: + check_mode: true + community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' subnets: - '{{ subnet_id_a_1 }}' register: simple_attach - - assert: + - name: Assert that there is no change + ansible.builtin.assert: that: - simple_attach is not changed - '"attachments" in simple_attach' @@ -428,13 +439,14 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: 'By Name - minimal parameters -- IDEMPOTENCY' - ec2_transit_gateway_vpc_attachment: + community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' subnets: - '{{ subnet_id_a_1 }}' register: simple_attach - - assert: + - name: Assert that there is no change + ansible.builtin.assert: that: - simple_attach is not changed - '"attachments" in simple_attach' @@ -471,10 +483,11 @@ # Describe - name: 'Describe all attachments' - ec2_transit_gateway_vpc_attachment_info: + community.aws.ec2_transit_gateway_vpc_attachment_info: register: info - - assert: + - name: Assert that the transit_gateway_vpc_attachment_info is returned sucessfully + ansible.builtin.assert: that: - info is not changed - '"attachments" in info' @@ -497,12 +510,13 @@ attachment: '{{ info.attachments[0] }}' - name: 'Describe attachments on a specific VPC' - ec2_transit_gateway_vpc_attachment_info: + community.aws.ec2_transit_gateway_vpc_attachment_info: filters: transit-gateway-id: '{{ tgw_id }}' register: info - - assert: + - name: Assert that the returned info is correct + ansible.builtin.assert: that: - info is not changed - '"attachments" in info' @@ -526,11 +540,12 @@ attachment: '{{ info.attachments[0] }}' - name: 'Describe attachment with a specific name' - ec2_transit_gateway_vpc_attachment_info: + community.aws.ec2_transit_gateway_vpc_attachment_info: name: '{{ attachment_name }}' register: info - - assert: + - name: Assert that the returned info is correct + ansible.builtin.assert: that: - info is not changed - '"attachments" in info' @@ -564,11 +579,12 @@ attachment: '{{ info.attachments[0] }}' - name: 'Describe attachment by ID' - ec2_transit_gateway_vpc_attachment_info: + community.aws.ec2_transit_gateway_vpc_attachment_info: id: '{{ simple_attachment_id }}' register: info - - assert: + - name: Assert that the returned info is correct + ansible.builtin.assert: that: - info is not changed - '"attachments" in info' @@ -605,8 +621,8 @@ # Tag attachment - name: '(CHECK_MODE) Set tags' - check_mode: True - ec2_transit_gateway_vpc_attachment: + check_mode: true + community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' tags: CamelCase: CamelCaseValue @@ -615,7 +631,8 @@ "Tag with Space": value with space register: simple_attach - - assert: + - name: Assert that 'Set tags' is successful + ansible.builtin.assert: that: - simple_attach is changed - '"attachments" in simple_attach' @@ -657,7 +674,7 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: 'Set tags' - ec2_transit_gateway_vpc_attachment: + community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' tags: CamelCase: CamelCaseValue @@ -666,7 +683,8 @@ "Tag with Space": value with space register: simple_attach - - assert: + - name: Assert that 'Set tags' is successful + ansible.builtin.assert: that: - simple_attach is changed - '"attachments" in simple_attach' @@ -708,8 +726,8 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: '(CHECK_MODE) Set tags -- IDEMPOTENCY' - check_mode: True - ec2_transit_gateway_vpc_attachment: + check_mode: true + community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' tags: CamelCase: CamelCaseValue @@ -718,7 +736,8 @@ "Tag with Space": value with space register: simple_attach - - assert: + - name: Assert that there is no change + ansible.builtin.assert: that: - simple_attach is not changed - '"attachments" in simple_attach' @@ -760,7 +779,7 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: 'Set tags -- IDEMPOTENCY' - ec2_transit_gateway_vpc_attachment: + community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' tags: CamelCase: CamelCaseValue @@ -769,7 +788,8 @@ "Tag with Space": value with space register: simple_attach - - assert: + - name: Assert that there is no change + ansible.builtin.assert: that: - simple_attach is not changed - '"attachments" in simple_attach' @@ -811,11 +831,12 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: 'Describe attachment with tags set' - ec2_transit_gateway_vpc_attachment_info: + community.aws.ec2_transit_gateway_vpc_attachment_info: id: '{{ simple_attachment_id }}' register: info - - assert: + - name: Assert that there is no change + ansible.builtin.assert: that: - info is not changed - '"attachments" in info' @@ -859,12 +880,13 @@ # ===== - name: '(CHECK_MODE) No change to tags with name set -- IDEMPOTENCY' - check_mode: True - ec2_transit_gateway_vpc_attachment: + check_mode: true + community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' register: simple_attach - - assert: + - name: Assert that there is no change + ansible.builtin.assert: that: - simple_attach is not changed - '"attachments" in simple_attach' @@ -906,11 +928,12 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: 'No change to tags with name set -- IDEMPOTENCY' - ec2_transit_gateway_vpc_attachment: + community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' register: simple_attach - - assert: + - name: Assert that there is no change + ansible.builtin.assert: that: - simple_attach is not changed - '"attachments" in simple_attach' @@ -954,8 +977,8 @@ # ===== - name: '(CHECK_MODE) Update tags' - check_mode: True - ec2_transit_gateway_vpc_attachment: + check_mode: true + community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' purge_tags: False tags: @@ -963,7 +986,8 @@ "Tag with Space": value with space 2 register: simple_attach - - assert: + - name: Assert that the test is successful + ansible.builtin.assert: that: - simple_attach is changed - '"attachments" in simple_attach' @@ -1005,7 +1029,7 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: 'Update tags' - ec2_transit_gateway_vpc_attachment: + community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' purge_tags: False tags: @@ -1013,7 +1037,8 @@ "Tag with Space": value with space 2 register: simple_attach - - assert: + - name: Assert that the test is successful + ansible.builtin.assert: that: - simple_attach is changed - '"attachments" in simple_attach' @@ -1055,8 +1080,8 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: '(CHECK_MODE) Update tags -- IDEMPOTENCY' - check_mode: True - ec2_transit_gateway_vpc_attachment: + check_mode: true + community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' purge_tags: False tags: @@ -1064,7 +1089,8 @@ "Tag with Space": value with space 2 register: simple_attach - - assert: + - name: Assert that there is no change + ansible.builtin.assert: that: - simple_attach is not changed - '"attachments" in simple_attach' @@ -1106,7 +1132,7 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: 'Update tags -- IDEMPOTENCY' - ec2_transit_gateway_vpc_attachment: + community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' purge_tags: False tags: @@ -1114,7 +1140,8 @@ "Tag with Space": value with space 2 register: simple_attach - - assert: + - name: Assert that there is no change + ansible.builtin.assert: that: - simple_attach is not changed - '"attachments" in simple_attach' @@ -1158,15 +1185,16 @@ # ===== - name: '(CHECK_MODE) Remove tags' - check_mode: True - ec2_transit_gateway_vpc_attachment: + check_mode: true + community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' tags: CamelCase: CamelCaseValue pascalCase: pascalCaseValue register: simple_attach - - assert: + - name: Assert that the test is successful + ansible.builtin.assert: that: - simple_attach is changed - '"attachments" in simple_attach' @@ -1204,14 +1232,15 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: 'Remove tags' - ec2_transit_gateway_vpc_attachment: + community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' tags: CamelCase: CamelCaseValue pascalCase: pascalCaseValue register: simple_attach - - assert: + - name: Assert that the test is successful + ansible.builtin.assert: that: - simple_attach is changed - '"attachments" in simple_attach' @@ -1249,15 +1278,16 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: '(CHECK_MODE) Remove tags -- IDEMPOTENCY' - check_mode: True - ec2_transit_gateway_vpc_attachment: + check_mode: true + community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' tags: CamelCase: CamelCaseValue pascalCase: pascalCaseValue register: simple_attach - - assert: + - name: Assert that there is no change + ansible.builtin.assert: that: - simple_attach is not changed - '"attachments" in simple_attach' @@ -1295,14 +1325,15 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: 'Remove tags -- IDEMPOTENCY' - ec2_transit_gateway_vpc_attachment: + community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' tags: CamelCase: CamelCaseValue pascalCase: pascalCaseValue register: simple_attach - - assert: + - name: Assert that there is no change + ansible.builtin.assert: that: - simple_attach is not changed - '"attachments" in simple_attach' @@ -1342,15 +1373,16 @@ # ===== - name: '(CHECK_MODE) Add tags with no purge' - check_mode: True - ec2_transit_gateway_vpc_attachment: + check_mode: true + community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' purge_tags: False tags: AnotherTag: Another Value register: simple_attach - - assert: + - name: Assert that there is no change + ansible.builtin.assert: that: - simple_attach is changed - '"attachments" in simple_attach' @@ -1390,14 +1422,15 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: 'Add tags with no purge' - ec2_transit_gateway_vpc_attachment: + community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' purge_tags: False tags: AnotherTag: Another Value register: simple_attach - - assert: + - name: Assert that the test is successful + ansible.builtin.assert: that: - simple_attach is changed - '"attachments" in simple_attach' @@ -1437,15 +1470,16 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: '(CHECK_MODE) Add tags with no purge -- IDEMPOTENCY' - check_mode: True - ec2_transit_gateway_vpc_attachment: + check_mode: true + community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' purge_tags: False tags: AnotherTag: Another Value register: simple_attach - - assert: + - name: Assert that there is no change + ansible.builtin.assert: that: - simple_attach is not changed - '"attachments" in simple_attach' @@ -1485,14 +1519,15 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: 'Add tags with no purge -- IDEMPOTENCY' - ec2_transit_gateway_vpc_attachment: + community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' purge_tags: False tags: AnotherTag: Another Value register: simple_attach - - assert: + - name: Assert that there is no change + ansible.builtin.assert: that: - simple_attach is not changed - '"attachments" in simple_attach' @@ -1534,13 +1569,14 @@ # ===== - name: '(CHECK_MODE) Remove all tags with name set' - check_mode: True - ec2_transit_gateway_vpc_attachment: + check_mode: true + community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' tags: {} register: simple_attach - - assert: + - name: Assert that the test is successful + ansible.builtin.assert: that: - simple_attach is changed - '"attachments" in simple_attach' @@ -1574,12 +1610,13 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: 'Remove all tags with name set' - ec2_transit_gateway_vpc_attachment: + community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' tags: {} register: simple_attach - - assert: + - name: Assert that the test is successful + ansible.builtin.assert: that: - simple_attach is changed - '"attachments" in simple_attach' @@ -1613,13 +1650,14 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: '(CHECK_MODE) Remove all tags with name set -- IDEMPOTENCY' - check_mode: True - ec2_transit_gateway_vpc_attachment: + check_mode: true + community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' tags: {} register: simple_attach - - assert: + - name: Assert that there is no change + ansible.builtin.assert: that: - simple_attach is not changed - '"attachments" in simple_attach' @@ -1653,12 +1691,13 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: 'Remove all tags with name set -- IDEMPOTENCY' - ec2_transit_gateway_vpc_attachment: + community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' tags: {} register: simple_attach - - assert: + - name: Assert that there is no change + ansible.builtin.assert: that: - simple_attach is not changed - '"attachments" in simple_attach' @@ -1694,13 +1733,14 @@ # ===== - name: '(CHECK_MODE) Remove all tags including name' - check_mode: True - ec2_transit_gateway_vpc_attachment: + check_mode: true + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' tags: {} register: simple_attach - - assert: + - name: Assert that the test is successful + ansible.builtin.assert: that: - simple_attach is changed - '"attachments" in simple_attach' @@ -1732,12 +1772,13 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: 'Remove all tags including name' - ec2_transit_gateway_vpc_attachment: + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' tags: {} register: simple_attach - - assert: + - name: Assert that the test is successful + ansible.builtin.assert: that: - simple_attach is changed - '"attachments" in simple_attach' @@ -1769,13 +1810,14 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: '(CHECK_MODE) Remove all tags including name -- IDEMPOTENCY' - check_mode: True - ec2_transit_gateway_vpc_attachment: + check_mode: true + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' tags: {} register: simple_attach - - assert: + - name: Assert that there is no change + ansible.builtin.assert: that: - simple_attach is not changed - '"attachments" in simple_attach' @@ -1807,12 +1849,13 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: 'Remove all tags including name -- IDEMPOTENCY' - ec2_transit_gateway_vpc_attachment: + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' tags: {} register: simple_attach - - assert: + - name: Assert that there is no change + ansible.builtin.assert: that: - simple_attach is not changed - '"attachments" in simple_attach' @@ -1847,13 +1890,14 @@ # Options - name: '(CHECK_MODE) Set IPv6 support' - check_mode: True - ec2_transit_gateway_vpc_attachment: + check_mode: true + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' - ipv6_support: True + ipv6_support: true register: simple_attach - - assert: + - name: Assert that the test is successful + ansible.builtin.assert: that: - simple_attach is changed - '"attachments" in simple_attach' @@ -1885,12 +1929,13 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: 'Set IPv6 support' - ec2_transit_gateway_vpc_attachment: + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' - ipv6_support: True + ipv6_support: true register: simple_attach - - assert: + - name: Assert that the test is successful + ansible.builtin.assert: that: - simple_attach is changed - '"attachments" in simple_attach' @@ -1922,13 +1967,14 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: '(CHECK_MODE) Set IPv6 support -- IDEMPOTENCY' - check_mode: True - ec2_transit_gateway_vpc_attachment: + check_mode: true + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' - ipv6_support: True + ipv6_support: true register: simple_attach - - assert: + - name: Assert that there is no change + ansible.builtin.assert: that: - simple_attach is not changed - '"attachments" in simple_attach' @@ -1960,12 +2006,13 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: 'Set IPv6 support -- IDEMPOTENCY' - ec2_transit_gateway_vpc_attachment: + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' - ipv6_support: True + ipv6_support: true register: simple_attach - - assert: + - name: Assert that there is no change + ansible.builtin.assert: that: - simple_attach is not changed - '"attachments" in simple_attach' @@ -1999,13 +2046,14 @@ # ===== - name: '(CHECK_MODE) Set DNS support' - check_mode: True - ec2_transit_gateway_vpc_attachment: + check_mode: true + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' dns_support: False register: simple_attach - - assert: + - name: Assert that the test is successful + ansible.builtin.assert: that: - simple_attach is changed - '"attachments" in simple_attach' @@ -2037,12 +2085,13 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: 'Set DNS support' - ec2_transit_gateway_vpc_attachment: + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' dns_support: False register: simple_attach - - assert: + - name: Assert that the test is successful + ansible.builtin.assert: that: - simple_attach is changed - '"attachments" in simple_attach' @@ -2074,13 +2123,14 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: '(CHECK_MODE) Set DNS support -- IDEMPOTENCY' - check_mode: True - ec2_transit_gateway_vpc_attachment: + check_mode: true + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' dns_support: False register: simple_attach - - assert: + - name: Assert that there is no change + ansible.builtin.assert: that: - simple_attach is not changed - '"attachments" in simple_attach' @@ -2112,12 +2162,13 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: 'Set DNS support -- IDEMPOTENCY' - ec2_transit_gateway_vpc_attachment: + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' dns_support: False register: simple_attach - - assert: + - name: Assert that there is no change + ansible.builtin.assert: that: - simple_attach is not changed - '"attachments" in simple_attach' @@ -2151,13 +2202,14 @@ # ===== - name: '(CHECK_MODE) Set Appliance Mode support' - check_mode: True - ec2_transit_gateway_vpc_attachment: + check_mode: true + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' - appliance_mode_support: True + appliance_mode_support: true register: simple_attach - - assert: + - name: Assert that the test is successful + ansible.builtin.assert: that: - simple_attach is changed - '"attachments" in simple_attach' @@ -2189,12 +2241,13 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: 'Set Appliance Mode support' - ec2_transit_gateway_vpc_attachment: + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' - appliance_mode_support: True + appliance_mode_support: true register: simple_attach - - assert: + - name: Assert that the test is successful + ansible.builtin.assert: that: - simple_attach is changed - '"attachments" in simple_attach' @@ -2226,13 +2279,14 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: '(CHECK_MODE) Set Appliance Mode support -- IDEMPOTENCY' - check_mode: True - ec2_transit_gateway_vpc_attachment: + check_mode: true + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' - appliance_mode_support: True + appliance_mode_support: true register: simple_attach - - assert: + - name: Assert that there is no change + ansible.builtin.assert: that: - simple_attach is not changed - '"attachments" in simple_attach' @@ -2264,12 +2318,13 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: 'Set Appliance Mode support -- IDEMPOTENCY' - ec2_transit_gateway_vpc_attachment: + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' - appliance_mode_support: True + appliance_mode_support: true register: simple_attach - - assert: + - name: Assert that there is no change + ansible.builtin.assert: that: - simple_attach is not changed - '"attachments" in simple_attach' @@ -2303,13 +2358,14 @@ # ===== - name: '(CHECK_MODE) Update IPv6 support' - check_mode: True - ec2_transit_gateway_vpc_attachment: + check_mode: true + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' ipv6_support: False register: simple_attach - - assert: + - name: Assert that the test is successful + ansible.builtin.assert: that: - simple_attach is changed - '"attachments" in simple_attach' @@ -2341,12 +2397,13 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: 'Update IPv6 support' - ec2_transit_gateway_vpc_attachment: + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' ipv6_support: False register: simple_attach - - assert: + - name: Assert that the test is successful + ansible.builtin.assert: that: - simple_attach is changed - '"attachments" in simple_attach' @@ -2378,13 +2435,14 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: '(CHECK_MODE) Update IPv6 support -- IDEMPOTENCY' - check_mode: True - ec2_transit_gateway_vpc_attachment: + check_mode: true + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' ipv6_support: False register: simple_attach - - assert: + - name: Assert that there is no change + ansible.builtin.assert: that: - simple_attach is not changed - '"attachments" in simple_attach' @@ -2416,12 +2474,13 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: 'Update IPv6 support -- IDEMPOTENCY' - ec2_transit_gateway_vpc_attachment: + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' ipv6_support: False register: simple_attach - - assert: + - name: Assert that there is no change + ansible.builtin.assert: that: - simple_attach is not changed - '"attachments" in simple_attach' @@ -2455,13 +2514,14 @@ # ===== - name: '(CHECK_MODE) Update DNS support' - check_mode: True - ec2_transit_gateway_vpc_attachment: + check_mode: true + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' - dns_support: True + dns_support: true register: simple_attach - - assert: + - name: Assert that the test is successful + ansible.builtin.assert: that: - simple_attach is changed - '"attachments" in simple_attach' @@ -2493,12 +2553,13 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: 'Update DNS support' - ec2_transit_gateway_vpc_attachment: + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' - dns_support: True + dns_support: true register: simple_attach - - assert: + - name: Assert that the test is successful + ansible.builtin.assert: that: - simple_attach is changed - '"attachments" in simple_attach' @@ -2530,13 +2591,14 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: '(CHECK_MODE) Update DNS support -- IDEMPOTENCY' - check_mode: True - ec2_transit_gateway_vpc_attachment: + check_mode: true + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' - dns_support: True + dns_support: true register: simple_attach - - assert: + - name: Assert that there is no change + ansible.builtin.assert: that: - simple_attach is not changed - '"attachments" in simple_attach' @@ -2568,12 +2630,13 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: 'Update DNS support -- IDEMPOTENCY' - ec2_transit_gateway_vpc_attachment: + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' - dns_support: True + dns_support: true register: simple_attach - - assert: + - name: Assert that there is no change + ansible.builtin.assert: that: - simple_attach is not changed - '"attachments" in simple_attach' @@ -2607,13 +2670,14 @@ # ===== - name: '(CHECK_MODE) Update Appliance Mode support' - check_mode: True - ec2_transit_gateway_vpc_attachment: + check_mode: true + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' appliance_mode_support: False register: simple_attach - - assert: + - name: Assert that the test is successful + ansible.builtin.assert: that: - simple_attach is changed - '"attachments" in simple_attach' @@ -2645,12 +2709,13 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: 'Update Appliance Mode support' - ec2_transit_gateway_vpc_attachment: + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' appliance_mode_support: False register: simple_attach - - assert: + - name: Assert that the test is successful + ansible.builtin.assert: that: - simple_attach is changed - '"attachments" in simple_attach' @@ -2682,13 +2747,14 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: '(CHECK_MODE) Update Appliance Mode support -- IDEMPOTENCY' - check_mode: True - ec2_transit_gateway_vpc_attachment: + check_mode: true + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' appliance_mode_support: False register: simple_attach - - assert: + - name: Assert that there is no change + ansible.builtin.assert: that: - simple_attach is not changed - '"attachments" in simple_attach' @@ -2720,12 +2786,13 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: 'Update Appliance Mode support -- IDEMPOTENCY' - ec2_transit_gateway_vpc_attachment: + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' appliance_mode_support: False register: simple_attach - - assert: + - name: Assert that there is no change + ansible.builtin.assert: that: - simple_attach is not changed - '"attachments" in simple_attach' @@ -2760,135 +2827,144 @@ # Subnet Management - name: '(CHECK_MODE) Try to add subnet from a different VPC - no purge' - check_mode: True - ec2_transit_gateway_vpc_attachment: + check_mode: true + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_b_2 }}' purge_subnets: False register: simple_attach - ignore_errors: True + ignore_errors: true - - assert: + - name: Assert that the test failed + ansible.builtin.assert: that: - simple_attach is failed - name: 'Try to add subnet from a different VPC - no purge' - ec2_transit_gateway_vpc_attachment: + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_b_2 }}' purge_subnets: False register: simple_attach - ignore_errors: True + ignore_errors: true - - assert: + - name: Assert that the test failed + ansible.builtin.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: + check_mode: true + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_a_1 }}' - '{{ subnet_id_b_2 }}' - purge_subnets: True + purge_subnets: true register: simple_attach - ignore_errors: True + ignore_errors: true - - assert: + - name: Assert that the test failed + ansible.builtin.assert: that: - simple_attach is failed - name: 'Try to add subnet from a different VPC - with purge' - ec2_transit_gateway_vpc_attachment: + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_a_1 }}' - '{{ subnet_id_b_2 }}' - purge_subnets: True + purge_subnets: true register: simple_attach - ignore_errors: True + ignore_errors: true - - assert: + - name: Assert that the test failed + ansible.builtin.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: + check_mode: true + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_b_1a }}' purge_subnets: False register: simple_attach - ignore_errors: True + ignore_errors: true - - assert: + - name: Assert that the test failed + ansible.builtin.assert: that: - simple_attach is failed - name: 'Try to add subnet in the same AZ - no purge' - ec2_transit_gateway_vpc_attachment: + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_a_1a }}' purge_subnets: False register: simple_attach - ignore_errors: True + ignore_errors: true - - assert: + - name: Assert that the test failed + ansible.builtin.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: + check_mode: true + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_a_1 }}' - '{{ subnet_id_a_1a }}' - purge_subnets: True + purge_subnets: true register: simple_attach - ignore_errors: True + ignore_errors: true - - assert: + - name: Assert that the test failed + ansible.builtin.assert: that: - simple_attach is failed - name: 'Try to add subnet in the same AZ - with purge' - ec2_transit_gateway_vpc_attachment: + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_a_1 }}' - '{{ subnet_id_a_1a }}' - purge_subnets: True + purge_subnets: true register: simple_attach - ignore_errors: True + ignore_errors: true - - assert: + - name: Assert that the test failed + ansible.builtin.assert: that: - simple_attach is failed # ===== - name: '(CHECK_MODE) Add subnet - without purge' - check_mode: True - ec2_transit_gateway_vpc_attachment: + check_mode: true + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_a_2 }}' purge_subnets: False register: simple_attach - - assert: + - name: Assert that the test is successful + ansible.builtin.assert: that: - simple_attach is changed - '"attachments" in simple_attach' @@ -2921,14 +2997,15 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: 'Add subnet - without purge' - ec2_transit_gateway_vpc_attachment: + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_a_2 }}' purge_subnets: False register: simple_attach - - assert: + - name: Assert that the test is successful + ansible.builtin.assert: that: - simple_attach is changed - '"attachments" in simple_attach' @@ -2961,15 +3038,16 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: '(CHECK_MODE) Add subnet - without purge -- IDEMPOTENCY' - check_mode: True - ec2_transit_gateway_vpc_attachment: + check_mode: true + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_a_2 }}' purge_subnets: False register: simple_attach - - assert: + - name: Assert that there is no change + ansible.builtin.assert: that: - simple_attach is not changed - '"attachments" in simple_attach' @@ -3002,14 +3080,15 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: 'Add subnet - without purge -- IDEMPOTENCY' - ec2_transit_gateway_vpc_attachment: + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_a_2 }}' purge_subnets: False register: simple_attach - - assert: + - name: Assert that there is no change + ansible.builtin.assert: that: - simple_attach is not changed - '"attachments" in simple_attach' @@ -3044,17 +3123,18 @@ # ===== - name: '(CHECK_MODE) Add subnet - with purge' - check_mode: True - ec2_transit_gateway_vpc_attachment: + check_mode: true + community.aws.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 + purge_subnets: true register: simple_attach - - assert: + - name: Assert that the test is successful + ansible.builtin.assert: that: - simple_attach is changed - '"attachments" in simple_attach' @@ -3088,16 +3168,17 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: 'Add subnet - with purge' - ec2_transit_gateway_vpc_attachment: + community.aws.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 + purge_subnets: true register: simple_attach - - assert: + - name: Assert that the test is successful + ansible.builtin.assert: that: - simple_attach is changed - '"attachments" in simple_attach' @@ -3131,17 +3212,18 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: '(CHECK_MODE) Add subnet - with purge -- IDEMPOTENCY' - check_mode: True - ec2_transit_gateway_vpc_attachment: + check_mode: true + community.aws.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 + purge_subnets: true register: simple_attach - - assert: + - name: Assert that there is no change + ansible.builtin.assert: that: - simple_attach is not changed - '"attachments" in simple_attach' @@ -3175,16 +3257,17 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: 'Add subnet - with purge -- IDEMPOTENCY' - ec2_transit_gateway_vpc_attachment: + community.aws.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 + purge_subnets: true register: simple_attach - - assert: + - name: Assert that there is no change + ansible.builtin.assert: that: - simple_attach is not changed - '"attachments" in simple_attach' @@ -3220,16 +3303,17 @@ # ===== - name: '(CHECK_MODE) Remove subnet' - check_mode: True - ec2_transit_gateway_vpc_attachment: + check_mode: true + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_a_2 }}' - '{{ subnet_id_a_3 }}' - purge_subnets: True + purge_subnets: true register: simple_attach - - assert: + - name: Assert that the test is successful + ansible.builtin.assert: that: - simple_attach is changed - '"attachments" in simple_attach' @@ -3262,15 +3346,16 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: 'Remove subnet' - ec2_transit_gateway_vpc_attachment: + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_a_2 }}' - '{{ subnet_id_a_3 }}' - purge_subnets: True + purge_subnets: true register: simple_attach - - assert: + - name: Assert that the test is successful + ansible.builtin.assert: that: - simple_attach is changed - '"attachments" in simple_attach' @@ -3303,16 +3388,17 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: '(CHECK_MODE) Remove subnet -- IDEMPOTENCY' - check_mode: True - ec2_transit_gateway_vpc_attachment: + check_mode: true + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_a_2 }}' - '{{ subnet_id_a_3 }}' - purge_subnets: True + purge_subnets: true register: simple_attach - - assert: + - name: Assert that there is no change + ansible.builtin.assert: that: - simple_attach is not changed - '"attachments" in simple_attach' @@ -3345,15 +3431,16 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: 'Remove subnet -- IDEMPOTENCY' - ec2_transit_gateway_vpc_attachment: + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_a_2 }}' - '{{ subnet_id_a_3 }}' - purge_subnets: True + purge_subnets: true register: simple_attach - - assert: + - name: Assert that there is no change + ansible.builtin.assert: that: - simple_attach is not changed - '"attachments" in simple_attach' @@ -3388,16 +3475,17 @@ # ===== - name: '(CHECK_MODE) Remove and add subnet' - check_mode: True - ec2_transit_gateway_vpc_attachment: + check_mode: true + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_a_1 }}' - '{{ subnet_id_a_2 }}' - purge_subnets: True + purge_subnets: true register: simple_attach - - assert: + - name: Assert that the test is successful + ansible.builtin.assert: that: - simple_attach is changed - '"attachments" in simple_attach' @@ -3430,15 +3518,16 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: 'Remove and add subnet' - ec2_transit_gateway_vpc_attachment: + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_a_1 }}' - '{{ subnet_id_a_2 }}' - purge_subnets: True + purge_subnets: true register: simple_attach - - assert: + - name: Assert that the test is successful + ansible.builtin.assert: that: - simple_attach is changed - '"attachments" in simple_attach' @@ -3471,16 +3560,17 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: '(CHECK_MODE) Remove and add subnet -- IDEMPOTENCY' - check_mode: True - ec2_transit_gateway_vpc_attachment: + check_mode: true + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_a_1 }}' - '{{ subnet_id_a_2 }}' - purge_subnets: True + purge_subnets: true register: simple_attach - - assert: + - name: Assert that there is no change + ansible.builtin.assert: that: - simple_attach is not changed - '"attachments" in simple_attach' @@ -3513,15 +3603,16 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: 'Remove and add subnet -- IDEMPOTENCY' - ec2_transit_gateway_vpc_attachment: + community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_a_1 }}' - '{{ subnet_id_a_2 }}' - purge_subnets: True + purge_subnets: true register: simple_attach - - assert: + - name: Assert that there is no change + ansible.builtin.assert: that: - simple_attach is not changed - '"attachments" in simple_attach' @@ -3557,55 +3648,59 @@ # Deletion - name: '(CHECK_MODE) Delete an attachment - minimal parameters' - check_mode: True - ec2_transit_gateway_vpc_attachment: + check_mode: true + community.aws.ec2_transit_gateway_vpc_attachment: state: absent id: '{{ simple_attachment_id }}' - wait: False + wait: false register: simple_attach - - assert: + - name: Assert that the test is successful + ansible.builtin.assert: that: - simple_attach is changed - name: 'Delete an attachment - minimal parameters' - ec2_transit_gateway_vpc_attachment: + community.aws.ec2_transit_gateway_vpc_attachment: state: absent id: '{{ simple_attachment_id }}' - wait: False + wait: false register: simple_attach - - assert: + - name: Assert that the test is successful + ansible.builtin.assert: that: - simple_attach is changed - name: '(CHECK_MODE) Delete an attachment - minimal parameters -- IDEMPOTENCY' - check_mode: True - ec2_transit_gateway_vpc_attachment: + check_mode: true + community.aws.ec2_transit_gateway_vpc_attachment: state: absent id: '{{ simple_attachment_id }}' wait: False register: simple_attach - - assert: + - name: Assert that there is no change + ansible.builtin.assert: that: - simple_attach is not changed - name: 'Delete an attachment - minimal parameters -- IDEMPOTENCY' - ec2_transit_gateway_vpc_attachment: + community.aws.ec2_transit_gateway_vpc_attachment: state: absent id: '{{ simple_attachment_id }}' wait: False register: simple_attach - - assert: + - name: Assert that there is no change + ansible.builtin.assert: that: - simple_attach is not changed always: - name: 'Delete attachment' - ec2_transit_gateway_vpc_attachment: + community.aws.ec2_transit_gateway_vpc_attachment: state: absent id: '{{ simple_attachment_id }}' wait: False - ignore_errors: True + ignore_errors: true From aeaa375b25c7b9f51cc0b11901fedc6baed3a5db Mon Sep 17 00:00:00 2001 From: Alina Buzachis Date: Fri, 18 Oct 2024 14:09:27 +0200 Subject: [PATCH 16/25] Update runtime --- meta/runtime.yml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/meta/runtime.yml b/meta/runtime.yml index b62a89aae8d..9331be82a56 100644 --- a/meta/runtime.yml +++ b/meta/runtime.yml @@ -52,6 +52,8 @@ action_groups: - ec2_spot_instance_info - ec2_tag - ec2_tag_info + - ec2_transit_gateway_vpc_attachment + - ec2_transit_gateway_vpc_attachment_info - ec2_vol - ec2_vol_info - ec2_vpc_dhcp_option @@ -164,14 +166,14 @@ plugin_routing: rds_param_group: redirect: amazon.aws.rds_instance_param_group deprecation: - removal_version: 10.0.0 - warning_text: >- - rds_param_group has been renamed to rds_instance_param_group. - Please update your tasks. + removal_version: 10.0.0 + warning_text: >- + rds_param_group has been renamed to rds_instance_param_group. + Please update your tasks. lookup: aws_ssm: # Deprecation for this alias should not *start* prior to 2024-09-01 redirect: amazon.aws.ssm_parameter aws_secret: # Deprecation for this alias should not *start* prior to 2024-09-01 - redirect: amazon.aws.secretsmanager_secret + redirect: amazon.aws.secretsmanager_secret \ No newline at end of file From 207faba4a4ff4f1f59cc7a18d678f7b571f9dcd1 Mon Sep 17 00:00:00 2001 From: Alina Buzachis Date: Fri, 18 Oct 2024 14:09:27 +0200 Subject: [PATCH 17/25] Update FQDN --- plugins/modules/ec2_transit_gateway_vpc_attachment.py | 6 +++--- plugins/modules/ec2_transit_gateway_vpc_attachment_info.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/modules/ec2_transit_gateway_vpc_attachment.py b/plugins/modules/ec2_transit_gateway_vpc_attachment.py index 9ecdeb3b2bb..60139da7806 100644 --- a/plugins/modules/ec2_transit_gateway_vpc_attachment.py +++ b/plugins/modules/ec2_transit_gateway_vpc_attachment.py @@ -106,7 +106,7 @@ EXAMPLES = r""" - name: Create a Transit Gateway attachment - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: state: "present" transit_gateway: "tgw-123456789abcdef01" name: "AnsibleTest-1" @@ -122,7 +122,7 @@ TestTag: "changed data in Test Tag" - name: Set sub options on a Transit Gateway attachment - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: state: "present" id: "tgw-attach-0c0c5fd0b0f01d1c9" name: "AnsibleTest-1" @@ -132,7 +132,7 @@ appliance_mode_support: true - name: Delete the transit gateway - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: state: "absent" id: "tgw-attach-0c0c5fd0b0f01d1c9" """ diff --git a/plugins/modules/ec2_transit_gateway_vpc_attachment_info.py b/plugins/modules/ec2_transit_gateway_vpc_attachment_info.py index 2ec87583a94..f6ca5d1da30 100644 --- a/plugins/modules/ec2_transit_gateway_vpc_attachment_info.py +++ b/plugins/modules/ec2_transit_gateway_vpc_attachment_info.py @@ -48,16 +48,16 @@ EXAMPLES = r""" - name: Describe a specific Transit Gateway attachment - community.aws.ec2_transit_gateway_vpc_attachment_info: + amazon.aws.ec2_transit_gateway_vpc_attachment_info: id: "tgw-attach-0123456789abcdef0" - name: Describe all attachments attached to a transit gateway - community.aws.ec2_transit_gateway_vpc_attachment_info: + amazon.aws.ec2_transit_gateway_vpc_attachment_info: filters: transit-gateway-id: "tgw-0fedcba9876543210" - name: Describe all attachments in an account - community.aws.ec2_transit_gateway_vpc_attachment_info: + amazon.aws.ec2_transit_gateway_vpc_attachment_info: """ RETURN = r""" From 07fc71f8e61d43f9b5800e85b2065db92a68941a Mon Sep 17 00:00:00 2001 From: Alina Buzachis Date: Fri, 18 Oct 2024 14:09:28 +0200 Subject: [PATCH 18/25] Update AnsibleAWSModule import path --- plugins/modules/ec2_transit_gateway_vpc_attachment.py | 2 +- plugins/modules/ec2_transit_gateway_vpc_attachment_info.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/modules/ec2_transit_gateway_vpc_attachment.py b/plugins/modules/ec2_transit_gateway_vpc_attachment.py index 60139da7806..7a9bcc1d6eb 100644 --- a/plugins/modules/ec2_transit_gateway_vpc_attachment.py +++ b/plugins/modules/ec2_transit_gateway_vpc_attachment.py @@ -228,7 +228,7 @@ from ansible_collections.amazon.aws.plugins.module_utils.transformation import boto3_resource_to_ansible_dict -from ansible_collections.community.aws.plugins.module_utils.modules import AnsibleCommunityAWSModule as AnsibleAWSModule +from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule from ansible_collections.community.aws.plugins.module_utils.transitgateway import TransitGatewayVpcAttachmentManager from ansible_collections.community.aws.plugins.module_utils.transitgateway import find_existing_attachment from ansible_collections.community.aws.plugins.module_utils.transitgateway import get_states diff --git a/plugins/modules/ec2_transit_gateway_vpc_attachment_info.py b/plugins/modules/ec2_transit_gateway_vpc_attachment_info.py index f6ca5d1da30..2dce78aa1e5 100644 --- a/plugins/modules/ec2_transit_gateway_vpc_attachment_info.py +++ b/plugins/modules/ec2_transit_gateway_vpc_attachment_info.py @@ -156,7 +156,7 @@ from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list from ansible_collections.amazon.aws.plugins.module_utils.transformation import boto3_resource_to_ansible_dict -from ansible_collections.community.aws.plugins.module_utils.modules import AnsibleCommunityAWSModule as AnsibleAWSModule +from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule from ansible_collections.community.aws.plugins.module_utils.transitgateway import get_states From 2f6cd79172e35ca17033166a4a67fab9b003d628 Mon Sep 17 00:00:00 2001 From: Alina Buzachis Date: Fri, 18 Oct 2024 14:09:28 +0200 Subject: [PATCH 19/25] Remove collection reference inside the tests --- .../defaults/main.yml | 4 +- .../meta/main.yml | 2 +- .../tasks/cleanup.yml | 7 +- .../tasks/complex.yml | 28 +- .../tasks/main.yml | 13 +- .../tasks/setup.yml | 5 +- .../tasks/simple.yml | 266 +++++++++--------- 7 files changed, 160 insertions(+), 165 deletions(-) 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 index c9727746555..ded63478d39 100644 --- a/tests/integration/targets/ec2_transit_gateway_vpc_attachment/defaults/main.yml +++ b/tests/integration/targets/ec2_transit_gateway_vpc_attachment/defaults/main.yml @@ -1,6 +1,6 @@ -_resource_prefix: 'AnsibleTest' +_resource_prefix: AnsibleTest #_resource_prefix: 'AnsibleTest-{{ tiny_prefix }}-TGW-Attach' -cidr_prefix: '10.{{ 255 | random(seed=_resource_prefix) }}' +cidr_prefix: 10.{{ 255 | random(seed=_resource_prefix) }} tgw_name: '{{ _resource_prefix }}' tgw_name_2: '{{ _resource_prefix }}-2' vpc_name_a: '{{ _resource_prefix }}-1' 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 index aef5ca0ee57..2bff8543af2 100644 --- a/tests/integration/targets/ec2_transit_gateway_vpc_attachment/meta/main.yml +++ b/tests/integration/targets/ec2_transit_gateway_vpc_attachment/meta/main.yml @@ -1,2 +1,2 @@ dependencies: - - role: setup_ec2_facts +- 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 index b917be3907a..7448fce7b6a 100644 --- a/tests/integration/targets/ec2_transit_gateway_vpc_attachment/tasks/cleanup.yml +++ b/tests/integration/targets/ec2_transit_gateway_vpc_attachment/tasks/cleanup.yml @@ -1,4 +1,3 @@ ---- - name: Describe all attachments on our VPC community.aws.ec2_transit_gateway_vpc_attachment_info: filters: @@ -40,7 +39,7 @@ vpc_id: '{{ vpc_id_b }}' - cidr: '{{ subnet_cidr_a_1a }}' vpc_id: '{{ vpc_id_a }}' - ignore_errors: True + ignore_errors: true - name: Delete VPCs to attach to TGW amazon.aws.ec2_vpc_net: @@ -57,8 +56,8 @@ - name: Gather info about all transit gateways community.aws.ec2_transit_gateway_info: transit_gateway_ids: - - '{{ tgw_id }}' - - '{{ tgw_id_2 }}' + - '{{ tgw_id }}' + - '{{ tgw_id_2 }}' - name: Delete Transit Gateways community.aws.ec2_transit_gateway: 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 index 2a234bb165f..1208e480cb3 100644 --- a/tests/integration/targets/ec2_transit_gateway_vpc_attachment/tasks/complex.yml +++ b/tests/integration/targets/ec2_transit_gateway_vpc_attachment/tasks/complex.yml @@ -1,4 +1,3 @@ ---- # 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 @@ -17,8 +16,8 @@ - '{{ subnet_id_b_1 }}' - '{{ subnet_id_b_2 }}' tags: - tagA: 'example Value' - Tag_B: 'second value' + tagA: example Value + Tag_B: second value appliance_mode_support: true ipv6_support: true register: complex_attach @@ -61,8 +60,8 @@ - '{{ subnet_id_b_1 }}' - '{{ subnet_id_b_2 }}' tags: - tagA: 'example Value' - Tag_B: 'second value' + tagA: example Value + Tag_B: second value appliance_mode_support: true ipv6_support: true register: complex_attach @@ -108,7 +107,8 @@ - name: Save Attachment ID set_fact: - complex_attachment_id: '{{ complex_attach.attachments[0].transit_gateway_attachment_id }}' + complex_attachment_id: '{{ complex_attach.attachments[0].transit_gateway_attachment_id + }}' - name: (CHECK_MODE) Create an attachment - complex parameters -- IDEMPOTENCY check_mode: true @@ -119,8 +119,8 @@ - '{{ subnet_id_b_1 }}' - '{{ subnet_id_b_2 }}' tags: - tagA: 'example Value' - Tag_B: 'second value' + tagA: example Value + Tag_B: second value appliance_mode_support: true ipv6_support: true register: complex_attach @@ -172,8 +172,8 @@ - '{{ subnet_id_b_1 }}' - '{{ subnet_id_b_2 }}' tags: - tagA: 'example Value' - Tag_B: 'second value' + tagA: example Value + Tag_B: second value appliance_mode_support: true ipv6_support: true register: complex_attach @@ -230,7 +230,7 @@ purge_subnets: true tags: tagC: '3' - Tag_D: 'Hello again dear world' + Tag_D: Hello again dear world purge_tags: false dns_support: false ipv6_support: false @@ -287,7 +287,7 @@ purge_subnets: true tags: tagC: '3' - Tag_D: 'Hello again dear world' + Tag_D: Hello again dear world purge_tags: false dns_support: false ipv6_support: false @@ -345,7 +345,7 @@ purge_subnets: true tags: tagC: '3' - Tag_D: 'Hello again dear world' + Tag_D: Hello again dear world purge_tags: false dns_support: false ipv6_support: false @@ -402,7 +402,7 @@ purge_subnets: true tags: tagC: '3' - Tag_D: 'Hello again dear world' + Tag_D: Hello again dear world purge_tags: false dns_support: false ipv6_support: false 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 index ce9659473f6..ecec94bff5a 100644 --- a/tests/integration/targets/ec2_transit_gateway_vpc_attachment/tasks/main.yml +++ b/tests/integration/targets/ec2_transit_gateway_vpc_attachment/tasks/main.yml @@ -1,7 +1,4 @@ ---- -- name: 'ec2_transit_gateway_vpc_attachment integration tests' - collections: - - amazon.aws +- name: ec2_transit_gateway_vpc_attachment integration tests module_defaults: group/aws: access_key: '{{ aws_access_key }}' @@ -11,14 +8,14 @@ block: # Prepares various resources - - include_tasks: 'setup.yml' + - include_tasks: setup.yml # Tests create / update on parameters simulatniously - - include_tasks: 'complex.yml' + - include_tasks: complex.yml # Tests create / update / delete on individual parameters - - include_tasks: 'simple.yml' + - include_tasks: simple.yml always: # Cleanup after ourselves - - include_tasks: 'cleanup.yml' + - 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 index f3b3e86f387..b97883948eb 100644 --- a/tests/integration/targets/ec2_transit_gateway_vpc_attachment/tasks/setup.yml +++ b/tests/integration/targets/ec2_transit_gateway_vpc_attachment/tasks/setup.yml @@ -1,4 +1,3 @@ ---- - name: Pick 2 AZs available for use set_fact: subnet_az_a_1: '{{ ec2_availability_zone_names[0] }}' @@ -14,9 +13,9 @@ tags: Name: '{{ item.name }}' loop: - - description: 'Transit Gateway for testing community.aws.ec2_transit_gateway_attachment' + - description: Transit Gateway for testing community.aws.ec2_transit_gateway_attachment name: '{{ tgw_name }}' - - description: 'Second Transit Gateway for testing community.aws.ec2_transit_gateway_attachment' + - description: Second Transit Gateway for testing community.aws.ec2_transit_gateway_attachment name: '{{ tgw_name_2 }}' register: create_tgws 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 index 2cee6627e2c..6b62ae1b92f 100644 --- a/tests/integration/targets/ec2_transit_gateway_vpc_attachment/tasks/simple.yml +++ b/tests/integration/targets/ec2_transit_gateway_vpc_attachment/tasks/simple.yml @@ -1,4 +1,3 @@ ---- # ============================================================================= # Creation - block: @@ -67,7 +66,8 @@ - name: Save Attachment ID ansible.builtin.set_fact: - simple_attachment_id: '{{ simple_attach.attachments[0].transit_gateway_attachment_id }}' + simple_attachment_id: '{{ simple_attach.attachments[0].transit_gateway_attachment_id + }}' - name: (CHECK_MODE) Create an attachment - minimal parameters -- IDEMPOTENCY check_mode: true @@ -109,7 +109,7 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: 'Create an attachment - minimal parameters -- IDEMPOTENCY' + - name: Create an attachment - minimal parameters -- IDEMPOTENCY community.aws.ec2_transit_gateway_vpc_attachment: transit_gateway: '{{ tgw_id }}' subnets: @@ -190,7 +190,7 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: 'By Id - minimal parameters -- IDEMPOTENCY' + - name: By Id - minimal parameters -- IDEMPOTENCY community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: @@ -232,7 +232,7 @@ # ============================================================================= # Set a name - - name: '(CHECK_MODE) Set name' + - name: (CHECK_MODE) Set name check_mode: true community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' @@ -273,7 +273,7 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: 'Set name' + - name: Set name community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' name: '{{ attachment_name }}' @@ -313,7 +313,7 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: '(CHECK_MODE) Set name -- IDEMPOTENCY' + - name: (CHECK_MODE) Set name -- IDEMPOTENCY check_mode: true community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' @@ -354,7 +354,7 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: 'Set name -- IDEMPOTENCY' + - name: Set name -- IDEMPOTENCY community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' name: '{{ attachment_name }}' @@ -396,7 +396,7 @@ # ===== - - name: '(CHECK_MODE) By Name - minimal parameters -- IDEMPOTENCY' + - name: (CHECK_MODE) By Name - minimal parameters -- IDEMPOTENCY check_mode: true community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' @@ -438,7 +438,7 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: 'By Name - minimal parameters -- IDEMPOTENCY' + - name: By Name - minimal parameters -- IDEMPOTENCY community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' subnets: @@ -482,7 +482,7 @@ # ============================================================================= # Describe - - name: 'Describe all attachments' + - name: Describe all attachments community.aws.ec2_transit_gateway_vpc_attachment_info: register: info @@ -509,7 +509,7 @@ vars: attachment: '{{ info.attachments[0] }}' - - name: 'Describe attachments on a specific VPC' + - name: Describe attachments on a specific VPC community.aws.ec2_transit_gateway_vpc_attachment_info: filters: transit-gateway-id: '{{ tgw_id }}' @@ -539,7 +539,7 @@ vars: attachment: '{{ info.attachments[0] }}' - - name: 'Describe attachment with a specific name' + - name: Describe attachment with a specific name community.aws.ec2_transit_gateway_vpc_attachment_info: name: '{{ attachment_name }}' register: info @@ -578,7 +578,7 @@ vars: attachment: '{{ info.attachments[0] }}' - - name: 'Describe attachment by ID' + - name: Describe attachment by ID community.aws.ec2_transit_gateway_vpc_attachment_info: id: '{{ simple_attachment_id }}' register: info @@ -620,7 +620,7 @@ # ============================================================================= # Tag attachment - - name: '(CHECK_MODE) Set tags' + - name: (CHECK_MODE) Set tags check_mode: true community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' @@ -628,7 +628,7 @@ CamelCase: CamelCaseValue pascalCase: pascalCaseValue snake_case: snake_case_value - "Tag with Space": value with space + Tag with Space: value with space register: simple_attach - name: Assert that 'Set tags' is successful @@ -673,14 +673,14 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: 'Set tags' + - name: Set tags community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' tags: CamelCase: CamelCaseValue pascalCase: pascalCaseValue snake_case: snake_case_value - "Tag with Space": value with space + Tag with Space: value with space register: simple_attach - name: Assert that 'Set tags' is successful @@ -725,7 +725,7 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: '(CHECK_MODE) Set tags -- IDEMPOTENCY' + - name: (CHECK_MODE) Set tags -- IDEMPOTENCY check_mode: true community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' @@ -733,7 +733,7 @@ CamelCase: CamelCaseValue pascalCase: pascalCaseValue snake_case: snake_case_value - "Tag with Space": value with space + Tag with Space: value with space register: simple_attach - name: Assert that there is no change @@ -778,14 +778,14 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: 'Set tags -- IDEMPOTENCY' + - name: Set tags -- IDEMPOTENCY community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' tags: CamelCase: CamelCaseValue pascalCase: pascalCaseValue snake_case: snake_case_value - "Tag with Space": value with space + Tag with Space: value with space register: simple_attach - name: Assert that there is no change @@ -830,7 +830,7 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: 'Describe attachment with tags set' + - name: Describe attachment with tags set community.aws.ec2_transit_gateway_vpc_attachment_info: id: '{{ simple_attachment_id }}' register: info @@ -879,7 +879,7 @@ # ===== - - name: '(CHECK_MODE) No change to tags with name set -- IDEMPOTENCY' + - name: (CHECK_MODE) No change to tags with name set -- IDEMPOTENCY check_mode: true community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' @@ -927,7 +927,7 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: 'No change to tags with name set -- IDEMPOTENCY' + - name: No change to tags with name set -- IDEMPOTENCY community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' register: simple_attach @@ -976,14 +976,14 @@ # ===== - - name: '(CHECK_MODE) Update tags' + - name: (CHECK_MODE) Update tags check_mode: true community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' - purge_tags: False + purge_tags: false tags: snake_case: snake_case_value 2 - "Tag with Space": value with space 2 + Tag with Space: value with space 2 register: simple_attach - name: Assert that the test is successful @@ -1028,13 +1028,13 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: 'Update tags' + - name: Update tags community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' - purge_tags: False + purge_tags: false tags: snake_case: snake_case_value 2 - "Tag with Space": value with space 2 + Tag with Space: value with space 2 register: simple_attach - name: Assert that the test is successful @@ -1079,14 +1079,14 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: '(CHECK_MODE) Update tags -- IDEMPOTENCY' + - name: (CHECK_MODE) Update tags -- IDEMPOTENCY check_mode: true community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' - purge_tags: False + purge_tags: false tags: snake_case: snake_case_value 2 - "Tag with Space": value with space 2 + Tag with Space: value with space 2 register: simple_attach - name: Assert that there is no change @@ -1131,13 +1131,13 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: 'Update tags -- IDEMPOTENCY' + - name: Update tags -- IDEMPOTENCY community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' - purge_tags: False + purge_tags: false tags: snake_case: snake_case_value 2 - "Tag with Space": value with space 2 + Tag with Space: value with space 2 register: simple_attach - name: Assert that there is no change @@ -1184,7 +1184,7 @@ # ===== - - name: '(CHECK_MODE) Remove tags' + - name: (CHECK_MODE) Remove tags check_mode: true community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' @@ -1231,7 +1231,7 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: 'Remove tags' + - name: Remove tags community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' tags: @@ -1277,7 +1277,7 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: '(CHECK_MODE) Remove tags -- IDEMPOTENCY' + - name: (CHECK_MODE) Remove tags -- IDEMPOTENCY check_mode: true community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' @@ -1324,7 +1324,7 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: 'Remove tags -- IDEMPOTENCY' + - name: Remove tags -- IDEMPOTENCY community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' tags: @@ -1372,11 +1372,11 @@ # ===== - - name: '(CHECK_MODE) Add tags with no purge' + - name: (CHECK_MODE) Add tags with no purge check_mode: true community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' - purge_tags: False + purge_tags: false tags: AnotherTag: Another Value register: simple_attach @@ -1421,10 +1421,10 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: 'Add tags with no purge' + - name: Add tags with no purge community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' - purge_tags: False + purge_tags: false tags: AnotherTag: Another Value register: simple_attach @@ -1469,11 +1469,11 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: '(CHECK_MODE) Add tags with no purge -- IDEMPOTENCY' + - name: (CHECK_MODE) Add tags with no purge -- IDEMPOTENCY check_mode: true community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' - purge_tags: False + purge_tags: false tags: AnotherTag: Another Value register: simple_attach @@ -1518,10 +1518,10 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: 'Add tags with no purge -- IDEMPOTENCY' + - name: Add tags with no purge -- IDEMPOTENCY community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' - purge_tags: False + purge_tags: false tags: AnotherTag: Another Value register: simple_attach @@ -1568,7 +1568,7 @@ # ===== - - name: '(CHECK_MODE) Remove all tags with name set' + - name: (CHECK_MODE) Remove all tags with name set check_mode: true community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' @@ -1609,7 +1609,7 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: 'Remove all tags with name set' + - name: Remove all tags with name set community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' tags: {} @@ -1649,7 +1649,7 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: '(CHECK_MODE) Remove all tags with name set -- IDEMPOTENCY' + - name: (CHECK_MODE) Remove all tags with name set -- IDEMPOTENCY check_mode: true community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' @@ -1690,7 +1690,7 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: 'Remove all tags with name set -- IDEMPOTENCY' + - name: Remove all tags with name set -- IDEMPOTENCY community.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' tags: {} @@ -1732,7 +1732,7 @@ # ===== - - name: '(CHECK_MODE) Remove all tags including name' + - name: (CHECK_MODE) Remove all tags including name check_mode: true community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' @@ -1771,7 +1771,7 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: 'Remove all tags including name' + - name: Remove all tags including name community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' tags: {} @@ -1809,7 +1809,7 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: '(CHECK_MODE) Remove all tags including name -- IDEMPOTENCY' + - name: (CHECK_MODE) Remove all tags including name -- IDEMPOTENCY check_mode: true community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' @@ -1848,7 +1848,7 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: 'Remove all tags including name -- IDEMPOTENCY' + - name: Remove all tags including name -- IDEMPOTENCY community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' tags: {} @@ -1889,7 +1889,7 @@ # ============================================================================= # Options - - name: '(CHECK_MODE) Set IPv6 support' + - name: (CHECK_MODE) Set IPv6 support check_mode: true community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' @@ -1928,7 +1928,7 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: 'Set IPv6 support' + - name: Set IPv6 support community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' ipv6_support: true @@ -1966,7 +1966,7 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: '(CHECK_MODE) Set IPv6 support -- IDEMPOTENCY' + - name: (CHECK_MODE) Set IPv6 support -- IDEMPOTENCY check_mode: true community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' @@ -2005,7 +2005,7 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: 'Set IPv6 support -- IDEMPOTENCY' + - name: Set IPv6 support -- IDEMPOTENCY community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' ipv6_support: true @@ -2045,11 +2045,11 @@ # ===== - - name: '(CHECK_MODE) Set DNS support' + - name: (CHECK_MODE) Set DNS support check_mode: true community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' - dns_support: False + dns_support: false register: simple_attach - name: Assert that the test is successful @@ -2084,10 +2084,10 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: 'Set DNS support' + - name: Set DNS support community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' - dns_support: False + dns_support: false register: simple_attach - name: Assert that the test is successful @@ -2122,11 +2122,11 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: '(CHECK_MODE) Set DNS support -- IDEMPOTENCY' + - name: (CHECK_MODE) Set DNS support -- IDEMPOTENCY check_mode: true community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' - dns_support: False + dns_support: false register: simple_attach - name: Assert that there is no change @@ -2161,10 +2161,10 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: 'Set DNS support -- IDEMPOTENCY' + - name: Set DNS support -- IDEMPOTENCY community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' - dns_support: False + dns_support: false register: simple_attach - name: Assert that there is no change @@ -2201,7 +2201,7 @@ # ===== - - name: '(CHECK_MODE) Set Appliance Mode support' + - name: (CHECK_MODE) Set Appliance Mode support check_mode: true community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' @@ -2240,7 +2240,7 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: 'Set Appliance Mode support' + - name: Set Appliance Mode support community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' appliance_mode_support: true @@ -2278,7 +2278,7 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: '(CHECK_MODE) Set Appliance Mode support -- IDEMPOTENCY' + - name: (CHECK_MODE) Set Appliance Mode support -- IDEMPOTENCY check_mode: true community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' @@ -2317,7 +2317,7 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: 'Set Appliance Mode support -- IDEMPOTENCY' + - name: Set Appliance Mode support -- IDEMPOTENCY community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' appliance_mode_support: true @@ -2357,11 +2357,11 @@ # ===== - - name: '(CHECK_MODE) Update IPv6 support' + - name: (CHECK_MODE) Update IPv6 support check_mode: true community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' - ipv6_support: False + ipv6_support: false register: simple_attach - name: Assert that the test is successful @@ -2396,10 +2396,10 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: 'Update IPv6 support' + - name: Update IPv6 support community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' - ipv6_support: False + ipv6_support: false register: simple_attach - name: Assert that the test is successful @@ -2434,11 +2434,11 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: '(CHECK_MODE) Update IPv6 support -- IDEMPOTENCY' + - name: (CHECK_MODE) Update IPv6 support -- IDEMPOTENCY check_mode: true community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' - ipv6_support: False + ipv6_support: false register: simple_attach - name: Assert that there is no change @@ -2473,10 +2473,10 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: 'Update IPv6 support -- IDEMPOTENCY' + - name: Update IPv6 support -- IDEMPOTENCY community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' - ipv6_support: False + ipv6_support: false register: simple_attach - name: Assert that there is no change @@ -2513,7 +2513,7 @@ # ===== - - name: '(CHECK_MODE) Update DNS support' + - name: (CHECK_MODE) Update DNS support check_mode: true community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' @@ -2552,7 +2552,7 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: 'Update DNS support' + - name: Update DNS support community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' dns_support: true @@ -2590,7 +2590,7 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: '(CHECK_MODE) Update DNS support -- IDEMPOTENCY' + - name: (CHECK_MODE) Update DNS support -- IDEMPOTENCY check_mode: true community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' @@ -2629,7 +2629,7 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: 'Update DNS support -- IDEMPOTENCY' + - name: Update DNS support -- IDEMPOTENCY community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' dns_support: true @@ -2669,11 +2669,11 @@ # ===== - - name: '(CHECK_MODE) Update Appliance Mode support' + - name: (CHECK_MODE) Update Appliance Mode support check_mode: true community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' - appliance_mode_support: False + appliance_mode_support: false register: simple_attach - name: Assert that the test is successful @@ -2708,10 +2708,10 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: 'Update Appliance Mode support' + - name: Update Appliance Mode support community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' - appliance_mode_support: False + appliance_mode_support: false register: simple_attach - name: Assert that the test is successful @@ -2746,11 +2746,11 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: '(CHECK_MODE) Update Appliance Mode support -- IDEMPOTENCY' + - name: (CHECK_MODE) Update Appliance Mode support -- IDEMPOTENCY check_mode: true community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' - appliance_mode_support: False + appliance_mode_support: false register: simple_attach - name: Assert that there is no change @@ -2785,10 +2785,10 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: 'Update Appliance Mode support -- IDEMPOTENCY' + - name: Update Appliance Mode support -- IDEMPOTENCY community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' - appliance_mode_support: False + appliance_mode_support: false register: simple_attach - name: Assert that there is no change @@ -2826,13 +2826,13 @@ # ============================================================================= # Subnet Management - - name: '(CHECK_MODE) Try to add subnet from a different VPC - no purge' + - name: (CHECK_MODE) Try to add subnet from a different VPC - no purge check_mode: true community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_b_2 }}' - purge_subnets: False + purge_subnets: false register: simple_attach ignore_errors: true @@ -2841,12 +2841,12 @@ that: - simple_attach is failed - - name: 'Try to add subnet from a different VPC - no purge' + - name: Try to add subnet from a different VPC - no purge community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_b_2 }}' - purge_subnets: False + purge_subnets: false register: simple_attach ignore_errors: true @@ -2857,7 +2857,7 @@ # ===== - - name: '(CHECK_MODE) Try to add subnet from a different VPC - with purge' + - name: (CHECK_MODE) Try to add subnet from a different VPC - with purge check_mode: true community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' @@ -2873,7 +2873,7 @@ that: - simple_attach is failed - - name: 'Try to add subnet from a different VPC - with purge' + - name: Try to add subnet from a different VPC - with purge community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: @@ -2890,13 +2890,13 @@ # ===== - - name: '(CHECK_MODE) Try to add subnet in the same AZ - no purge' + - name: (CHECK_MODE) Try to add subnet in the same AZ - no purge check_mode: true community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_b_1a }}' - purge_subnets: False + purge_subnets: false register: simple_attach ignore_errors: true @@ -2905,12 +2905,12 @@ that: - simple_attach is failed - - name: 'Try to add subnet in the same AZ - no purge' + - name: Try to add subnet in the same AZ - no purge community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_a_1a }}' - purge_subnets: False + purge_subnets: false register: simple_attach ignore_errors: true @@ -2921,7 +2921,7 @@ # ===== - - name: '(CHECK_MODE) Try to add subnet in the same AZ - with purge' + - name: (CHECK_MODE) Try to add subnet in the same AZ - with purge check_mode: true community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' @@ -2937,7 +2937,7 @@ that: - simple_attach is failed - - name: 'Try to add subnet in the same AZ - with purge' + - name: Try to add subnet in the same AZ - with purge community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: @@ -2954,13 +2954,13 @@ # ===== - - name: '(CHECK_MODE) Add subnet - without purge' + - name: (CHECK_MODE) Add subnet - without purge check_mode: true community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_a_2 }}' - purge_subnets: False + purge_subnets: false register: simple_attach - name: Assert that the test is successful @@ -2996,12 +2996,12 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: 'Add subnet - without purge' + - name: Add subnet - without purge community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_a_2 }}' - purge_subnets: False + purge_subnets: false register: simple_attach - name: Assert that the test is successful @@ -3037,13 +3037,13 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: '(CHECK_MODE) Add subnet - without purge -- IDEMPOTENCY' + - name: (CHECK_MODE) Add subnet - without purge -- IDEMPOTENCY check_mode: true community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_a_2 }}' - purge_subnets: False + purge_subnets: false register: simple_attach - name: Assert that there is no change @@ -3079,12 +3079,12 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: 'Add subnet - without purge -- IDEMPOTENCY' + - name: Add subnet - without purge -- IDEMPOTENCY community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_a_2 }}' - purge_subnets: False + purge_subnets: false register: simple_attach - name: Assert that there is no change @@ -3122,7 +3122,7 @@ # ===== - - name: '(CHECK_MODE) Add subnet - with purge' + - name: (CHECK_MODE) Add subnet - with purge check_mode: true community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' @@ -3167,7 +3167,7 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: 'Add subnet - with purge' + - name: Add subnet - with purge community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: @@ -3211,7 +3211,7 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: '(CHECK_MODE) Add subnet - with purge -- IDEMPOTENCY' + - name: (CHECK_MODE) Add subnet - with purge -- IDEMPOTENCY check_mode: true community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' @@ -3256,7 +3256,7 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: 'Add subnet - with purge -- IDEMPOTENCY' + - name: Add subnet - with purge -- IDEMPOTENCY community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: @@ -3302,7 +3302,7 @@ # ===== - - name: '(CHECK_MODE) Remove subnet' + - name: (CHECK_MODE) Remove subnet check_mode: true community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' @@ -3345,7 +3345,7 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: 'Remove subnet' + - name: Remove subnet community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: @@ -3387,7 +3387,7 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: '(CHECK_MODE) Remove subnet -- IDEMPOTENCY' + - name: (CHECK_MODE) Remove subnet -- IDEMPOTENCY check_mode: true community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' @@ -3430,7 +3430,7 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: 'Remove subnet -- IDEMPOTENCY' + - name: Remove subnet -- IDEMPOTENCY community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: @@ -3474,7 +3474,7 @@ # ===== - - name: '(CHECK_MODE) Remove and add subnet' + - name: (CHECK_MODE) Remove and add subnet check_mode: true community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' @@ -3517,7 +3517,7 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: 'Remove and add subnet' + - name: Remove and add subnet community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: @@ -3559,7 +3559,7 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: '(CHECK_MODE) Remove and add subnet -- IDEMPOTENCY' + - name: (CHECK_MODE) Remove and add subnet -- IDEMPOTENCY check_mode: true community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' @@ -3602,7 +3602,7 @@ vars: attachment: '{{ simple_attach.attachments[0] }}' - - name: 'Remove and add subnet -- IDEMPOTENCY' + - name: Remove and add subnet -- IDEMPOTENCY community.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: @@ -3647,7 +3647,7 @@ # ============================================================================= # Deletion - - name: '(CHECK_MODE) Delete an attachment - minimal parameters' + - name: (CHECK_MODE) Delete an attachment - minimal parameters check_mode: true community.aws.ec2_transit_gateway_vpc_attachment: state: absent @@ -3660,7 +3660,7 @@ that: - simple_attach is changed - - name: 'Delete an attachment - minimal parameters' + - name: Delete an attachment - minimal parameters community.aws.ec2_transit_gateway_vpc_attachment: state: absent id: '{{ simple_attachment_id }}' @@ -3672,12 +3672,12 @@ that: - simple_attach is changed - - name: '(CHECK_MODE) Delete an attachment - minimal parameters -- IDEMPOTENCY' + - name: (CHECK_MODE) Delete an attachment - minimal parameters -- IDEMPOTENCY check_mode: true community.aws.ec2_transit_gateway_vpc_attachment: state: absent id: '{{ simple_attachment_id }}' - wait: False + wait: false register: simple_attach - name: Assert that there is no change @@ -3685,11 +3685,11 @@ that: - simple_attach is not changed - - name: 'Delete an attachment - minimal parameters -- IDEMPOTENCY' + - name: Delete an attachment - minimal parameters -- IDEMPOTENCY community.aws.ec2_transit_gateway_vpc_attachment: state: absent id: '{{ simple_attachment_id }}' - wait: False + wait: false register: simple_attach - name: Assert that there is no change @@ -3698,9 +3698,9 @@ - simple_attach is not changed always: - - name: 'Delete attachment' + - name: Delete attachment community.aws.ec2_transit_gateway_vpc_attachment: state: absent id: '{{ simple_attachment_id }}' - wait: False + wait: false ignore_errors: true From 337591cd0b733e40f819f72f6e6aa98115fbe94d Mon Sep 17 00:00:00 2001 From: Alina Buzachis Date: Fri, 18 Oct 2024 14:09:29 +0200 Subject: [PATCH 20/25] Add changelog fragment --- .../migrate_ec2_transit_gateway_vpc_attachment.yml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 changelogs/fragments/migrate_ec2_transit_gateway_vpc_attachment.yml diff --git a/changelogs/fragments/migrate_ec2_transit_gateway_vpc_attachment.yml b/changelogs/fragments/migrate_ec2_transit_gateway_vpc_attachment.yml new file mode 100644 index 00000000000..21bf1ba51c4 --- /dev/null +++ b/changelogs/fragments/migrate_ec2_transit_gateway_vpc_attachment.yml @@ -0,0 +1,8 @@ +--- +major_changes: + - ec2_transit_gateway_vpc_attachment - The module has been migrated from the ``community.aws`` + collection. Playbooks using the Fully Qualified Collection Name for this module + should be updated to use ``amazon.aws.ec2_transit_gateway_vpc_attachment``. + - ec2_transit_gateway_vpc_attachment_info - The module has been migrated from the + ``community.aws`` collection. Playbooks using the Fully Qualified Collection Name + for this module should be updated to use ``amazon.aws.ec2_transit_gateway_vpc_attachment_info``. From 68f980153f603453f675a88891a0b58bc1ab15d0 Mon Sep 17 00:00:00 2001 From: Alina Buzachis Date: Fri, 18 Oct 2024 14:13:00 +0200 Subject: [PATCH 21/25] Apply isort Signed-off-by: Alina Buzachis --- plugins/modules/ec2_transit_gateway_vpc_attachment.py | 3 ++- plugins/modules/ec2_transit_gateway_vpc_attachment_info.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/modules/ec2_transit_gateway_vpc_attachment.py b/plugins/modules/ec2_transit_gateway_vpc_attachment.py index 7a9bcc1d6eb..1d3edd85060 100644 --- a/plugins/modules/ec2_transit_gateway_vpc_attachment.py +++ b/plugins/modules/ec2_transit_gateway_vpc_attachment.py @@ -8,6 +8,7 @@ module: ec2_transit_gateway_vpc_attachment short_description: Create and delete AWS Transit Gateway VPC attachments version_added: 4.0.0 +version_added_collection: community.aws description: - Creates, Deletes and Updates AWS Transit Gateway VPC Attachments. options: @@ -226,9 +227,9 @@ from typing import NoReturn +from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule from ansible_collections.amazon.aws.plugins.module_utils.transformation import boto3_resource_to_ansible_dict -from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule from ansible_collections.community.aws.plugins.module_utils.transitgateway import TransitGatewayVpcAttachmentManager from ansible_collections.community.aws.plugins.module_utils.transitgateway import find_existing_attachment from ansible_collections.community.aws.plugins.module_utils.transitgateway import get_states diff --git a/plugins/modules/ec2_transit_gateway_vpc_attachment_info.py b/plugins/modules/ec2_transit_gateway_vpc_attachment_info.py index 2dce78aa1e5..106c6fea9e4 100644 --- a/plugins/modules/ec2_transit_gateway_vpc_attachment_info.py +++ b/plugins/modules/ec2_transit_gateway_vpc_attachment_info.py @@ -8,6 +8,7 @@ module: ec2_transit_gateway_vpc_attachment_info short_description: describes AWS Transit Gateway VPC attachments version_added: 4.0.0 +version_added_collection: community.aws description: - Describes AWS Transit Gateway VPC Attachments. options: @@ -153,10 +154,10 @@ from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AnsibleEC2Error from ansible_collections.amazon.aws.plugins.module_utils.ec2 import describe_transit_gateway_vpc_attachments +from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list from ansible_collections.amazon.aws.plugins.module_utils.transformation import boto3_resource_to_ansible_dict -from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule from ansible_collections.community.aws.plugins.module_utils.transitgateway import get_states From ca6a98d9b1e72a5dd19207ce4304b5db4e89a789 Mon Sep 17 00:00:00 2001 From: Alina Buzachis Date: Fri, 18 Oct 2024 15:35:55 +0200 Subject: [PATCH 22/25] Update transitgateway.py --- plugins/module_utils/transitgateway.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/module_utils/transitgateway.py b/plugins/module_utils/transitgateway.py index a3454931205..14fb08ef931 100644 --- a/plugins/module_utils/transitgateway.py +++ b/plugins/module_utils/transitgateway.py @@ -455,7 +455,7 @@ def _update_attachment(self, tags: Dict[str, Any], purge_tags: bool) -> None: # Wait for resources to finish creating before updating self.state_manager.wait_for_state_change("available") elif self.existing.get("State") == "deleting": - self.module.fail_json(msg="Deletion in progress, unable to update", route_tables=[self.original_resource]) + self.module.fail_json(msg="Deletion in progress, unable to update", route_tables=[self.existing]) # Apply the configuration if self.apply_configuration(): From cdcb00e83770d4a5cecb9b24af97efbf77cea026 Mon Sep 17 00:00:00 2001 From: Alina Buzachis Date: Fri, 18 Oct 2024 16:22:34 +0200 Subject: [PATCH 23/25] Update FQCN integration tests Signed-off-by: Alina Buzachis --- plugins/module_utils/transitgateway.py | 3 +- .../ec2_transit_gateway_vpc_attachment.py | 9 +- ...ec2_transit_gateway_vpc_attachment_info.py | 3 +- .../tasks/cleanup.yml | 6 +- .../tasks/complex.yml | 16 +- .../tasks/simple.yml | 192 +++++++++--------- 6 files changed, 113 insertions(+), 116 deletions(-) diff --git a/plugins/module_utils/transitgateway.py b/plugins/module_utils/transitgateway.py index 14fb08ef931..66421fa8681 100644 --- a/plugins/module_utils/transitgateway.py +++ b/plugins/module_utils/transitgateway.py @@ -26,14 +26,13 @@ from ansible_collections.amazon.aws.plugins.module_utils.ec2 import describe_transit_gateway_vpc_attachments from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ensure_ec2_tags from ansible_collections.amazon.aws.plugins.module_utils.ec2 import modify_transit_gateway_vpc_attachment +from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_list_to_ansible_dict from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_specifications from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list from ansible_collections.amazon.aws.plugins.module_utils.transformation import boto3_resource_to_ansible_dict from ansible_collections.amazon.aws.plugins.module_utils.waiters import get_waiter -from ansible_collections.community.aws.plugins.module_utils.modules import AnsibleCommunityAWSModule as AnsibleAWSModule - def get_states() -> List[str]: return [ diff --git a/plugins/modules/ec2_transit_gateway_vpc_attachment.py b/plugins/modules/ec2_transit_gateway_vpc_attachment.py index 1d3edd85060..aeb86269ea3 100644 --- a/plugins/modules/ec2_transit_gateway_vpc_attachment.py +++ b/plugins/modules/ec2_transit_gateway_vpc_attachment.py @@ -229,11 +229,10 @@ from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule from ansible_collections.amazon.aws.plugins.module_utils.transformation import boto3_resource_to_ansible_dict - -from ansible_collections.community.aws.plugins.module_utils.transitgateway import TransitGatewayVpcAttachmentManager -from ansible_collections.community.aws.plugins.module_utils.transitgateway import find_existing_attachment -from ansible_collections.community.aws.plugins.module_utils.transitgateway import get_states -from ansible_collections.community.aws.plugins.module_utils.transitgateway import subnets_to_vpc +from ansible_collections.amazon.aws.plugins.module_utils.transitgateway import TransitGatewayVpcAttachmentManager +from ansible_collections.amazon.aws.plugins.module_utils.transitgateway import find_existing_attachment +from ansible_collections.amazon.aws.plugins.module_utils.transitgateway import get_states +from ansible_collections.amazon.aws.plugins.module_utils.transitgateway import subnets_to_vpc def handle_vpc_attachments(client, module: AnsibleAWSModule) -> NoReturn: diff --git a/plugins/modules/ec2_transit_gateway_vpc_attachment_info.py b/plugins/modules/ec2_transit_gateway_vpc_attachment_info.py index 106c6fea9e4..581e5d55c2d 100644 --- a/plugins/modules/ec2_transit_gateway_vpc_attachment_info.py +++ b/plugins/modules/ec2_transit_gateway_vpc_attachment_info.py @@ -157,8 +157,7 @@ from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list from ansible_collections.amazon.aws.plugins.module_utils.transformation import boto3_resource_to_ansible_dict - -from ansible_collections.community.aws.plugins.module_utils.transitgateway import get_states +from ansible_collections.amazon.aws.plugins.module_utils.transitgateway import get_states def main(): 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 index 7448fce7b6a..1beefea219e 100644 --- a/tests/integration/targets/ec2_transit_gateway_vpc_attachment/tasks/cleanup.yml +++ b/tests/integration/targets/ec2_transit_gateway_vpc_attachment/tasks/cleanup.yml @@ -1,12 +1,12 @@ - name: Describe all attachments on our VPC - community.aws.ec2_transit_gateway_vpc_attachment_info: + amazon.aws.ec2_transit_gateway_vpc_attachment_info: filters: transit-gateway-id: '{{ tgw_id }}' register: info ignore_errors: true - name: Start deletion of all attachments - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: state: absent id: '{{ item.transit_gateway_attachment_id }}' wait: false @@ -14,7 +14,7 @@ ignore_errors: true - name: Wait for deletion of all attachments - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: state: absent id: '{{ item.transit_gateway_attachment_id }}' wait: 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 index 1208e480cb3..a45f2345f8c 100644 --- a/tests/integration/targets/ec2_transit_gateway_vpc_attachment/tasks/complex.yml +++ b/tests/integration/targets/ec2_transit_gateway_vpc_attachment/tasks/complex.yml @@ -9,7 +9,7 @@ - block: - name: (CHECK_MODE) Create an attachment - complex parameters check_mode: true - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name_complex }}' transit_gateway: '{{ tgw_id }}' subnets: @@ -53,7 +53,7 @@ attachment: '{{ complex_attach.attachments[0] }}' - name: Create an attachment - complex parameters - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name_complex }}' transit_gateway: '{{ tgw_id }}' subnets: @@ -112,7 +112,7 @@ - name: (CHECK_MODE) Create an attachment - complex parameters -- IDEMPOTENCY check_mode: true - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name_complex }}' transit_gateway: '{{ tgw_id }}' subnets: @@ -165,7 +165,7 @@ attachment: '{{ complex_attach.attachments[0] }}' - name: Create an attachment - complex parameters -- IDEMPOTENCY - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name_complex }}' transit_gateway: '{{ tgw_id }}' subnets: @@ -222,7 +222,7 @@ - name: (CHECK_MODE) Update an attachment - complex parameters check_mode: true - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name_complex }}' transit_gateway: '{{ tgw_id }}' subnets: @@ -279,7 +279,7 @@ attachment: '{{ complex_attach.attachments[0] }}' - name: Update an attachment - complex parameters - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name_complex }}' transit_gateway: '{{ tgw_id }}' subnets: @@ -337,7 +337,7 @@ - name: (CHECK_MODE) Update an attachment - complex parameters -- IDEMPOTENCY check_mode: true - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name_complex }}' transit_gateway: '{{ tgw_id }}' subnets: @@ -394,7 +394,7 @@ attachment: '{{ complex_attach.attachments[0] }}' - name: Update an attachment - complex parameters -- IDEMPOTENCY - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name_complex }}' transit_gateway: '{{ tgw_id }}' subnets: 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 index 6b62ae1b92f..9a2ff5aa211 100644 --- a/tests/integration/targets/ec2_transit_gateway_vpc_attachment/tasks/simple.yml +++ b/tests/integration/targets/ec2_transit_gateway_vpc_attachment/tasks/simple.yml @@ -3,7 +3,7 @@ - block: - name: (CHECK_MODE) Create an attachment - minimal parameters check_mode: true - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: transit_gateway: '{{ tgw_id }}' subnets: - '{{ subnet_id_a_1 }}' @@ -26,7 +26,7 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: Create an attachment - minimal parameters - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: transit_gateway: '{{ tgw_id }}' subnets: - '{{ subnet_id_a_1 }}' @@ -71,7 +71,7 @@ - name: (CHECK_MODE) Create an attachment - minimal parameters -- IDEMPOTENCY check_mode: true - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: transit_gateway: '{{ tgw_id }}' subnets: - '{{ subnet_id_a_1 }}' @@ -110,7 +110,7 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: Create an attachment - minimal parameters -- IDEMPOTENCY - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: transit_gateway: '{{ tgw_id }}' subnets: - '{{ subnet_id_a_1 }}' @@ -152,7 +152,7 @@ - name: (CHECK_MODE) By Id - minimal parameters -- IDEMPOTENCY check_mode: true - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_a_1 }}' @@ -191,7 +191,7 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: By Id - minimal parameters -- IDEMPOTENCY - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_a_1 }}' @@ -234,7 +234,7 @@ - name: (CHECK_MODE) Set name check_mode: true - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' name: '{{ attachment_name }}' register: simple_attach @@ -274,7 +274,7 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: Set name - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' name: '{{ attachment_name }}' register: simple_attach @@ -315,7 +315,7 @@ - name: (CHECK_MODE) Set name -- IDEMPOTENCY check_mode: true - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' name: '{{ attachment_name }}' register: simple_attach @@ -355,7 +355,7 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: Set name -- IDEMPOTENCY - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' name: '{{ attachment_name }}' register: simple_attach @@ -398,7 +398,7 @@ - name: (CHECK_MODE) By Name - minimal parameters -- IDEMPOTENCY check_mode: true - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' subnets: - '{{ subnet_id_a_1 }}' @@ -439,7 +439,7 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: By Name - minimal parameters -- IDEMPOTENCY - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' subnets: - '{{ subnet_id_a_1 }}' @@ -483,7 +483,7 @@ # Describe - name: Describe all attachments - community.aws.ec2_transit_gateway_vpc_attachment_info: + amazon.aws.ec2_transit_gateway_vpc_attachment_info: register: info - name: Assert that the transit_gateway_vpc_attachment_info is returned sucessfully @@ -510,7 +510,7 @@ attachment: '{{ info.attachments[0] }}' - name: Describe attachments on a specific VPC - community.aws.ec2_transit_gateway_vpc_attachment_info: + amazon.aws.ec2_transit_gateway_vpc_attachment_info: filters: transit-gateway-id: '{{ tgw_id }}' register: info @@ -540,7 +540,7 @@ attachment: '{{ info.attachments[0] }}' - name: Describe attachment with a specific name - community.aws.ec2_transit_gateway_vpc_attachment_info: + amazon.aws.ec2_transit_gateway_vpc_attachment_info: name: '{{ attachment_name }}' register: info @@ -579,7 +579,7 @@ attachment: '{{ info.attachments[0] }}' - name: Describe attachment by ID - community.aws.ec2_transit_gateway_vpc_attachment_info: + amazon.aws.ec2_transit_gateway_vpc_attachment_info: id: '{{ simple_attachment_id }}' register: info @@ -622,7 +622,7 @@ - name: (CHECK_MODE) Set tags check_mode: true - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' tags: CamelCase: CamelCaseValue @@ -674,7 +674,7 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: Set tags - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' tags: CamelCase: CamelCaseValue @@ -727,7 +727,7 @@ - name: (CHECK_MODE) Set tags -- IDEMPOTENCY check_mode: true - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' tags: CamelCase: CamelCaseValue @@ -779,7 +779,7 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: Set tags -- IDEMPOTENCY - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' tags: CamelCase: CamelCaseValue @@ -831,7 +831,7 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: Describe attachment with tags set - community.aws.ec2_transit_gateway_vpc_attachment_info: + amazon.aws.ec2_transit_gateway_vpc_attachment_info: id: '{{ simple_attachment_id }}' register: info @@ -881,7 +881,7 @@ - name: (CHECK_MODE) No change to tags with name set -- IDEMPOTENCY check_mode: true - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' register: simple_attach @@ -928,7 +928,7 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: No change to tags with name set -- IDEMPOTENCY - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' register: simple_attach @@ -978,7 +978,7 @@ - name: (CHECK_MODE) Update tags check_mode: true - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' purge_tags: false tags: @@ -1029,7 +1029,7 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: Update tags - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' purge_tags: false tags: @@ -1081,7 +1081,7 @@ - name: (CHECK_MODE) Update tags -- IDEMPOTENCY check_mode: true - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' purge_tags: false tags: @@ -1132,7 +1132,7 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: Update tags -- IDEMPOTENCY - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' purge_tags: false tags: @@ -1186,7 +1186,7 @@ - name: (CHECK_MODE) Remove tags check_mode: true - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' tags: CamelCase: CamelCaseValue @@ -1232,7 +1232,7 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: Remove tags - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' tags: CamelCase: CamelCaseValue @@ -1279,7 +1279,7 @@ - name: (CHECK_MODE) Remove tags -- IDEMPOTENCY check_mode: true - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' tags: CamelCase: CamelCaseValue @@ -1325,7 +1325,7 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: Remove tags -- IDEMPOTENCY - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' tags: CamelCase: CamelCaseValue @@ -1374,7 +1374,7 @@ - name: (CHECK_MODE) Add tags with no purge check_mode: true - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' purge_tags: false tags: @@ -1422,7 +1422,7 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: Add tags with no purge - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' purge_tags: false tags: @@ -1471,7 +1471,7 @@ - name: (CHECK_MODE) Add tags with no purge -- IDEMPOTENCY check_mode: true - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' purge_tags: false tags: @@ -1519,7 +1519,7 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: Add tags with no purge -- IDEMPOTENCY - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' purge_tags: false tags: @@ -1570,7 +1570,7 @@ - name: (CHECK_MODE) Remove all tags with name set check_mode: true - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' tags: {} register: simple_attach @@ -1610,7 +1610,7 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: Remove all tags with name set - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' tags: {} register: simple_attach @@ -1651,7 +1651,7 @@ - name: (CHECK_MODE) Remove all tags with name set -- IDEMPOTENCY check_mode: true - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' tags: {} register: simple_attach @@ -1691,7 +1691,7 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: Remove all tags with name set -- IDEMPOTENCY - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: name: '{{ attachment_name }}' tags: {} register: simple_attach @@ -1734,7 +1734,7 @@ - name: (CHECK_MODE) Remove all tags including name check_mode: true - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' tags: {} register: simple_attach @@ -1772,7 +1772,7 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: Remove all tags including name - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' tags: {} register: simple_attach @@ -1811,7 +1811,7 @@ - name: (CHECK_MODE) Remove all tags including name -- IDEMPOTENCY check_mode: true - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' tags: {} register: simple_attach @@ -1849,7 +1849,7 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: Remove all tags including name -- IDEMPOTENCY - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' tags: {} register: simple_attach @@ -1891,7 +1891,7 @@ - name: (CHECK_MODE) Set IPv6 support check_mode: true - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' ipv6_support: true register: simple_attach @@ -1929,7 +1929,7 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: Set IPv6 support - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' ipv6_support: true register: simple_attach @@ -1968,7 +1968,7 @@ - name: (CHECK_MODE) Set IPv6 support -- IDEMPOTENCY check_mode: true - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' ipv6_support: true register: simple_attach @@ -2006,7 +2006,7 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: Set IPv6 support -- IDEMPOTENCY - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' ipv6_support: true register: simple_attach @@ -2047,7 +2047,7 @@ - name: (CHECK_MODE) Set DNS support check_mode: true - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' dns_support: false register: simple_attach @@ -2085,7 +2085,7 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: Set DNS support - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' dns_support: false register: simple_attach @@ -2124,7 +2124,7 @@ - name: (CHECK_MODE) Set DNS support -- IDEMPOTENCY check_mode: true - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' dns_support: false register: simple_attach @@ -2162,7 +2162,7 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: Set DNS support -- IDEMPOTENCY - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' dns_support: false register: simple_attach @@ -2203,7 +2203,7 @@ - name: (CHECK_MODE) Set Appliance Mode support check_mode: true - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' appliance_mode_support: true register: simple_attach @@ -2241,7 +2241,7 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: Set Appliance Mode support - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' appliance_mode_support: true register: simple_attach @@ -2280,7 +2280,7 @@ - name: (CHECK_MODE) Set Appliance Mode support -- IDEMPOTENCY check_mode: true - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' appliance_mode_support: true register: simple_attach @@ -2318,7 +2318,7 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: Set Appliance Mode support -- IDEMPOTENCY - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' appliance_mode_support: true register: simple_attach @@ -2359,7 +2359,7 @@ - name: (CHECK_MODE) Update IPv6 support check_mode: true - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' ipv6_support: false register: simple_attach @@ -2397,7 +2397,7 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: Update IPv6 support - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' ipv6_support: false register: simple_attach @@ -2436,7 +2436,7 @@ - name: (CHECK_MODE) Update IPv6 support -- IDEMPOTENCY check_mode: true - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' ipv6_support: false register: simple_attach @@ -2474,7 +2474,7 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: Update IPv6 support -- IDEMPOTENCY - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' ipv6_support: false register: simple_attach @@ -2515,7 +2515,7 @@ - name: (CHECK_MODE) Update DNS support check_mode: true - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' dns_support: true register: simple_attach @@ -2553,7 +2553,7 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: Update DNS support - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' dns_support: true register: simple_attach @@ -2592,7 +2592,7 @@ - name: (CHECK_MODE) Update DNS support -- IDEMPOTENCY check_mode: true - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' dns_support: true register: simple_attach @@ -2630,7 +2630,7 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: Update DNS support -- IDEMPOTENCY - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' dns_support: true register: simple_attach @@ -2671,7 +2671,7 @@ - name: (CHECK_MODE) Update Appliance Mode support check_mode: true - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' appliance_mode_support: false register: simple_attach @@ -2709,7 +2709,7 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: Update Appliance Mode support - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' appliance_mode_support: false register: simple_attach @@ -2748,7 +2748,7 @@ - name: (CHECK_MODE) Update Appliance Mode support -- IDEMPOTENCY check_mode: true - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' appliance_mode_support: false register: simple_attach @@ -2786,7 +2786,7 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: Update Appliance Mode support -- IDEMPOTENCY - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' appliance_mode_support: false register: simple_attach @@ -2828,7 +2828,7 @@ - name: (CHECK_MODE) Try to add subnet from a different VPC - no purge check_mode: true - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_b_2 }}' @@ -2842,7 +2842,7 @@ - simple_attach is failed - name: Try to add subnet from a different VPC - no purge - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_b_2 }}' @@ -2859,7 +2859,7 @@ - name: (CHECK_MODE) Try to add subnet from a different VPC - with purge check_mode: true - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_a_1 }}' @@ -2874,7 +2874,7 @@ - simple_attach is failed - name: Try to add subnet from a different VPC - with purge - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_a_1 }}' @@ -2892,7 +2892,7 @@ - name: (CHECK_MODE) Try to add subnet in the same AZ - no purge check_mode: true - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_b_1a }}' @@ -2906,7 +2906,7 @@ - simple_attach is failed - name: Try to add subnet in the same AZ - no purge - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_a_1a }}' @@ -2923,7 +2923,7 @@ - name: (CHECK_MODE) Try to add subnet in the same AZ - with purge check_mode: true - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_a_1 }}' @@ -2938,7 +2938,7 @@ - simple_attach is failed - name: Try to add subnet in the same AZ - with purge - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_a_1 }}' @@ -2956,7 +2956,7 @@ - name: (CHECK_MODE) Add subnet - without purge check_mode: true - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_a_2 }}' @@ -2997,7 +2997,7 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: Add subnet - without purge - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_a_2 }}' @@ -3039,7 +3039,7 @@ - name: (CHECK_MODE) Add subnet - without purge -- IDEMPOTENCY check_mode: true - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_a_2 }}' @@ -3080,7 +3080,7 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: Add subnet - without purge -- IDEMPOTENCY - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_a_2 }}' @@ -3124,7 +3124,7 @@ - name: (CHECK_MODE) Add subnet - with purge check_mode: true - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_a_1 }}' @@ -3168,7 +3168,7 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: Add subnet - with purge - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_a_1 }}' @@ -3213,7 +3213,7 @@ - name: (CHECK_MODE) Add subnet - with purge -- IDEMPOTENCY check_mode: true - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_a_1 }}' @@ -3257,7 +3257,7 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: Add subnet - with purge -- IDEMPOTENCY - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_a_1 }}' @@ -3304,7 +3304,7 @@ - name: (CHECK_MODE) Remove subnet check_mode: true - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_a_2 }}' @@ -3346,7 +3346,7 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: Remove subnet - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_a_2 }}' @@ -3389,7 +3389,7 @@ - name: (CHECK_MODE) Remove subnet -- IDEMPOTENCY check_mode: true - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_a_2 }}' @@ -3431,7 +3431,7 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: Remove subnet -- IDEMPOTENCY - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_a_2 }}' @@ -3476,7 +3476,7 @@ - name: (CHECK_MODE) Remove and add subnet check_mode: true - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_a_1 }}' @@ -3518,7 +3518,7 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: Remove and add subnet - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_a_1 }}' @@ -3561,7 +3561,7 @@ - name: (CHECK_MODE) Remove and add subnet -- IDEMPOTENCY check_mode: true - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_a_1 }}' @@ -3603,7 +3603,7 @@ attachment: '{{ simple_attach.attachments[0] }}' - name: Remove and add subnet -- IDEMPOTENCY - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: id: '{{ simple_attachment_id }}' subnets: - '{{ subnet_id_a_1 }}' @@ -3649,7 +3649,7 @@ - name: (CHECK_MODE) Delete an attachment - minimal parameters check_mode: true - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: state: absent id: '{{ simple_attachment_id }}' wait: false @@ -3661,7 +3661,7 @@ - simple_attach is changed - name: Delete an attachment - minimal parameters - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: state: absent id: '{{ simple_attachment_id }}' wait: false @@ -3674,7 +3674,7 @@ - name: (CHECK_MODE) Delete an attachment - minimal parameters -- IDEMPOTENCY check_mode: true - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: state: absent id: '{{ simple_attachment_id }}' wait: false @@ -3686,7 +3686,7 @@ - simple_attach is not changed - name: Delete an attachment - minimal parameters -- IDEMPOTENCY - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: state: absent id: '{{ simple_attachment_id }}' wait: false @@ -3699,7 +3699,7 @@ always: - name: Delete attachment - community.aws.ec2_transit_gateway_vpc_attachment: + amazon.aws.ec2_transit_gateway_vpc_attachment: state: absent id: '{{ simple_attachment_id }}' wait: false From 53009071a3b4c6aba7fcb6e9ed57b4082310ea43 Mon Sep 17 00:00:00 2001 From: Alina Buzachis Date: Thu, 24 Oct 2024 16:34:40 +0200 Subject: [PATCH 24/25] Fix naming Signed-off-by: Alina Buzachis --- plugins/module_utils/transitgateway.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/module_utils/transitgateway.py b/plugins/module_utils/transitgateway.py index 66421fa8681..e49445f2fbe 100644 --- a/plugins/module_utils/transitgateway.py +++ b/plugins/module_utils/transitgateway.py @@ -454,7 +454,10 @@ def _update_attachment(self, tags: Dict[str, Any], purge_tags: bool) -> None: # Wait for resources to finish creating before updating self.state_manager.wait_for_state_change("available") elif self.existing.get("State") == "deleting": - self.module.fail_json(msg="Deletion in progress, unable to update", route_tables=[self.existing]) + self.module.fail_json( + msg="Deletion in progress, unable to update", + attachments=[boto3_resource_to_ansible_dict(self.existing)], + ) # Apply the configuration if self.apply_configuration(): From 338f2115fdb0aea221099b50090f0b79081ebeb8 Mon Sep 17 00:00:00 2001 From: Alina Buzachis Date: Thu, 24 Oct 2024 16:40:10 +0200 Subject: [PATCH 25/25] Fix naming Signed-off-by: Alina Buzachis --- plugins/module_utils/transitgateway.py | 10 +++++----- .../tasks/complex.yml | 9 +++++++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/plugins/module_utils/transitgateway.py b/plugins/module_utils/transitgateway.py index e49445f2fbe..a8f50614e23 100644 --- a/plugins/module_utils/transitgateway.py +++ b/plugins/module_utils/transitgateway.py @@ -6,8 +6,7 @@ from copy import deepcopy try: - from botocore.exceptions import BotoCoreError - from botocore.exceptions import ClientError + from botocore.exceptions import WaiterError except ImportError: pass @@ -176,11 +175,12 @@ def wait_for_state_change(self, desired_state: str) -> None: # Wait until attachment reaches the desired state params = {"TransitGatewayAttachmentIds": [self.attachment_id]} params.update(self.waiter_config) + waiter = get_waiter(self.client, f"transit_gateway_vpc_attachment_{desired_state}") + try: - waiter = get_waiter(self.client, f"transit_gateway_vpc_attachment_{desired_state}") waiter.wait(**params) - except (BotoCoreError, ClientError) as e: - self.module.fail_json_aws_error(e) + except WaiterError as e: + self.module.fail_json_aws(e, "Timeout waiting for State change") class AttachmentConfigurationManager: 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 index a45f2345f8c..4fdd0ba6eb6 100644 --- a/tests/integration/targets/ec2_transit_gateway_vpc_attachment/tasks/complex.yml +++ b/tests/integration/targets/ec2_transit_gateway_vpc_attachment/tasks/complex.yml @@ -107,8 +107,13 @@ - name: Save Attachment ID set_fact: - complex_attachment_id: '{{ complex_attach.attachments[0].transit_gateway_attachment_id - }}' + complex_attachment_id: '{{ complex_attach.attachments[0].transit_gateway_attachment_id }}' + + - name: Gather information about the attachment + amazon.aws.ec2_transit_gateway_vpc_attachment_info: + filters: + transit-gateway-id: '{{ tgw_id }}' + register: info - name: (CHECK_MODE) Create an attachment - complex parameters -- IDEMPOTENCY check_mode: true