From 7dabfccc73b77239b95de01069890f3ee7bf95f0 Mon Sep 17 00:00:00 2001 From: GomathiselviS Date: Fri, 18 Oct 2024 06:05:47 -0400 Subject: [PATCH] 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 --- ...20240924-fix-documentation-tgw-vpc-att.yml | 2 + 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 +++++++++------- 8 files changed, 1094 insertions(+), 836 deletions(-) create mode 100644 changelogs/fragments/20240924-fix-documentation-tgw-vpc-att.yml diff --git a/changelogs/fragments/20240924-fix-documentation-tgw-vpc-att.yml b/changelogs/fragments/20240924-fix-documentation-tgw-vpc-att.yml new file mode 100644 index 00000000000..0fa478776bb --- /dev/null +++ b/changelogs/fragments/20240924-fix-documentation-tgw-vpc-att.yml @@ -0,0 +1,2 @@ +minor_changes: + - ec2_transit_gateway_vpc_attachment - Modify doumentation and refactor to adhere to coding guidelines (https://github.com/ansible-collections/community.aws/pull/2157). 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