From 6c767b173716c6afeb198efc47d05f0bd3b189fc Mon Sep 17 00:00:00 2001 From: Moritz Wagner Date: Fri, 20 Aug 2021 20:35:13 +0200 Subject: [PATCH 01/37] s3_bucket - Improve documentation of the policy parameter (#387) s3_bucket - improve documentation of policy parameter SUMMARY This pull requests improves the documentation of the policy parameter in the s3_bucket module. It documents how to ensure the absence of a policy. Fixes #385 ISSUE TYPE Docs Pull Request COMPONENT NAME s3_bucket Reviewed-by: Jill R Reviewed-by: Moritz Wagner Reviewed-by: None Reviewed-by: Mark Chappell --- plugins/modules/s3_bucket.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/plugins/modules/s3_bucket.py b/plugins/modules/s3_bucket.py index 2dd5dc934a5..591551ac5fc 100644 --- a/plugins/modules/s3_bucket.py +++ b/plugins/modules/s3_bucket.py @@ -41,7 +41,7 @@ type: str policy: description: - - The JSON policy as a string. + - The JSON policy as a string. Set to the string C("null") to force the absence of a policy. type: json s3_url: description: @@ -214,7 +214,7 @@ public_access: block_public_acls: true ignore_public_acls: true - ## keys == 'false' can be ommited, undefined keys defaults to 'false' + ## keys == 'false' can be omitted, undefined keys defaults to 'false' # block_public_policy: false # restrict_public_buckets: false @@ -235,6 +235,12 @@ name: mys3bucket state: present delete_object_ownership: true + +# Delete a bucket policy from bucket +- amazon.aws.s3_bucket: + name: mys3bucket + state: present + policy: "null" ''' import json From 19ea763cd4719b239c0603bac88f73e9742a4051 Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Tue, 24 Aug 2021 03:58:50 -0700 Subject: [PATCH 02/37] Adding example of using groups in aws_ec2.py module (#458) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding example of using groups in aws_ec2.py module SUMMARY Adding a example of using groups option to add items from a specific inventory configuration to groups. Example shows use of groups to group hosts based on vpc id. Resolves #412 ISSUE TYPE Docs Pull Request COMPONENT NAME aws_ec2.py Reviewed-by: Gonéri Le Bouder Reviewed-by: Alina Buzachis Reviewed-by: Abhijeet Kasurde Reviewed-by: None --- plugins/inventory/aws_ec2.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/plugins/inventory/aws_ec2.py b/plugins/inventory/aws_ec2.py index c881943a8a5..a7244260d6e 100644 --- a/plugins/inventory/aws_ec2.py +++ b/plugins/inventory/aws_ec2.py @@ -188,6 +188,23 @@ exclude_filters: - tag:Name: - 'my_first_tag' + +# Example using groups to assign the running hosts to a group based on vpc_id +plugin: aws_ec2 +boto_profile: aws_profile +# Populate inventory with instances in these regions +regions: + - us-east-2 +filters: + # All instances with their state as `running` + instance-state-name: running +keyed_groups: + - prefix: tag + key: tags +compose: + ansible_host: public_dns_name +groups: + libvpc: vpc_id == 'vpc-####' ''' import re From cc94310020fb68489878589e8b8aa0f1b3c37404 Mon Sep 17 00:00:00 2001 From: Alina Buzachis Date: Wed, 25 Aug 2021 20:59:07 +0200 Subject: [PATCH 03/37] ec2_instance - Support throughtput parameter for GP3 volume types (#433) ec2_instance - Support throughtput parameter for GP3 volume types SUMMARY ec2_instance - Support throughput parameter for GP3 volume types Fixes #395 ISSUE TYPE Feature Pull Request COMPONENT NAME ec2_instance Reviewed-by: Markus Bergholz Reviewed-by: Mark Chappell Reviewed-by: Alina Buzachis Reviewed-by: Jill R Reviewed-by: None --- .../fragments/433-ec2_instance-throughput.yml | 2 ++ plugins/modules/ec2_instance.py | 10 +++++++ .../ec2_instance/tasks/block_devices.yml | 28 +++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 changelogs/fragments/433-ec2_instance-throughput.yml diff --git a/changelogs/fragments/433-ec2_instance-throughput.yml b/changelogs/fragments/433-ec2_instance-throughput.yml new file mode 100644 index 00000000000..620cbec222d --- /dev/null +++ b/changelogs/fragments/433-ec2_instance-throughput.yml @@ -0,0 +1,2 @@ +minor_changes: + - ec2_instance - add ``throughput`` parameter for gp3 volume types (https://github.com/ansible-collections/amazon.aws/pull/433). \ No newline at end of file diff --git a/plugins/modules/ec2_instance.py b/plugins/modules/ec2_instance.py index 984b4dbc44e..d81312279f8 100644 --- a/plugins/modules/ec2_instance.py +++ b/plugins/modules/ec2_instance.py @@ -179,6 +179,7 @@ - A list of block device mappings, by default this will always use the AMI root device so the volumes option is primarily for adding more storage. - A mapping contains the (optional) keys device_name, virtual_name, ebs.volume_type, ebs.volume_size, ebs.kms_key_id, ebs.iops, and ebs.delete_on_termination. + - Set ebs.throughput value requires botocore>=1.19.27. - For more information about each parameter, see U(https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_BlockDeviceMapping.html). type: list elements: dict @@ -954,6 +955,15 @@ def build_volume_spec(params): for int_value in ['volume_size', 'iops']: if int_value in volume['ebs']: volume['ebs'][int_value] = int(volume['ebs'][int_value]) + if 'volume_type' in volume['ebs'] and volume['ebs']['volume_type'] == 'gp3': + if not volume['ebs'].get('iops'): + volume['ebs']['iops'] = 3000 + if 'throughput' in volume['ebs']: + module.require_botocore_at_least('1.19.27', reason='to set throughtput value') + volume['ebs']['throughput'] = int(volume['ebs']['throughput']) + else: + volume['ebs']['throughput'] = 125 + return [snake_dict_to_camel_dict(v, capitalize_first=True) for v in volumes] diff --git a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/block_devices.yml b/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/block_devices.yml index 0a8ab63f08b..0a0ac2a95f1 100644 --- a/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/block_devices.yml +++ b/tests/integration/targets/ec2_instance/roles/ec2_instance/tasks/block_devices.yml @@ -71,6 +71,34 @@ ec2_instance: state: absent instance_ids: "{{ block_device_instances.instance_ids }}" + + - name: "New instance with an extra block device - gp3 volume_type and throughput" + ec2_instance: + state: present + name: "{{ resource_prefix }}-test-ebs-vols-gp3" + image_id: "{{ ec2_ami_image }}" + vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}" + volumes: + - device_name: /dev/sdb + ebs: + volume_size: 20 + delete_on_termination: true + volume_type: gp3 + throughput: 500 + tags: + TestId: "{{ ec2_instance_tag_TestId }}" + instance_type: "{{ ec2_instance_type }}" + wait: true + register: block_device_instances_gp3 + + - assert: + that: + - block_device_instances_gp3 is not failed + - block_device_instances_gp3 is changed + - block_device_instances_gp3.spec.BlockDeviceMappings[0].DeviceName == '/dev/sdb' + - block_device_instances_gp3.spec.BlockDeviceMappings[0].Ebs.VolumeType == 'gp3' + - block_device_instances_gp3.spec.BlockDeviceMappings[0].Ebs.VolumeSize == 20 + - block_device_instances_gp3.spec.BlockDeviceMappings[0].Ebs.Throughput == 500 always: - name: "Terminate block_devices instances" From e10d7d2c46f81c36f062a9efde2ec7d87c967833 Mon Sep 17 00:00:00 2001 From: jillr Date: Mon, 2 Mar 2020 19:25:18 +0000 Subject: [PATCH 04/37] Initial commit This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/eb75681585a23ea79e642b86a0f8e64e0f40a6d7 --- plugins/modules/ec2_vpc_endpoint.py | 400 ++++++++++++++++++++++ plugins/modules/ec2_vpc_endpoint_facts.py | 1 + plugins/modules/ec2_vpc_endpoint_info.py | 200 +++++++++++ 3 files changed, 601 insertions(+) create mode 100644 plugins/modules/ec2_vpc_endpoint.py create mode 120000 plugins/modules/ec2_vpc_endpoint_facts.py create mode 100644 plugins/modules/ec2_vpc_endpoint_info.py diff --git a/plugins/modules/ec2_vpc_endpoint.py b/plugins/modules/ec2_vpc_endpoint.py new file mode 100644 index 00000000000..7c1f9f619ab --- /dev/null +++ b/plugins/modules/ec2_vpc_endpoint.py @@ -0,0 +1,400 @@ +#!/usr/bin/python +# Copyright: Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + + +ANSIBLE_METADATA = {'metadata_version': '1.1', + 'status': ['preview'], + 'supported_by': 'community'} + + +DOCUMENTATION = ''' +module: ec2_vpc_endpoint +short_description: Create and delete AWS VPC Endpoints. +description: + - Creates AWS VPC endpoints. + - Deletes AWS VPC endpoints. + - This module supports check mode. +requirements: [ boto3 ] +options: + vpc_id: + description: + - Required when creating a VPC endpoint. + required: false + type: str + service: + description: + - An AWS supported vpc endpoint service. Use the M(ec2_vpc_endpoint_info) + module to describe the supported endpoint services. + - Required when creating an endpoint. + required: false + type: str + policy: + description: + - A properly formatted json policy as string, see + U(https://github.com/ansible/ansible/issues/7005#issuecomment-42894813). + Cannot be used with I(policy_file). + - Option when creating an endpoint. If not provided AWS will + utilise a default policy which provides full access to the service. + required: false + type: json + policy_file: + description: + - The path to the properly json formatted policy file, see + U(https://github.com/ansible/ansible/issues/7005#issuecomment-42894813) + on how to use it properly. Cannot be used with I(policy). + - Option when creating an endpoint. If not provided AWS will + utilise a default policy which provides full access to the service. + required: false + aliases: [ "policy_path" ] + type: path + state: + description: + - present to ensure resource is created. + - absent to remove resource + required: false + default: present + choices: [ "present", "absent"] + type: str + wait: + description: + - When specified, will wait for either available status for state present. + Unfortunately this is ignored for delete actions due to a difference in + behaviour from AWS. + required: false + default: no + type: bool + wait_timeout: + description: + - Used in conjunction with wait. Number of seconds to wait for status. + Unfortunately this is ignored for delete actions due to a difference in + behaviour from AWS. + required: false + default: 320 + type: int + route_table_ids: + description: + - List of one or more route table ids to attach to the endpoint. A route + is added to the route table with the destination of the endpoint if + provided. + required: false + type: list + elements: str + vpc_endpoint_id: + description: + - One or more vpc endpoint ids to remove from the AWS account + required: false + type: str + client_token: + description: + - Optional client token to ensure idempotency + required: false + type: str +author: Karen Cheng (@Etherdaemon) +extends_documentation_fragment: +- ansible.amazon.aws +- ansible.amazon.ec2 + +''' + +EXAMPLES = ''' +# Note: These examples do not set authentication details, see the AWS Guide for details. + +- name: Create new vpc endpoint with a json template for policy + ec2_vpc_endpoint: + state: present + region: ap-southeast-2 + vpc_id: vpc-12345678 + service: com.amazonaws.ap-southeast-2.s3 + policy: " {{ lookup( 'template', 'endpoint_policy.json.j2') }} " + route_table_ids: + - rtb-12345678 + - rtb-87654321 + register: new_vpc_endpoint + +- name: Create new vpc endpoint with the default policy + ec2_vpc_endpoint: + state: present + region: ap-southeast-2 + vpc_id: vpc-12345678 + service: com.amazonaws.ap-southeast-2.s3 + route_table_ids: + - rtb-12345678 + - rtb-87654321 + register: new_vpc_endpoint + +- name: Create new vpc endpoint with json file + ec2_vpc_endpoint: + state: present + region: ap-southeast-2 + vpc_id: vpc-12345678 + service: com.amazonaws.ap-southeast-2.s3 + policy_file: "{{ role_path }}/files/endpoint_policy.json" + route_table_ids: + - rtb-12345678 + - rtb-87654321 + register: new_vpc_endpoint + +- name: Delete newly created vpc endpoint + ec2_vpc_endpoint: + state: absent + vpc_endpoint_id: "{{ new_vpc_endpoint.result['VpcEndpointId'] }}" + region: ap-southeast-2 +''' + +RETURN = ''' +endpoints: + description: The resulting endpoints from the module call + returned: success + type: list + sample: [ + { + "creation_timestamp": "2017-02-20T05:04:15+00:00", + "policy_document": { + "Id": "Policy1450910922815", + "Statement": [ + { + "Action": "s3:*", + "Effect": "Allow", + "Principal": "*", + "Resource": [ + "arn:aws:s3:::*/*", + "arn:aws:s3:::*" + ], + "Sid": "Stmt1450910920641" + } + ], + "Version": "2012-10-17" + }, + "route_table_ids": [ + "rtb-abcd1234" + ], + "service_name": "com.amazonaws.ap-southeast-2.s3", + "vpc_endpoint_id": "vpce-a1b2c3d4", + "vpc_id": "vpc-abbad0d0" + } + ] +''' + +import datetime +import json +import time +import traceback + +try: + import botocore +except ImportError: + pass # will be picked up by imported HAS_BOTO3 + +from ansible.module_utils.basic import AnsibleModule +from ansible_collections.ansible.amazon.plugins.module_utils.ec2 import (get_aws_connection_info, boto3_conn, ec2_argument_spec, HAS_BOTO3, + camel_dict_to_snake_dict) +from ansible.module_utils.six import string_types + + +def date_handler(obj): + return obj.isoformat() if hasattr(obj, 'isoformat') else obj + + +def wait_for_status(client, module, resource_id, status): + polling_increment_secs = 15 + max_retries = (module.params.get('wait_timeout') // polling_increment_secs) + status_achieved = False + + for x in range(0, max_retries): + try: + resource = get_endpoints(client, module, resource_id)['VpcEndpoints'][0] + if resource['State'] == status: + status_achieved = True + break + else: + time.sleep(polling_increment_secs) + except botocore.exceptions.ClientError as e: + module.fail_json(msg=str(e), exception=traceback.format_exc(), + **camel_dict_to_snake_dict(e.response)) + + return status_achieved, resource + + +def get_endpoints(client, module, resource_id=None): + params = dict() + if resource_id: + params['VpcEndpointIds'] = [resource_id] + + result = json.loads(json.dumps(client.describe_vpc_endpoints(**params), default=date_handler)) + return result + + +def setup_creation(client, module): + vpc_id = module.params.get('vpc_id') + service_name = module.params.get('service') + + if module.params.get('route_table_ids'): + route_table_ids = module.params.get('route_table_ids') + existing_endpoints = get_endpoints(client, module) + for endpoint in existing_endpoints['VpcEndpoints']: + if endpoint['VpcId'] == vpc_id and endpoint['ServiceName'] == service_name: + sorted_endpoint_rt_ids = sorted(endpoint['RouteTableIds']) + sorted_route_table_ids = sorted(route_table_ids) + if sorted_endpoint_rt_ids == sorted_route_table_ids: + return False, camel_dict_to_snake_dict(endpoint) + + changed, result = create_vpc_endpoint(client, module) + + return changed, json.loads(json.dumps(result, default=date_handler)) + + +def create_vpc_endpoint(client, module): + params = dict() + changed = False + token_provided = False + params['VpcId'] = module.params.get('vpc_id') + params['ServiceName'] = module.params.get('service') + params['DryRun'] = module.check_mode + + if module.params.get('route_table_ids'): + params['RouteTableIds'] = module.params.get('route_table_ids') + + if module.params.get('client_token'): + token_provided = True + request_time = datetime.datetime.utcnow() + params['ClientToken'] = module.params.get('client_token') + + policy = None + if module.params.get('policy'): + try: + policy = json.loads(module.params.get('policy')) + except ValueError as e: + module.fail_json(msg=str(e), exception=traceback.format_exc(), + **camel_dict_to_snake_dict(e.response)) + + elif module.params.get('policy_file'): + try: + with open(module.params.get('policy_file'), 'r') as json_data: + policy = json.load(json_data) + except Exception as e: + module.fail_json(msg=str(e), exception=traceback.format_exc(), + **camel_dict_to_snake_dict(e.response)) + + if policy: + params['PolicyDocument'] = json.dumps(policy) + + try: + changed = True + result = camel_dict_to_snake_dict(client.create_vpc_endpoint(**params)['VpcEndpoint']) + if token_provided and (request_time > result['creation_timestamp'].replace(tzinfo=None)): + changed = False + elif module.params.get('wait') and not module.check_mode: + status_achieved, result = wait_for_status(client, module, result['vpc_endpoint_id'], 'available') + if not status_achieved: + module.fail_json(msg='Error waiting for vpc endpoint to become available - please check the AWS console') + except botocore.exceptions.ClientError as e: + if "DryRunOperation" in e.message: + changed = True + result = 'Would have created VPC Endpoint if not in check mode' + elif "IdempotentParameterMismatch" in e.message: + module.fail_json(msg="IdempotentParameterMismatch - updates of endpoints are not allowed by the API") + elif "RouteAlreadyExists" in e.message: + module.fail_json(msg="RouteAlreadyExists for one of the route tables - update is not allowed by the API") + else: + module.fail_json(msg=str(e), exception=traceback.format_exc(), + **camel_dict_to_snake_dict(e.response)) + except Exception as e: + module.fail_json(msg=str(e), exception=traceback.format_exc(), + **camel_dict_to_snake_dict(e.response)) + + return changed, result + + +def setup_removal(client, module): + params = dict() + changed = False + params['DryRun'] = module.check_mode + if isinstance(module.params.get('vpc_endpoint_id'), string_types): + params['VpcEndpointIds'] = [module.params.get('vpc_endpoint_id')] + else: + params['VpcEndpointIds'] = module.params.get('vpc_endpoint_id') + try: + result = client.delete_vpc_endpoints(**params)['Unsuccessful'] + if not module.check_mode and (result != []): + module.fail_json(msg=result) + except botocore.exceptions.ClientError as e: + if "DryRunOperation" in e.message: + changed = True + result = 'Would have deleted VPC Endpoint if not in check mode' + else: + module.fail_json(msg=str(e), exception=traceback.format_exc(), + **camel_dict_to_snake_dict(e.response)) + except Exception as e: + module.fail_json(msg=str(e), exception=traceback.format_exc(), + **camel_dict_to_snake_dict(e.response)) + return changed, result + + +def main(): + argument_spec = ec2_argument_spec() + argument_spec.update( + dict( + vpc_id=dict(), + service=dict(), + policy=dict(type='json'), + policy_file=dict(type='path', aliases=['policy_path']), + state=dict(default='present', choices=['present', 'absent']), + wait=dict(type='bool', default=False), + wait_timeout=dict(type='int', default=320, required=False), + route_table_ids=dict(type='list'), + vpc_endpoint_id=dict(), + client_token=dict(), + ) + ) + module = AnsibleModule( + argument_spec=argument_spec, + supports_check_mode=True, + mutually_exclusive=[['policy', 'policy_file']], + required_if=[ + ['state', 'present', ['vpc_id', 'service']], + ['state', 'absent', ['vpc_endpoint_id']], + ] + ) + + # Validate Requirements + if not HAS_BOTO3: + module.fail_json(msg='botocore and boto3 are required for this module') + + state = module.params.get('state') + + try: + region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module, boto3=True) + except NameError as e: + # Getting around the get_aws_connection_info boto reliance for region + if "global name 'boto' is not defined" in e.message: + module.params['region'] = botocore.session.get_session().get_config_variable('region') + if not module.params['region']: + module.fail_json(msg="Error - no region provided") + else: + module.fail_json(msg="Can't retrieve connection information - " + str(e), + exception=traceback.format_exc(), + **camel_dict_to_snake_dict(e.response)) + + try: + region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module, boto3=True) + ec2 = boto3_conn(module, conn_type='client', resource='ec2', region=region, endpoint=ec2_url, **aws_connect_kwargs) + except botocore.exceptions.NoCredentialsError as e: + module.fail_json(msg="Failed to connect to AWS due to wrong or missing credentials: %s" % str(e), + exception=traceback.format_exc(), + **camel_dict_to_snake_dict(e.response)) + + # Ensure resource is present + if state == 'present': + (changed, results) = setup_creation(ec2, module) + else: + (changed, results) = setup_removal(ec2, module) + + module.exit_json(changed=changed, result=results) + + +if __name__ == '__main__': + main() diff --git a/plugins/modules/ec2_vpc_endpoint_facts.py b/plugins/modules/ec2_vpc_endpoint_facts.py new file mode 120000 index 00000000000..d2a144a7b86 --- /dev/null +++ b/plugins/modules/ec2_vpc_endpoint_facts.py @@ -0,0 +1 @@ +ec2_vpc_endpoint_info.py \ No newline at end of file diff --git a/plugins/modules/ec2_vpc_endpoint_info.py b/plugins/modules/ec2_vpc_endpoint_info.py new file mode 100644 index 00000000000..d82a3b8faf6 --- /dev/null +++ b/plugins/modules/ec2_vpc_endpoint_info.py @@ -0,0 +1,200 @@ +#!/usr/bin/python +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + + +ANSIBLE_METADATA = {'metadata_version': '1.1', + 'status': ['preview'], + 'supported_by': 'community'} + +DOCUMENTATION = ''' +module: ec2_vpc_endpoint_info +short_description: Retrieves AWS VPC endpoints details using AWS methods. +description: + - Gets various details related to AWS VPC Endpoints. + - This module was called C(ec2_vpc_endpoint_facts) before Ansible 2.9. The usage did not change. +requirements: [ boto3 ] +options: + query: + description: + - Specifies the query action to take. Services returns the supported + AWS services that can be specified when creating an endpoint. + required: True + choices: + - services + - endpoints + type: str + vpc_endpoint_ids: + description: + - Get details of specific endpoint IDs + type: list + elements: str + filters: + description: + - A dict of filters to apply. Each dict item consists of a filter key and a filter value. + See U(https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeVpcEndpoints.html) + for possible filters. + type: dict +author: Karen Cheng (@Etherdaemon) +extends_documentation_fragment: +- ansible.amazon.aws +- ansible.amazon.ec2 + +''' + +EXAMPLES = ''' +# Simple example of listing all support AWS services for VPC endpoints +- name: List supported AWS endpoint services + ec2_vpc_endpoint_info: + query: services + region: ap-southeast-2 + register: supported_endpoint_services + +- name: Get all endpoints in ap-southeast-2 region + ec2_vpc_endpoint_info: + query: endpoints + region: ap-southeast-2 + register: existing_endpoints + +- name: Get all endpoints with specific filters + ec2_vpc_endpoint_info: + query: endpoints + region: ap-southeast-2 + filters: + vpc-id: + - vpc-12345678 + - vpc-87654321 + vpc-endpoint-state: + - available + - pending + register: existing_endpoints + +- name: Get details on specific endpoint + ec2_vpc_endpoint_info: + query: endpoints + region: ap-southeast-2 + vpc_endpoint_ids: + - vpce-12345678 + register: endpoint_details +''' + +RETURN = ''' +service_names: + description: AWS VPC endpoint service names + returned: I(query) is C(services) + type: list + sample: + service_names: + - com.amazonaws.ap-southeast-2.s3 +vpc_endpoints: + description: + - A list of endpoints that match the query. Each endpoint has the keys creation_timestamp, + policy_document, route_table_ids, service_name, state, vpc_endpoint_id, vpc_id. + returned: I(query) is C(endpoints) + type: list + sample: + vpc_endpoints: + - creation_timestamp: "2017-02-16T11:06:48+00:00" + policy_document: > + "{\"Version\":\"2012-10-17\",\"Id\":\"Policy1450910922815\", + \"Statement\":[{\"Sid\":\"Stmt1450910920641\",\"Effect\":\"Allow\", + \"Principal\":\"*\",\"Action\":\"s3:*\",\"Resource\":[\"arn:aws:s3:::*/*\",\"arn:aws:s3:::*\"]}]}" + route_table_ids: + - rtb-abcd1234 + service_name: "com.amazonaws.ap-southeast-2.s3" + state: "available" + vpc_endpoint_id: "vpce-abbad0d0" + vpc_id: "vpc-1111ffff" +''' + +import json + +try: + import botocore +except ImportError: + pass # will be picked up from imported HAS_BOTO3 + +from ansible.module_utils.basic import AnsibleModule +from ansible_collections.ansible.amazon.plugins.module_utils.ec2 import (ec2_argument_spec, boto3_conn, get_aws_connection_info, + ansible_dict_to_boto3_filter_list, HAS_BOTO3, camel_dict_to_snake_dict, AWSRetry) + + +def date_handler(obj): + return obj.isoformat() if hasattr(obj, 'isoformat') else obj + + +@AWSRetry.exponential_backoff() +def get_supported_services(client, module): + results = list() + params = dict() + while True: + response = client.describe_vpc_endpoint_services(**params) + results.extend(response['ServiceNames']) + if 'NextToken' in response: + params['NextToken'] = response['NextToken'] + else: + break + return dict(service_names=results) + + +@AWSRetry.exponential_backoff() +def get_endpoints(client, module): + results = list() + params = dict() + params['Filters'] = ansible_dict_to_boto3_filter_list(module.params.get('filters')) + if module.params.get('vpc_endpoint_ids'): + params['VpcEndpointIds'] = module.params.get('vpc_endpoint_ids') + while True: + response = client.describe_vpc_endpoints(**params) + results.extend(response['VpcEndpoints']) + if 'NextToken' in response: + params['NextToken'] = response['NextToken'] + else: + break + try: + results = json.loads(json.dumps(results, default=date_handler)) + except Exception as e: + module.fail_json(msg=str(e.message)) + return dict(vpc_endpoints=[camel_dict_to_snake_dict(result) for result in results]) + + +def main(): + argument_spec = ec2_argument_spec() + argument_spec.update( + dict( + query=dict(choices=['services', 'endpoints'], required=True), + filters=dict(default={}, type='dict'), + vpc_endpoint_ids=dict(type='list'), + ) + ) + + module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) + if module._name == 'ec2_vpc_endpoint_facts': + module.deprecate("The 'ec2_vpc_endpoint_facts' module has been renamed to 'ec2_vpc_endpoint_info'", version='2.13') + + # Validate Requirements + if not HAS_BOTO3: + module.fail_json(msg='botocore and boto3 are required.') + + try: + region, ec2_url, aws_connect_params = get_aws_connection_info(module, boto3=True) + if region: + connection = boto3_conn(module, conn_type='client', resource='ec2', region=region, endpoint=ec2_url, **aws_connect_params) + else: + module.fail_json(msg="region must be specified") + except botocore.exceptions.NoCredentialsError as e: + module.fail_json(msg=str(e)) + + invocations = { + 'services': get_supported_services, + 'endpoints': get_endpoints, + } + results = invocations[module.params.get('query')](connection, module) + + module.exit_json(**results) + + +if __name__ == '__main__': + main() From e23ed4f129feaa95be51d8bffeeb7023266ce344 Mon Sep 17 00:00:00 2001 From: jillr Date: Tue, 3 Mar 2020 19:43:21 +0000 Subject: [PATCH 05/37] migration test cleanup This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/13b104b912784bb31a0bff23eed4c27b0f5e0283 --- plugins/modules/ec2_vpc_endpoint.py | 8 ++++++-- plugins/modules/ec2_vpc_endpoint_info.py | 10 ++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/plugins/modules/ec2_vpc_endpoint.py b/plugins/modules/ec2_vpc_endpoint.py index 7c1f9f619ab..aa55014c88b 100644 --- a/plugins/modules/ec2_vpc_endpoint.py +++ b/plugins/modules/ec2_vpc_endpoint.py @@ -190,8 +190,12 @@ pass # will be picked up by imported HAS_BOTO3 from ansible.module_utils.basic import AnsibleModule -from ansible_collections.ansible.amazon.plugins.module_utils.ec2 import (get_aws_connection_info, boto3_conn, ec2_argument_spec, HAS_BOTO3, - camel_dict_to_snake_dict) +from ansible_collections.ansible.amazon.plugins.module_utils.ec2 import (get_aws_connection_info, + boto3_conn, + ec2_argument_spec, + HAS_BOTO3, + camel_dict_to_snake_dict, + ) from ansible.module_utils.six import string_types diff --git a/plugins/modules/ec2_vpc_endpoint_info.py b/plugins/modules/ec2_vpc_endpoint_info.py index d82a3b8faf6..1436080ef17 100644 --- a/plugins/modules/ec2_vpc_endpoint_info.py +++ b/plugins/modules/ec2_vpc_endpoint_info.py @@ -117,8 +117,14 @@ pass # will be picked up from imported HAS_BOTO3 from ansible.module_utils.basic import AnsibleModule -from ansible_collections.ansible.amazon.plugins.module_utils.ec2 import (ec2_argument_spec, boto3_conn, get_aws_connection_info, - ansible_dict_to_boto3_filter_list, HAS_BOTO3, camel_dict_to_snake_dict, AWSRetry) +from ansible_collections.ansible.amazon.plugins.module_utils.ec2 import (ec2_argument_spec, + boto3_conn, + get_aws_connection_info, + ansible_dict_to_boto3_filter_list, + HAS_BOTO3, + camel_dict_to_snake_dict, + AWSRetry, + ) def date_handler(obj): From 028bfe57aece6736ecba95b6e863d8dd7cc96902 Mon Sep 17 00:00:00 2001 From: Jill R <4121322+jillr@users.noreply.github.com> Date: Wed, 25 Mar 2020 15:39:40 -0700 Subject: [PATCH 06/37] Rename collection (#12) * Rename core collection Rename references to ansible.amazon to amazon.aws. * Rename community.amazon to community.aws Fix pep8 line lengths for rewritten amazon.aws imports * Missed a path in shippable.sh * Dependency repos moved This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/235c5db571cc45db5839476c94356c9b91e1f228 --- plugins/modules/ec2_vpc_endpoint.py | 16 ++++++++-------- plugins/modules/ec2_vpc_endpoint_info.py | 20 ++++++++++---------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/plugins/modules/ec2_vpc_endpoint.py b/plugins/modules/ec2_vpc_endpoint.py index aa55014c88b..760af35c62e 100644 --- a/plugins/modules/ec2_vpc_endpoint.py +++ b/plugins/modules/ec2_vpc_endpoint.py @@ -95,8 +95,8 @@ type: str author: Karen Cheng (@Etherdaemon) extends_documentation_fragment: -- ansible.amazon.aws -- ansible.amazon.ec2 +- amazon.aws.aws +- amazon.aws.ec2 ''' @@ -190,12 +190,12 @@ pass # will be picked up by imported HAS_BOTO3 from ansible.module_utils.basic import AnsibleModule -from ansible_collections.ansible.amazon.plugins.module_utils.ec2 import (get_aws_connection_info, - boto3_conn, - ec2_argument_spec, - HAS_BOTO3, - camel_dict_to_snake_dict, - ) +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import (get_aws_connection_info, + boto3_conn, + ec2_argument_spec, + HAS_BOTO3, + camel_dict_to_snake_dict, + ) from ansible.module_utils.six import string_types diff --git a/plugins/modules/ec2_vpc_endpoint_info.py b/plugins/modules/ec2_vpc_endpoint_info.py index 1436080ef17..a43ef54ac13 100644 --- a/plugins/modules/ec2_vpc_endpoint_info.py +++ b/plugins/modules/ec2_vpc_endpoint_info.py @@ -39,8 +39,8 @@ type: dict author: Karen Cheng (@Etherdaemon) extends_documentation_fragment: -- ansible.amazon.aws -- ansible.amazon.ec2 +- amazon.aws.aws +- amazon.aws.ec2 ''' @@ -117,14 +117,14 @@ pass # will be picked up from imported HAS_BOTO3 from ansible.module_utils.basic import AnsibleModule -from ansible_collections.ansible.amazon.plugins.module_utils.ec2 import (ec2_argument_spec, - boto3_conn, - get_aws_connection_info, - ansible_dict_to_boto3_filter_list, - HAS_BOTO3, - camel_dict_to_snake_dict, - AWSRetry, - ) +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import (ec2_argument_spec, + boto3_conn, + get_aws_connection_info, + ansible_dict_to_boto3_filter_list, + HAS_BOTO3, + camel_dict_to_snake_dict, + AWSRetry, + ) def date_handler(obj): From c2d98792702d93fdbdb5f301be4bd3918e21e3d6 Mon Sep 17 00:00:00 2001 From: Jill R <4121322+jillr@users.noreply.github.com> Date: Tue, 19 May 2020 16:06:12 -0700 Subject: [PATCH 07/37] Remove METADATA and cleanup galaxy.yml (#70) * Remove ANSIBLE_METADATA entirely, see ansible/ansible/pull/69454. Remove `license` field from galaxy.yml, in favor of `license_file`. This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/05672a64e2362cc2d865b5af6a57da6bc3cd08e3 --- plugins/modules/ec2_vpc_endpoint.py | 5 ----- plugins/modules/ec2_vpc_endpoint_info.py | 4 ---- 2 files changed, 9 deletions(-) diff --git a/plugins/modules/ec2_vpc_endpoint.py b/plugins/modules/ec2_vpc_endpoint.py index 760af35c62e..1b89387bf36 100644 --- a/plugins/modules/ec2_vpc_endpoint.py +++ b/plugins/modules/ec2_vpc_endpoint.py @@ -6,11 +6,6 @@ __metaclass__ = type -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'community'} - - DOCUMENTATION = ''' module: ec2_vpc_endpoint short_description: Create and delete AWS VPC Endpoints. diff --git a/plugins/modules/ec2_vpc_endpoint_info.py b/plugins/modules/ec2_vpc_endpoint_info.py index a43ef54ac13..fa4f8c59713 100644 --- a/plugins/modules/ec2_vpc_endpoint_info.py +++ b/plugins/modules/ec2_vpc_endpoint_info.py @@ -5,10 +5,6 @@ __metaclass__ = type -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'community'} - DOCUMENTATION = ''' module: ec2_vpc_endpoint_info short_description: Retrieves AWS VPC endpoints details using AWS methods. From 75e2b5504258f20e8408b9a9eb7367e9c6cf8adb Mon Sep 17 00:00:00 2001 From: Jill R <4121322+jillr@users.noreply.github.com> Date: Tue, 16 Jun 2020 11:23:52 -0700 Subject: [PATCH 08/37] Collections related fixes for CI (#96) * Update module deprecations Switch version to `removed_at_date` * Don't install amazon.aws from galaxy We've been using galaxy to install amazon.aws in shippable, but that doesn't really work if we aren't publising faster. Get that collection from git so it is most up to date. * We need to declare python test deps now * missed a python dep This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/7cd211e9383db26bc2aa4cc06e657cf60ed0acc0 --- plugins/modules/ec2_vpc_endpoint_info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/ec2_vpc_endpoint_info.py b/plugins/modules/ec2_vpc_endpoint_info.py index fa4f8c59713..75ceb6b9bc7 100644 --- a/plugins/modules/ec2_vpc_endpoint_info.py +++ b/plugins/modules/ec2_vpc_endpoint_info.py @@ -174,7 +174,7 @@ def main(): module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) if module._name == 'ec2_vpc_endpoint_facts': - module.deprecate("The 'ec2_vpc_endpoint_facts' module has been renamed to 'ec2_vpc_endpoint_info'", version='2.13') + module.deprecate("The 'ec2_vpc_endpoint_facts' module has been renamed to 'ec2_vpc_endpoint_info'", date='2021-12-01', collection_name='community.aws') # Validate Requirements if not HAS_BOTO3: From 60937a00a38fc873fb7555cbea1fb001cd49011c Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Wed, 17 Jun 2020 01:24:54 +0530 Subject: [PATCH 09/37] Update Examples with FQCN (#67) Updated module examples with FQCN Signed-off-by: Abhijeet Kasurde This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/98173aefbbceed7fc0d9db62687b73f96a55a999 --- plugins/modules/ec2_vpc_endpoint.py | 10 +++++----- plugins/modules/ec2_vpc_endpoint_info.py | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/plugins/modules/ec2_vpc_endpoint.py b/plugins/modules/ec2_vpc_endpoint.py index 1b89387bf36..7978c48dfde 100644 --- a/plugins/modules/ec2_vpc_endpoint.py +++ b/plugins/modules/ec2_vpc_endpoint.py @@ -22,7 +22,7 @@ type: str service: description: - - An AWS supported vpc endpoint service. Use the M(ec2_vpc_endpoint_info) + - An AWS supported vpc endpoint service. Use the M(community.aws.ec2_vpc_endpoint_info) module to describe the supported endpoint services. - Required when creating an endpoint. required: false @@ -99,7 +99,7 @@ # Note: These examples do not set authentication details, see the AWS Guide for details. - name: Create new vpc endpoint with a json template for policy - ec2_vpc_endpoint: + community.aws.ec2_vpc_endpoint: state: present region: ap-southeast-2 vpc_id: vpc-12345678 @@ -111,7 +111,7 @@ register: new_vpc_endpoint - name: Create new vpc endpoint with the default policy - ec2_vpc_endpoint: + community.aws.ec2_vpc_endpoint: state: present region: ap-southeast-2 vpc_id: vpc-12345678 @@ -122,7 +122,7 @@ register: new_vpc_endpoint - name: Create new vpc endpoint with json file - ec2_vpc_endpoint: + community.aws.ec2_vpc_endpoint: state: present region: ap-southeast-2 vpc_id: vpc-12345678 @@ -134,7 +134,7 @@ register: new_vpc_endpoint - name: Delete newly created vpc endpoint - ec2_vpc_endpoint: + community.aws.ec2_vpc_endpoint: state: absent vpc_endpoint_id: "{{ new_vpc_endpoint.result['VpcEndpointId'] }}" region: ap-southeast-2 diff --git a/plugins/modules/ec2_vpc_endpoint_info.py b/plugins/modules/ec2_vpc_endpoint_info.py index 75ceb6b9bc7..0f23ca53217 100644 --- a/plugins/modules/ec2_vpc_endpoint_info.py +++ b/plugins/modules/ec2_vpc_endpoint_info.py @@ -43,19 +43,19 @@ EXAMPLES = ''' # Simple example of listing all support AWS services for VPC endpoints - name: List supported AWS endpoint services - ec2_vpc_endpoint_info: + community.aws.ec2_vpc_endpoint_info: query: services region: ap-southeast-2 register: supported_endpoint_services - name: Get all endpoints in ap-southeast-2 region - ec2_vpc_endpoint_info: + community.aws.ec2_vpc_endpoint_info: query: endpoints region: ap-southeast-2 register: existing_endpoints - name: Get all endpoints with specific filters - ec2_vpc_endpoint_info: + community.aws.ec2_vpc_endpoint_info: query: endpoints region: ap-southeast-2 filters: @@ -68,7 +68,7 @@ register: existing_endpoints - name: Get details on specific endpoint - ec2_vpc_endpoint_info: + community.aws.ec2_vpc_endpoint_info: query: endpoints region: ap-southeast-2 vpc_endpoint_ids: From 541340a839e2a6ace9b45c357083d8246e42a4b3 Mon Sep 17 00:00:00 2001 From: Jill R <4121322+jillr@users.noreply.github.com> Date: Wed, 17 Jun 2020 09:31:32 -0700 Subject: [PATCH 10/37] Update docs (#99) * Update docs Remove .git from repo url so links in readme will generate correctly Add required ansible version Run latest version of add_docs.py Add version_added string to modules * galaxy.yml was missing authors This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/96ee268e5267f5b12c3d59892bc1279f75aa3135 --- plugins/modules/ec2_vpc_endpoint.py | 1 + plugins/modules/ec2_vpc_endpoint_info.py | 1 + 2 files changed, 2 insertions(+) diff --git a/plugins/modules/ec2_vpc_endpoint.py b/plugins/modules/ec2_vpc_endpoint.py index 7978c48dfde..920cf45ca6e 100644 --- a/plugins/modules/ec2_vpc_endpoint.py +++ b/plugins/modules/ec2_vpc_endpoint.py @@ -9,6 +9,7 @@ DOCUMENTATION = ''' module: ec2_vpc_endpoint short_description: Create and delete AWS VPC Endpoints. +version_added: 1.0.0 description: - Creates AWS VPC endpoints. - Deletes AWS VPC endpoints. diff --git a/plugins/modules/ec2_vpc_endpoint_info.py b/plugins/modules/ec2_vpc_endpoint_info.py index 0f23ca53217..a1f3ff0a901 100644 --- a/plugins/modules/ec2_vpc_endpoint_info.py +++ b/plugins/modules/ec2_vpc_endpoint_info.py @@ -8,6 +8,7 @@ DOCUMENTATION = ''' module: ec2_vpc_endpoint_info short_description: Retrieves AWS VPC endpoints details using AWS methods. +version_added: 1.0.0 description: - Gets various details related to AWS VPC Endpoints. - This module was called C(ec2_vpc_endpoint_facts) before Ansible 2.9. The usage did not change. From d977e99c9786b425274985fbb0d562d2c1a57bdf Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Thu, 16 Jul 2020 01:31:41 +0530 Subject: [PATCH 11/37] Docs: sanity fixes (#133) Signed-off-by: Abhijeet Kasurde This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/059cf9efc95bb976de21ab4f8e4d9ddd001983fc --- plugins/modules/ec2_vpc_endpoint.py | 8 ++++---- plugins/modules/ec2_vpc_endpoint_info.py | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/plugins/modules/ec2_vpc_endpoint.py b/plugins/modules/ec2_vpc_endpoint.py index 920cf45ca6e..833e64ae1db 100644 --- a/plugins/modules/ec2_vpc_endpoint.py +++ b/plugins/modules/ec2_vpc_endpoint.py @@ -6,7 +6,7 @@ __metaclass__ = type -DOCUMENTATION = ''' +DOCUMENTATION = r''' module: ec2_vpc_endpoint short_description: Create and delete AWS VPC Endpoints. version_added: 1.0.0 @@ -96,7 +96,7 @@ ''' -EXAMPLES = ''' +EXAMPLES = r''' # Note: These examples do not set authentication details, see the AWS Guide for details. - name: Create new vpc endpoint with a json template for policy @@ -141,7 +141,7 @@ region: ap-southeast-2 ''' -RETURN = ''' +RETURN = r''' endpoints: description: The resulting endpoints from the module call returned: success @@ -345,7 +345,7 @@ def main(): state=dict(default='present', choices=['present', 'absent']), wait=dict(type='bool', default=False), wait_timeout=dict(type='int', default=320, required=False), - route_table_ids=dict(type='list'), + route_table_ids=dict(type='list', elements='str'), vpc_endpoint_id=dict(), client_token=dict(), ) diff --git a/plugins/modules/ec2_vpc_endpoint_info.py b/plugins/modules/ec2_vpc_endpoint_info.py index a1f3ff0a901..eeb7a7d80d1 100644 --- a/plugins/modules/ec2_vpc_endpoint_info.py +++ b/plugins/modules/ec2_vpc_endpoint_info.py @@ -5,7 +5,7 @@ __metaclass__ = type -DOCUMENTATION = ''' +DOCUMENTATION = r''' module: ec2_vpc_endpoint_info short_description: Retrieves AWS VPC endpoints details using AWS methods. version_added: 1.0.0 @@ -41,7 +41,7 @@ ''' -EXAMPLES = ''' +EXAMPLES = r''' # Simple example of listing all support AWS services for VPC endpoints - name: List supported AWS endpoint services community.aws.ec2_vpc_endpoint_info: @@ -77,7 +77,7 @@ register: endpoint_details ''' -RETURN = ''' +RETURN = r''' service_names: description: AWS VPC endpoint service names returned: I(query) is C(services) @@ -169,7 +169,7 @@ def main(): dict( query=dict(choices=['services', 'endpoints'], required=True), filters=dict(default={}, type='dict'), - vpc_endpoint_ids=dict(type='list'), + vpc_endpoint_ids=dict(type='list', elements='str'), ) ) From e1ac60f77c19c71f83948da75ddb21fe91c50fec Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Wed, 12 Aug 2020 13:06:35 +0200 Subject: [PATCH 12/37] Bulk migration to AnsibleAWSModule (#173) * Update comments to reference AnsibleAWSModule rather than AnsibleModule * Bulk re-order imports and split onto one from import per-line. * Add AnsibleAWSModule imports * Migrate boto 2 based modules to AnsibleAWSModule * Move boto3-only modules over to AnsibleAWSModule * Remove extra ec2_argument_spec calls - not needed now we're using AnsibleAWSModule * Remove most HAS_BOTO3 code, it's handled by AnsibleAWSModule * Handle missing Boto 2 consistently (HAS_BOTO) * Remove AnsibleModule imports * Changelog fragment This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/818c6d2faa046974a9bdfa9346122d11e5bef3b1 --- plugins/modules/ec2_vpc_endpoint.py | 48 ++++++++++-------------- plugins/modules/ec2_vpc_endpoint_info.py | 33 ++++++---------- 2 files changed, 32 insertions(+), 49 deletions(-) diff --git a/plugins/modules/ec2_vpc_endpoint.py b/plugins/modules/ec2_vpc_endpoint.py index 833e64ae1db..e4e98fb4067 100644 --- a/plugins/modules/ec2_vpc_endpoint.py +++ b/plugins/modules/ec2_vpc_endpoint.py @@ -183,17 +183,15 @@ try: import botocore except ImportError: - pass # will be picked up by imported HAS_BOTO3 - -from ansible.module_utils.basic import AnsibleModule -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import (get_aws_connection_info, - boto3_conn, - ec2_argument_spec, - HAS_BOTO3, - camel_dict_to_snake_dict, - ) + pass # Handled by AnsibleAWSModule + from ansible.module_utils.six import string_types +from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import get_aws_connection_info +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import boto3_conn +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict + def date_handler(obj): return obj.isoformat() if hasattr(obj, 'isoformat') else obj @@ -335,35 +333,29 @@ def setup_removal(client, module): def main(): - argument_spec = ec2_argument_spec() - argument_spec.update( - dict( - vpc_id=dict(), - service=dict(), - policy=dict(type='json'), - policy_file=dict(type='path', aliases=['policy_path']), - state=dict(default='present', choices=['present', 'absent']), - wait=dict(type='bool', default=False), - wait_timeout=dict(type='int', default=320, required=False), - route_table_ids=dict(type='list', elements='str'), - vpc_endpoint_id=dict(), - client_token=dict(), - ) + argument_spec = dict( + vpc_id=dict(), + service=dict(), + policy=dict(type='json'), + policy_file=dict(type='path', aliases=['policy_path']), + state=dict(default='present', choices=['present', 'absent']), + wait=dict(type='bool', default=False), + wait_timeout=dict(type='int', default=320, required=False), + route_table_ids=dict(type='list', elements='str'), + vpc_endpoint_id=dict(), + client_token=dict(), ) - module = AnsibleModule( + module = AnsibleAWSModule( argument_spec=argument_spec, supports_check_mode=True, mutually_exclusive=[['policy', 'policy_file']], required_if=[ ['state', 'present', ['vpc_id', 'service']], ['state', 'absent', ['vpc_endpoint_id']], - ] + ], ) # Validate Requirements - if not HAS_BOTO3: - module.fail_json(msg='botocore and boto3 are required for this module') - state = module.params.get('state') try: diff --git a/plugins/modules/ec2_vpc_endpoint_info.py b/plugins/modules/ec2_vpc_endpoint_info.py index eeb7a7d80d1..a48b886a179 100644 --- a/plugins/modules/ec2_vpc_endpoint_info.py +++ b/plugins/modules/ec2_vpc_endpoint_info.py @@ -111,17 +111,14 @@ try: import botocore except ImportError: - pass # will be picked up from imported HAS_BOTO3 + pass # Handled by AnsibleAWSModule -from ansible.module_utils.basic import AnsibleModule -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import (ec2_argument_spec, - boto3_conn, - get_aws_connection_info, - ansible_dict_to_boto3_filter_list, - HAS_BOTO3, - camel_dict_to_snake_dict, - AWSRetry, - ) +from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import boto3_conn +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import get_aws_connection_info +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ansible_dict_to_boto3_filter_list +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry def date_handler(obj): @@ -164,23 +161,17 @@ def get_endpoints(client, module): def main(): - argument_spec = ec2_argument_spec() - argument_spec.update( - dict( - query=dict(choices=['services', 'endpoints'], required=True), - filters=dict(default={}, type='dict'), - vpc_endpoint_ids=dict(type='list', elements='str'), - ) + argument_spec = dict( + query=dict(choices=['services', 'endpoints'], required=True), + filters=dict(default={}, type='dict'), + vpc_endpoint_ids=dict(type='list', elements='str'), ) - module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) + module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=True) if module._name == 'ec2_vpc_endpoint_facts': module.deprecate("The 'ec2_vpc_endpoint_facts' module has been renamed to 'ec2_vpc_endpoint_info'", date='2021-12-01', collection_name='community.aws') # Validate Requirements - if not HAS_BOTO3: - module.fail_json(msg='botocore and boto3 are required.') - try: region, ec2_url, aws_connect_params = get_aws_connection_info(module, boto3=True) if region: From a6e64ce405d0ec477d3d0753a9f4c2d366365593 Mon Sep 17 00:00:00 2001 From: Vincent Vinet Date: Sat, 15 Aug 2020 09:11:59 -0400 Subject: [PATCH 13/37] =?UTF-8?q?Python=203=20compatibility=20error=20hand?= =?UTF-8?q?ling:=20use=20to=5Fnative(e)=20instead=20of=20str(e)=20or=20e.m?= =?UTF-8?q?e=E2=80=A6=20(#26)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Py3 compat error handling: use to_native(e) instead of str(e) or e.message * PR comment changes, use fail_json_aws and is_boto3_error_code This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/ffe14f95186399dc080019554035021015765872 --- plugins/modules/ec2_vpc_endpoint.py | 38 +++++++++++------------- plugins/modules/ec2_vpc_endpoint_info.py | 3 +- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/plugins/modules/ec2_vpc_endpoint.py b/plugins/modules/ec2_vpc_endpoint.py index e4e98fb4067..3eaf2850e6e 100644 --- a/plugins/modules/ec2_vpc_endpoint.py +++ b/plugins/modules/ec2_vpc_endpoint.py @@ -186,8 +186,10 @@ pass # Handled by AnsibleAWSModule from ansible.module_utils.six import string_types +from ansible.module_utils._text import to_native from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule +from ansible_collections.amazon.aws.plugins.module_utils.core import is_boto3_error_code from ansible_collections.amazon.aws.plugins.module_utils.ec2 import get_aws_connection_info from ansible_collections.amazon.aws.plugins.module_utils.ec2 import boto3_conn from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict @@ -289,19 +291,15 @@ def create_vpc_endpoint(client, module): status_achieved, result = wait_for_status(client, module, result['vpc_endpoint_id'], 'available') if not status_achieved: module.fail_json(msg='Error waiting for vpc endpoint to become available - please check the AWS console') - except botocore.exceptions.ClientError as e: - if "DryRunOperation" in e.message: - changed = True - result = 'Would have created VPC Endpoint if not in check mode' - elif "IdempotentParameterMismatch" in e.message: - module.fail_json(msg="IdempotentParameterMismatch - updates of endpoints are not allowed by the API") - elif "RouteAlreadyExists" in e.message: - module.fail_json(msg="RouteAlreadyExists for one of the route tables - update is not allowed by the API") - else: - module.fail_json(msg=str(e), exception=traceback.format_exc(), - **camel_dict_to_snake_dict(e.response)) + except is_boto3_error_code('DryRunOperation'): + changed = True + result = 'Would have created VPC Endpoint if not in check mode' + except is_boto3_error_code('IdempotentParameterMismatch'): # pylint: disable=duplicate-except + module.fail_json(msg="IdempotentParameterMismatch - updates of endpoints are not allowed by the API") + except is_boto3_error_code('RouteAlreadyExists'): # pylint: disable=duplicate-except + module.fail_json(msg="RouteAlreadyExists for one of the route tables - update is not allowed by the API") except Exception as e: - module.fail_json(msg=str(e), exception=traceback.format_exc(), + module.fail_json(msg=to_native(e), exception=traceback.format_exc(), **camel_dict_to_snake_dict(e.response)) return changed, result @@ -319,15 +317,13 @@ def setup_removal(client, module): result = client.delete_vpc_endpoints(**params)['Unsuccessful'] if not module.check_mode and (result != []): module.fail_json(msg=result) - except botocore.exceptions.ClientError as e: - if "DryRunOperation" in e.message: - changed = True - result = 'Would have deleted VPC Endpoint if not in check mode' - else: - module.fail_json(msg=str(e), exception=traceback.format_exc(), - **camel_dict_to_snake_dict(e.response)) + except is_boto3_error_code('DryRunOperation'): + changed = True + result = 'Would have deleted VPC Endpoint if not in check mode' + except botocore.exceptions.ClientError as e: # pylint: disable=duplicate-except + module.fail_json_aws(e, "Failed to delete VPC endpoint") except Exception as e: - module.fail_json(msg=str(e), exception=traceback.format_exc(), + module.fail_json(msg=to_native(e), exception=traceback.format_exc(), **camel_dict_to_snake_dict(e.response)) return changed, result @@ -362,7 +358,7 @@ def main(): region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module, boto3=True) except NameError as e: # Getting around the get_aws_connection_info boto reliance for region - if "global name 'boto' is not defined" in e.message: + if "global name 'boto' is not defined" in to_native(e): module.params['region'] = botocore.session.get_session().get_config_variable('region') if not module.params['region']: module.fail_json(msg="Error - no region provided") diff --git a/plugins/modules/ec2_vpc_endpoint_info.py b/plugins/modules/ec2_vpc_endpoint_info.py index a48b886a179..f2b6da3adfa 100644 --- a/plugins/modules/ec2_vpc_endpoint_info.py +++ b/plugins/modules/ec2_vpc_endpoint_info.py @@ -113,6 +113,7 @@ except ImportError: pass # Handled by AnsibleAWSModule +from ansible.module_utils._text import to_native from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule from ansible_collections.amazon.aws.plugins.module_utils.ec2 import boto3_conn from ansible_collections.amazon.aws.plugins.module_utils.ec2 import get_aws_connection_info @@ -156,7 +157,7 @@ def get_endpoints(client, module): try: results = json.loads(json.dumps(results, default=date_handler)) except Exception as e: - module.fail_json(msg=str(e.message)) + module.fail_json_aws(e, msg="Failed to get endpoints") return dict(vpc_endpoints=[camel_dict_to_snake_dict(result) for result in results]) From ef312186bab6f6ec13620085567deee12ea8165c Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Wed, 26 Aug 2020 11:35:32 +0200 Subject: [PATCH 14/37] Cleanup: Bulk Migration from boto3_conn to module.client() (#188) * Migrate from boto3_conn to module.client * Simplify error handling when creating connections * Simplify Region handling * Remove unused imports * Changelog This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/6bdf00d2198927bdaa119ae76ddd379a8b6eeb3d --- plugins/modules/ec2_vpc_endpoint.py | 24 +++--------------------- plugins/modules/ec2_vpc_endpoint_info.py | 12 +++--------- 2 files changed, 6 insertions(+), 30 deletions(-) diff --git a/plugins/modules/ec2_vpc_endpoint.py b/plugins/modules/ec2_vpc_endpoint.py index 3eaf2850e6e..771ea52ba75 100644 --- a/plugins/modules/ec2_vpc_endpoint.py +++ b/plugins/modules/ec2_vpc_endpoint.py @@ -190,8 +190,6 @@ from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule from ansible_collections.amazon.aws.plugins.module_utils.core import is_boto3_error_code -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import get_aws_connection_info -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import boto3_conn from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict @@ -355,25 +353,9 @@ def main(): state = module.params.get('state') try: - region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module, boto3=True) - except NameError as e: - # Getting around the get_aws_connection_info boto reliance for region - if "global name 'boto' is not defined" in to_native(e): - module.params['region'] = botocore.session.get_session().get_config_variable('region') - if not module.params['region']: - module.fail_json(msg="Error - no region provided") - else: - module.fail_json(msg="Can't retrieve connection information - " + str(e), - exception=traceback.format_exc(), - **camel_dict_to_snake_dict(e.response)) - - try: - region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module, boto3=True) - ec2 = boto3_conn(module, conn_type='client', resource='ec2', region=region, endpoint=ec2_url, **aws_connect_kwargs) - except botocore.exceptions.NoCredentialsError as e: - module.fail_json(msg="Failed to connect to AWS due to wrong or missing credentials: %s" % str(e), - exception=traceback.format_exc(), - **camel_dict_to_snake_dict(e.response)) + ec2 = module.client('ec2') + except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: + module.fail_json_aws(e, msg='Failed to connect to AWS') # Ensure resource is present if state == 'present': diff --git a/plugins/modules/ec2_vpc_endpoint_info.py b/plugins/modules/ec2_vpc_endpoint_info.py index f2b6da3adfa..e72b487db3d 100644 --- a/plugins/modules/ec2_vpc_endpoint_info.py +++ b/plugins/modules/ec2_vpc_endpoint_info.py @@ -115,8 +115,6 @@ from ansible.module_utils._text import to_native from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import boto3_conn -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import get_aws_connection_info from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ansible_dict_to_boto3_filter_list from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry @@ -174,13 +172,9 @@ def main(): # Validate Requirements try: - region, ec2_url, aws_connect_params = get_aws_connection_info(module, boto3=True) - if region: - connection = boto3_conn(module, conn_type='client', resource='ec2', region=region, endpoint=ec2_url, **aws_connect_params) - else: - module.fail_json(msg="region must be specified") - except botocore.exceptions.NoCredentialsError as e: - module.fail_json(msg=str(e)) + connection = module.client('ec2') + except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: + module.fail_json_aws(e, msg='Failed to connect to AWS') invocations = { 'services': get_supported_services, From d91e690df7494109d8686de38879a80df2f9883a Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Sat, 16 Jan 2021 10:50:49 +0100 Subject: [PATCH 15/37] Bulk import cleanup (#360) * Split imports and reorder * Import camel_dict_to_snake_dict and snake_dict_to_camel_dict direct from ansible.module_utils.common.dict_transformations * Remove unused imports * Route53 Info was migrated to Boto3 drop the HAS_BOTO check and import * changelog This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/130cf3cc5980014020632f19fdab79c9bcf28add --- plugins/modules/ec2_vpc_endpoint_info.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/modules/ec2_vpc_endpoint_info.py b/plugins/modules/ec2_vpc_endpoint_info.py index e72b487db3d..7e259c6ca8e 100644 --- a/plugins/modules/ec2_vpc_endpoint_info.py +++ b/plugins/modules/ec2_vpc_endpoint_info.py @@ -113,11 +113,11 @@ except ImportError: pass # Handled by AnsibleAWSModule -from ansible.module_utils._text import to_native +from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict + from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ansible_dict_to_boto3_filter_list -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ansible_dict_to_boto3_filter_list def date_handler(obj): From e7361dec1a3cf4a3a7f3e6bd47cf9bcb9c8d706e Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Wed, 27 Jan 2021 09:17:44 +0100 Subject: [PATCH 16/37] Bulk migration to fail_json_aws (#361) * Split imports and sort * Move camel_dict_to_snake_dict imports to ansible.module_utils.common.dict_transformations * Cleanup unused imports * Bulk migration to fail_json_aws * Changelog This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/6c883156d250d3ed926a21dbd619b2b138246c5d --- plugins/modules/ec2_vpc_endpoint.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/plugins/modules/ec2_vpc_endpoint.py b/plugins/modules/ec2_vpc_endpoint.py index 771ea52ba75..4daaaeaa23e 100644 --- a/plugins/modules/ec2_vpc_endpoint.py +++ b/plugins/modules/ec2_vpc_endpoint.py @@ -186,11 +186,10 @@ pass # Handled by AnsibleAWSModule from ansible.module_utils.six import string_types -from ansible.module_utils._text import to_native +from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule from ansible_collections.amazon.aws.plugins.module_utils.core import is_boto3_error_code -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict def date_handler(obj): @@ -210,9 +209,8 @@ def wait_for_status(client, module, resource_id, status): break else: time.sleep(polling_increment_secs) - except botocore.exceptions.ClientError as e: - module.fail_json(msg=str(e), exception=traceback.format_exc(), - **camel_dict_to_snake_dict(e.response)) + except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: + module.fail_json_aws(e, msg='Failure while waiting for status') return status_achieved, resource @@ -296,9 +294,8 @@ def create_vpc_endpoint(client, module): module.fail_json(msg="IdempotentParameterMismatch - updates of endpoints are not allowed by the API") except is_boto3_error_code('RouteAlreadyExists'): # pylint: disable=duplicate-except module.fail_json(msg="RouteAlreadyExists for one of the route tables - update is not allowed by the API") - except Exception as e: - module.fail_json(msg=to_native(e), exception=traceback.format_exc(), - **camel_dict_to_snake_dict(e.response)) + except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: # pylint: disable=duplicate-except + module.fail_json_aws(e, msg="Failed to create VPC.") return changed, result @@ -318,11 +315,8 @@ def setup_removal(client, module): except is_boto3_error_code('DryRunOperation'): changed = True result = 'Would have deleted VPC Endpoint if not in check mode' - except botocore.exceptions.ClientError as e: # pylint: disable=duplicate-except + except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: # pylint: disable=duplicate-except module.fail_json_aws(e, "Failed to delete VPC endpoint") - except Exception as e: - module.fail_json(msg=to_native(e), exception=traceback.format_exc(), - **camel_dict_to_snake_dict(e.response)) return changed, result From acbbdb6dac7ed1914ed6ccb3f2eca57aed3e181c Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Fri, 12 Feb 2021 01:23:16 +0100 Subject: [PATCH 17/37] ec2_vpc_endpoint - deprecate policy_file (#366) * deprecate policy_file * ignore file * changelog This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/820e5cd7ed4512556c6dbedb888b3907a66e955e --- plugins/modules/ec2_vpc_endpoint.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/plugins/modules/ec2_vpc_endpoint.py b/plugins/modules/ec2_vpc_endpoint.py index 4daaaeaa23e..8e2426a525a 100644 --- a/plugins/modules/ec2_vpc_endpoint.py +++ b/plugins/modules/ec2_vpc_endpoint.py @@ -44,6 +44,9 @@ on how to use it properly. Cannot be used with I(policy). - Option when creating an endpoint. If not provided AWS will utilise a default policy which provides full access to the service. + - This option has been deprecated and will be removed after 2022-12-01 + to maintain the existing functionality please use the I(policy) option + and a file lookup. required: false aliases: [ "policy_path" ] type: path @@ -346,6 +349,11 @@ def main(): # Validate Requirements state = module.params.get('state') + if module.params.get('policy_file'): + module.deprecate('The policy_file option has been deprecated and' + ' will be removed after 2022-12-01', + date='2022-12-01', collection_name='community.aws') + try: ec2 = module.client('ec2') except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: From 04d50f6e60757e611d6d543a3f872063f28ac13e Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Fri, 12 Feb 2021 01:32:24 +0100 Subject: [PATCH 18/37] ec2_vpc_endpoint - fixup deletion 'changed' (#362) * Ensure ec2_vpc_endpoint returns True when deleting an Endpoint Return not changed when state=absent and endpoint has already been deleted * Add minimal endpoint tests This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/a89ec9048b9c5e4a5ae79503bad3cd90e073bebf --- plugins/modules/ec2_vpc_endpoint.py | 12 +- .../targets/ec2_vpc_endpoint/aliases | 3 + .../ec2_vpc_endpoint/defaults/main.yml | 8 + .../targets/ec2_vpc_endpoint/tasks/main.yml | 395 ++++++++++++++++++ 4 files changed, 416 insertions(+), 2 deletions(-) create mode 100644 tests/integration/targets/ec2_vpc_endpoint/aliases create mode 100644 tests/integration/targets/ec2_vpc_endpoint/defaults/main.yml create mode 100644 tests/integration/targets/ec2_vpc_endpoint/tasks/main.yml diff --git a/plugins/modules/ec2_vpc_endpoint.py b/plugins/modules/ec2_vpc_endpoint.py index 8e2426a525a..28d0fda0eba 100644 --- a/plugins/modules/ec2_vpc_endpoint.py +++ b/plugins/modules/ec2_vpc_endpoint.py @@ -313,8 +313,16 @@ def setup_removal(client, module): params['VpcEndpointIds'] = module.params.get('vpc_endpoint_id') try: result = client.delete_vpc_endpoints(**params)['Unsuccessful'] - if not module.check_mode and (result != []): - module.fail_json(msg=result) + if len(result) < len(params['VpcEndpointIds']): + changed = True + # For some reason delete_vpc_endpoints doesn't throw exceptions it + # returns a list of failed 'results' instead. Throw these so we can + # catch them the way we expect + for r in result: + try: + raise botocore.exceptions.ClientError(r, 'delete_vpc_endpoints') + except is_boto3_error_code('InvalidVpcEndpoint.NotFound'): + continue except is_boto3_error_code('DryRunOperation'): changed = True result = 'Would have deleted VPC Endpoint if not in check mode' diff --git a/tests/integration/targets/ec2_vpc_endpoint/aliases b/tests/integration/targets/ec2_vpc_endpoint/aliases new file mode 100644 index 00000000000..0ed26a0a740 --- /dev/null +++ b/tests/integration/targets/ec2_vpc_endpoint/aliases @@ -0,0 +1,3 @@ +cloud/aws +shippable/aws/group2 +ec2_vpc_endpoint_info diff --git a/tests/integration/targets/ec2_vpc_endpoint/defaults/main.yml b/tests/integration/targets/ec2_vpc_endpoint/defaults/main.yml new file mode 100644 index 00000000000..f0041c402e5 --- /dev/null +++ b/tests/integration/targets/ec2_vpc_endpoint/defaults/main.yml @@ -0,0 +1,8 @@ +--- +vpc_name: '{{ resource_prefix }}-vpc' +vpc_seed: '{{ resource_prefix }}' +vpc_cidr: '10.{{ 256 | random(seed=vpc_seed) }}.22.0/24' + +# S3 and EC2 should generally be available... +endpoint_service_a: 'com.amazonaws.{{ aws_region }}.s3' +endpoint_service_b: 'com.amazonaws.{{ aws_region }}.ec2' diff --git a/tests/integration/targets/ec2_vpc_endpoint/tasks/main.yml b/tests/integration/targets/ec2_vpc_endpoint/tasks/main.yml new file mode 100644 index 00000000000..d06ac92fa01 --- /dev/null +++ b/tests/integration/targets/ec2_vpc_endpoint/tasks/main.yml @@ -0,0 +1,395 @@ +--- +- name: ec2_vpc_endpoint tests + collections: + - amazon.aws + + module_defaults: + group/aws: + aws_access_key: "{{ aws_access_key }}" + aws_secret_key: "{{ aws_secret_key }}" + security_token: "{{ security_token | default(omit) }}" + region: "{{ aws_region }}" + block: + # ============================================================ + # BEGIN PRE-TEST SETUP + - name: create a VPC + ec2_vpc_net: + state: present + name: "{{ vpc_name }}" + cidr_block: "{{ vpc_cidr }}" + tags: + AnsibleTest: 'ec2_vpc_endpoint' + AnsibleRun: '{{ resource_prefix }}' + register: vpc_creation + - name: Assert success + assert: + that: + - vpc_creation is successful + + - name: Create an IGW + ec2_vpc_igw: + vpc_id: "{{ vpc_creation.vpc.id }}" + state: present + tags: + Name: "{{ resource_prefix }}" + AnsibleTest: 'ec2_vpc_endpoint' + AnsibleRun: '{{ resource_prefix }}' + register: igw_creation + - name: Assert success + assert: + that: + - igw_creation is successful + + - name: Create a minimal route table (no routes) + ec2_vpc_route_table: + vpc_id: '{{ vpc_creation.vpc.id }}' + tags: + AnsibleTest: 'ec2_vpc_endpoint' + AnsibleRun: '{{ resource_prefix }}' + Name: '{{ resource_prefix }}-empty' + subnets: [] + routes: [] + register: rtb_creation_empty + + - name: Create a minimal route table (with IGW) + ec2_vpc_route_table: + vpc_id: '{{ vpc_creation.vpc.id }}' + tags: + AnsibleTest: 'ec2_vpc_endpoint' + AnsibleRun: '{{ resource_prefix }}' + Name: '{{ resource_prefix }}-igw' + subnets: [] + routes: + - dest: 0.0.0.0/0 + gateway_id: "{{ igw_creation.gateway_id }}" + register: rtb_creation_igw + + - name: Save VPC info in a fact + set_fact: + vpc_id: '{{ vpc_creation.vpc.id }}' + rtb_empty_id: '{{ rtb_creation_empty.route_table.id }}' + rtb_igw_id: '{{ rtb_creation_igw.route_table.id }}' + + # ============================================================ + # BEGIN TESTS + + # Minimal check_mode with _info + - name: Fetch Endpoints in check_mode + ec2_vpc_endpoint_info: + query: endpoints + register: endpoint_info + check_mode: True + - name: Assert success + assert: + that: + # May be run in parallel, the only thing we can guarantee is + # - we shouldn't error + # - we should return 'vpc_endpoints' (even if it's empty) + - endpoint_info is successful + - '"vpc_endpoints" in endpoint_info' + + - name: Fetch Services in check_mode + ec2_vpc_endpoint_info: + query: services + register: endpoint_info + check_mode: True + - name: Assert success + assert: + that: + - endpoint_info is successful + - '"service_names" in endpoint_info' + # This is just 2 arbitrary AWS services that should (generally) be + # available. The actual list will vary over time and between regions + - endpoint_service_a in endpoint_info.service_names + - endpoint_service_b in endpoint_info.service_names + + # Fetch services without check mode + # Note: Filters not supported on services via this module, this is all we can test for now + - name: Fetch Services + ec2_vpc_endpoint_info: + query: services + register: endpoint_info + - name: Assert success + assert: + that: + - endpoint_info is successful + - '"service_names" in endpoint_info' + # This is just 2 arbitrary AWS services that should (generally) be + # available. The actual list will vary over time and between regions + - endpoint_service_a in endpoint_info.service_names + - endpoint_service_b in endpoint_info.service_names + + # Attempt to create an endpoint + - name: Create minimal endpoint (check mode) + ec2_vpc_endpoint: + state: present + vpc_id: '{{ vpc_id }}' + service: '{{ endpoint_service_a }}' + register: create_endpoint_check + check_mode: True + - name: Assert changed + assert: + that: + - create_endpoint_check is changed + + - name: Create minimal endpoint + ec2_vpc_endpoint: + state: present + vpc_id: '{{ vpc_id }}' + service: '{{ endpoint_service_a }}' + register: create_endpoint + - name: Check standard return values + assert: + that: + - create_endpoint is changed + - '"result" in create_endpoint' + - '"creation_timestamp" in create_endpoint.result' + - '"dns_entries" in create_endpoint.result' + - '"groups" in create_endpoint.result' + - '"network_interface_ids" in create_endpoint.result' + - '"owner_id" in create_endpoint.result' + - '"policy_document" in create_endpoint.result' + - '"private_dns_enabled" in create_endpoint.result' + - create_endpoint.result.private_dns_enabled == False + - '"requester_managed" in create_endpoint.result' + - create_endpoint.result.requester_managed == False + - '"service_name" in create_endpoint.result' + - create_endpoint.result.service_name == endpoint_service_a + - '"state" in create_endpoint.result' + - create_endpoint.result.state == "available" + - '"vpc_endpoint_id" in create_endpoint.result' + - create_endpoint.result.vpc_endpoint_id.startswith("vpce-") + - '"vpc_endpoint_type" in create_endpoint.result' + - create_endpoint.result.vpc_endpoint_type == "Gateway" + - '"vpc_id" in create_endpoint.result' + - create_endpoint.result.vpc_id == vpc_id + + - name: Save Endpoint info in a fact + set_fact: + endpoint_id: '{{ create_endpoint.result.vpc_endpoint_id }}' + + # Pull info about the endpoints + - name: Fetch Endpoints (all) + ec2_vpc_endpoint_info: + query: endpoints + register: endpoint_info + - name: Assert success + assert: + that: + # We're fetching all endpoints, there's no guarantee what the values + # will be + - endpoint_info is successful + - '"vpc_endpoints" in endpoint_info' + - '"creation_timestamp" in first_endpoint' + - '"policy_document" in first_endpoint' + - '"route_table_ids" in first_endpoint' + - '"service_name" in first_endpoint' + - '"state" in first_endpoint' + - '"vpc_endpoint_id" in first_endpoint' + - '"vpc_id" in first_endpoint' + # Not yet documented, but returned + - '"dns_entries" in first_endpoint' + - '"groups" in first_endpoint' + - '"network_interface_ids" in first_endpoint' + - '"owner_id" in first_endpoint' + - '"private_dns_enabled" in first_endpoint' + - '"requester_managed" in first_endpoint' + - '"subnet_ids" in first_endpoint' + - '"tags" in first_endpoint' + - '"vpc_endpoint_type" in first_endpoint' + # Make sure our endpoint is included + - endpoint_id in ( endpoint_info | community.general.json_query("vpc_endpoints[*].vpc_endpoint_id") | list | flatten ) + vars: + first_endpoint: '{{ endpoint_info.vpc_endpoints[0] }}' + + - name: Fetch Endpoints (targetted by ID) + ec2_vpc_endpoint_info: + query: endpoints + vpc_endpoint_ids: '{{ endpoint_id }}' + register: endpoint_info + - name: Assert success + assert: + that: + - endpoint_info is successful + - '"vpc_endpoints" in endpoint_info' + - '"creation_timestamp" in first_endpoint' + - '"policy_document" in first_endpoint' + - '"route_table_ids" in first_endpoint' + - '"service_name" in first_endpoint' + - first_endpoint.service_name == endpoint_service_a + - '"state" in first_endpoint' + - first_endpoint.state == "available" + - '"vpc_endpoint_id" in first_endpoint' + - first_endpoint.vpc_endpoint_id == endpoint_id + - '"vpc_id" in first_endpoint' + - first_endpoint.vpc_id == vpc_id + # Not yet documented, but returned + - '"dns_entries" in first_endpoint' + - '"groups" in first_endpoint' + - '"network_interface_ids" in first_endpoint' + - '"owner_id" in first_endpoint' + - '"private_dns_enabled" in first_endpoint' + - first_endpoint.private_dns_enabled == False + - '"requester_managed" in first_endpoint' + - first_endpoint.requester_managed == False + - '"subnet_ids" in first_endpoint' + - '"tags" in first_endpoint' + - '"vpc_endpoint_type" in first_endpoint' + vars: + first_endpoint: '{{ endpoint_info.vpc_endpoints[0] }}' + + - name: Fetch Endpoints (targetted by VPC) + ec2_vpc_endpoint_info: + query: endpoints + filters: + vpc-id: + - '{{ vpc_id }}' + register: endpoint_info + - name: Assert success + assert: + that: + - endpoint_info is successful + - '"vpc_endpoints" in endpoint_info' + - '"creation_timestamp" in first_endpoint' + - '"policy_document" in first_endpoint' + - '"route_table_ids" in first_endpoint' + - '"service_name" in first_endpoint' + - first_endpoint.service_name == endpoint_service_a + - '"state" in first_endpoint' + - first_endpoint.state == "available" + - '"vpc_endpoint_id" in first_endpoint' + - first_endpoint.vpc_endpoint_id == endpoint_id + - '"vpc_id" in first_endpoint' + - first_endpoint.vpc_id == vpc_id + # Not yet documented, but returned + - '"dns_entries" in first_endpoint' + - '"groups" in first_endpoint' + - '"network_interface_ids" in first_endpoint' + - '"owner_id" in first_endpoint' + - '"private_dns_enabled" in first_endpoint' + - first_endpoint.private_dns_enabled == False + - '"requester_managed" in first_endpoint' + - first_endpoint.requester_managed == False + - '"subnet_ids" in first_endpoint' + - '"tags" in first_endpoint' + - '"vpc_endpoint_type" in first_endpoint' + vars: + first_endpoint: '{{ endpoint_info.vpc_endpoints[0] }}' + +# ec2_vpc_endpoint is not idempotent without explicitly passing the endpoint ID +# - name: Create minimal endpoint - idempotency (check mode) +# ec2_vpc_endpoint: +# state: present +# vpc_id: '{{ vpc_id }}' +# service: '{{ endpoint_service_a }}' +# register: create_endpoint_idem_check +# check_mode: True +# +# - name: Create minimal endpoint - idempotency +# ec2_vpc_endpoint: +# state: present +# vpc_id: '{{ vpc_id }}' +# service: '{{ endpoint_service_a }}' +# register: create_endpoint_idem + + # Deletion + # Delete the routes first - you can't delete an endpoint with a route + # attached. + - name: Delete minimal route table (no routes) + ec2_vpc_route_table: + state: absent + lookup: id + route_table_id: "{{ rtb_empty_id }}" + register: rtb_delete + - assert: + that: + - rtb_delete is changed + + - name: Delete minimal route table (IGW route) + ec2_vpc_route_table: + state: absent + lookup: id + route_table_id: "{{ rtb_igw_id }}" + - assert: + that: + - rtb_delete is changed + + - name: Delete endpoint by ID (check_mode) + ec2_vpc_endpoint: + state: absent + vpc_endpoint_id: "{{ endpoint_id }}" + check_mode: true + register: endpoint_delete_check + - assert: + that: + - endpoint_delete_check is changed + + - name: Delete endpoint by ID + ec2_vpc_endpoint: + state: absent + vpc_endpoint_id: "{{ endpoint_id }}" + register: endpoint_delete_check + - assert: + that: + - endpoint_delete_check is changed + +# XXX Bug: uses AWS's check mode which only checks permissions +# - name: Delete endpoint by ID - idempotency (check_mode) +# ec2_vpc_endpoint: +# state: absent +# vpc_endpoint_id: "{{ endpoint_id }}" +# check_mode: true +# register: endpoint_delete_check +# - assert: +# that: +# - endpoint_delete_check is not changed + + - name: Delete endpoint by ID - idempotency + ec2_vpc_endpoint: + state: absent + vpc_endpoint_id: "{{ endpoint_id }}" + register: endpoint_delete_check + - assert: + that: + - endpoint_delete_check is not changed + + + # ============================================================ + # BEGIN POST-TEST CLEANUP + always: + - name: Delete minimal route table (no routes) + ec2_vpc_route_table: + state: absent + lookup: id + route_table_id: "{{ rtb_creation_empty.route_table.id }}" + ignore_errors: True + + - name: Delete minimal route table (IGW route) + ec2_vpc_route_table: + state: absent + lookup: id + route_table_id: "{{ rtb_creation_igw.route_table.id }}" + ignore_errors: True + + - name: Delete endpoint + ec2_vpc_endpoint: + state: absent + vpc_endpoint_id: "{{ create_endpoint.result.vpc_endpoint_id }}" + ignore_errors: True + + - name: Remove IGW + ec2_vpc_igw: + state: absent + vpc_id: "{{ vpc_creation.vpc.id }}" + register: igw_deletion + retries: 10 + delay: 5 + until: igw_deletion is success + ignore_errors: yes + + - name: Remove VPC + ec2_vpc_net: + state: absent + name: "{{ vpc_name }}" + cidr_block: "{{ vpc_cidr }}" + ignore_errors: true From d698c8cb254f6d9141473361f7af325e4660357f Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Sun, 21 Feb 2021 15:40:04 +0100 Subject: [PATCH 19/37] Yet more integration test aliases file cleanup (#431) * More aliases cleanup * Mark ec2_classic_lb tests unstable * Add more comments about why tests aren't enabled This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/cb55efa7a4fda574b637f3b18c072cd2436e2a21 --- tests/integration/targets/ec2_vpc_endpoint/aliases | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/integration/targets/ec2_vpc_endpoint/aliases b/tests/integration/targets/ec2_vpc_endpoint/aliases index 0ed26a0a740..68d272f2799 100644 --- a/tests/integration/targets/ec2_vpc_endpoint/aliases +++ b/tests/integration/targets/ec2_vpc_endpoint/aliases @@ -1,3 +1,4 @@ cloud/aws shippable/aws/group2 + ec2_vpc_endpoint_info From a28c1136f6f0ceda01bc349e612511ac0709f7b7 Mon Sep 17 00:00:00 2001 From: Damien Levac Date: Sun, 7 Mar 2021 10:22:58 -0500 Subject: [PATCH 20/37] Added support for 'vpc_endpoint_type'. (#460) * Added support for 'vpc_endpoint_type'. * Integration test for the 'vpc_endpoint_type' feature. * Added choices in documentation. * Added changelog. This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/4da568ad75b521272918295057ffeef4b2ea94a0 --- plugins/modules/ec2_vpc_endpoint.py | 11 +++++++++- .../targets/ec2_vpc_endpoint/tasks/main.yml | 20 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/plugins/modules/ec2_vpc_endpoint.py b/plugins/modules/ec2_vpc_endpoint.py index 28d0fda0eba..d7d10769f06 100644 --- a/plugins/modules/ec2_vpc_endpoint.py +++ b/plugins/modules/ec2_vpc_endpoint.py @@ -21,6 +21,13 @@ - Required when creating a VPC endpoint. required: false type: str + vpc_endpoint_type: + description: + - The type of endpoint. + required: false + default: Gateway + choices: [ "Interface", "Gateway", "GatewayLoadBalancer" ] + type: str service: description: - An AWS supported vpc endpoint service. Use the M(community.aws.ec2_vpc_endpoint_info) @@ -56,7 +63,7 @@ - absent to remove resource required: false default: present - choices: [ "present", "absent"] + choices: [ "present", "absent" ] type: str wait: description: @@ -251,6 +258,7 @@ def create_vpc_endpoint(client, module): changed = False token_provided = False params['VpcId'] = module.params.get('vpc_id') + params['VpcEndpointType'] = module.params.get('vpc_endpoint_type') params['ServiceName'] = module.params.get('service') params['DryRun'] = module.check_mode @@ -334,6 +342,7 @@ def setup_removal(client, module): def main(): argument_spec = dict( vpc_id=dict(), + vpc_endpoint_type=dict(default='Gateway', choices=['Interface', 'Gateway', 'GatewayLoadBalancer']), service=dict(), policy=dict(type='json'), policy_file=dict(type='path', aliases=['policy_path']), diff --git a/tests/integration/targets/ec2_vpc_endpoint/tasks/main.yml b/tests/integration/targets/ec2_vpc_endpoint/tasks/main.yml index d06ac92fa01..a8fdbec889d 100644 --- a/tests/integration/targets/ec2_vpc_endpoint/tasks/main.yml +++ b/tests/integration/targets/ec2_vpc_endpoint/tasks/main.yml @@ -353,6 +353,26 @@ that: - endpoint_delete_check is not changed + - name: Create interface endpoint + ec2_vpc_endpoint: + state: present + vpc_id: '{{ vpc_id }}' + service: '{{ endpoint_service_a }}' + vpc_endpoint_type: Interface + register: create_interface_endpoint + - name: Check that the interface endpoint was created properly + assert: + that: + - create_interface_endpoint is changed + - create_interface_endpoint.result.vpc_endpoint_type == "Interface" + - name: Delete interface endpoint + ec2_vpc_endpoint: + state: absent + vpc_endpoint_id: "{{ create_interface_endpoint.result.vpc_endpoint_id }}" + register: interface_endpoint_delete_check + - assert: + that: + - interface_endpoint_delete_check is changed # ============================================================ # BEGIN POST-TEST CLEANUP From d6dcb48a85d4b53209f02aeab074f48915a823ca Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Mon, 8 Mar 2021 09:14:27 +0100 Subject: [PATCH 21/37] Fix version_added and changelog from #460 (#465) This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/4f8c366df6552357717933f6ac2652f32552be6e --- plugins/modules/ec2_vpc_endpoint.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/modules/ec2_vpc_endpoint.py b/plugins/modules/ec2_vpc_endpoint.py index d7d10769f06..d15da3b2a79 100644 --- a/plugins/modules/ec2_vpc_endpoint.py +++ b/plugins/modules/ec2_vpc_endpoint.py @@ -28,6 +28,7 @@ default: Gateway choices: [ "Interface", "Gateway", "GatewayLoadBalancer" ] type: str + version_added: 1.5.0 service: description: - An AWS supported vpc endpoint service. Use the M(community.aws.ec2_vpc_endpoint_info) From f5ec6d2319e95263a37dca8a1565e554311bfcbf Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Sat, 13 Mar 2021 20:10:09 +0100 Subject: [PATCH 22/37] More no_log=False to fix sanity tests (#474) * Add no_log=False to mark some more false-positives of the no_log check. * More false-positives confirmed by tremble. This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/67b6d751cc4ee5728577af2fe7b330f8cc7cd5c2 --- plugins/modules/ec2_vpc_endpoint.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/ec2_vpc_endpoint.py b/plugins/modules/ec2_vpc_endpoint.py index d15da3b2a79..2bfe89008e5 100644 --- a/plugins/modules/ec2_vpc_endpoint.py +++ b/plugins/modules/ec2_vpc_endpoint.py @@ -352,7 +352,7 @@ def main(): wait_timeout=dict(type='int', default=320, required=False), route_table_ids=dict(type='list', elements='str'), vpc_endpoint_id=dict(), - client_token=dict(), + client_token=dict(no_log=False), ) module = AnsibleAWSModule( argument_spec=argument_spec, From 2dade299249e0a27d7731632b8088fde671cbb1a Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Fri, 19 Mar 2021 22:29:49 +0100 Subject: [PATCH 23/37] New module - ec2_vpc_endpoint_service_info (#346) * New module - ec2_vpc_endpoint_service_info * Deprecate querying services through ec2_vpc_endpoint_info * Attempt to cope with some services which have who possible endpoints Co-authored-by: Jill R <4121322+jillr@users.noreply.github.com> This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/b48c1ee4ab7af567335804ed24cbc87f9ea18745 --- plugins/modules/ec2_vpc_endpoint_info.py | 36 +++- .../modules/ec2_vpc_endpoint_service_info.py | 180 ++++++++++++++++++ .../ec2_vpc_endpoint_service_info/aliases | 3 + .../defaults/main.yml | 3 + .../meta/main.yml | 2 + .../tasks/main.yml | 139 ++++++++++++++ 6 files changed, 356 insertions(+), 7 deletions(-) create mode 100644 plugins/modules/ec2_vpc_endpoint_service_info.py create mode 100644 tests/integration/targets/ec2_vpc_endpoint_service_info/aliases create mode 100644 tests/integration/targets/ec2_vpc_endpoint_service_info/defaults/main.yml create mode 100644 tests/integration/targets/ec2_vpc_endpoint_service_info/meta/main.yml create mode 100644 tests/integration/targets/ec2_vpc_endpoint_service_info/tasks/main.yml diff --git a/plugins/modules/ec2_vpc_endpoint_info.py b/plugins/modules/ec2_vpc_endpoint_info.py index 7e259c6ca8e..7706a00c915 100644 --- a/plugins/modules/ec2_vpc_endpoint_info.py +++ b/plugins/modules/ec2_vpc_endpoint_info.py @@ -10,22 +10,26 @@ short_description: Retrieves AWS VPC endpoints details using AWS methods. version_added: 1.0.0 description: - - Gets various details related to AWS VPC Endpoints. + - Gets various details related to AWS VPC endpoints. - This module was called C(ec2_vpc_endpoint_facts) before Ansible 2.9. The usage did not change. requirements: [ boto3 ] options: query: description: - - Specifies the query action to take. Services returns the supported - AWS services that can be specified when creating an endpoint. - required: True + - Defaults to C(endpoints). + - Specifies the query action to take. + - I(query=endpoints) returns information about AWS VPC endpoints. + - Retrieving information about services using I(query=services) has been + deprecated in favour of the M(ec2_vpc_endpoint_service_info) module. + - The I(query) option has been deprecated and will be removed after 2022-12-01. + required: False choices: - services - endpoints type: str vpc_endpoint_ids: description: - - Get details of specific endpoint IDs + - The IDs of specific endpoints to retrieve the details of. type: list elements: str filters: @@ -161,7 +165,7 @@ def get_endpoints(client, module): def main(): argument_spec = dict( - query=dict(choices=['services', 'endpoints'], required=True), + query=dict(choices=['services', 'endpoints'], required=False), filters=dict(default={}, type='dict'), vpc_endpoint_ids=dict(type='list', elements='str'), ) @@ -176,11 +180,29 @@ def main(): except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: module.fail_json_aws(e, msg='Failed to connect to AWS') + query = module.params.get('query') + if query == 'endpoints': + module.deprecate('The query option has been deprecated and' + ' will be removed after 2022-12-01. Searching for' + ' `endpoints` is now the default and after' + ' 2022-12-01 this module will only support fetching' + ' endpoints.', + date='2022-12-01', collection_name='community.aws') + elif query == 'services': + module.deprecate('Support for fetching service information with this ' + 'module has been deprecated and will be removed after' + ' 2022-12-01. ' + 'Please use the ec2_vpc_endpoint_service_info module ' + 'instead.', date='2022-12-01', + collection_name='community.aws') + else: + query = 'endpoints' + invocations = { 'services': get_supported_services, 'endpoints': get_endpoints, } - results = invocations[module.params.get('query')](connection, module) + results = invocations[query](connection, module) module.exit_json(**results) diff --git a/plugins/modules/ec2_vpc_endpoint_service_info.py b/plugins/modules/ec2_vpc_endpoint_service_info.py new file mode 100644 index 00000000000..2afd0e5e906 --- /dev/null +++ b/plugins/modules/ec2_vpc_endpoint_service_info.py @@ -0,0 +1,180 @@ +#!/usr/bin/python +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + + +DOCUMENTATION = r''' +module: ec2_vpc_endpoint_service_info +short_description: retrieves AWS VPC endpoint service details +version_added: 1.5.0 +description: + - Gets details related to AWS VPC Endpoint Services. +requirements: [ boto3 ] +options: + filters: + description: + - A dict of filters to apply. + - Each dict item consists of a filter key and a filter value. + See U(https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeVpcEndpointServices.html) + for possible filters. + type: dict + service_names: + description: + - A list of service names which can be used to narrow the search results. + type: list + elements: str +author: + - Mark Chappell (@tremble) +extends_documentation_fragment: + - amazon.aws.aws + - amazon.aws.ec2 + +''' + +EXAMPLES = r''' +# Simple example of listing all supported AWS services for VPC endpoints +- name: List supported AWS endpoint services + community.aws.ec2_vpc_endpoint_service_info: + region: ap-southeast-2 + register: supported_endpoint_services +''' + +RETURN = r''' +service_names: + description: List of supported AWS VPC endpoint service names. + returned: success + type: list + sample: + service_names: + - com.amazonaws.ap-southeast-2.s3 +service_details: + description: Detailed information about the AWS VPC endpoint services. + returned: success + type: complex + contains: + service_name: + returned: success + description: The ARN of the endpoint service. + type: str + service_id: + returned: success + description: The ID of the endpoint service. + type: str + service_type: + returned: success + description: The type of the service + type: list + availability_zones: + returned: success + description: The Availability Zones in which the service is available. + type: list + owner: + returned: success + description: The AWS account ID of the service owner. + type: str + base_endpoint_dns_names: + returned: success + description: The DNS names for the service. + type: list + private_dns_name: + returned: success + description: The private DNS name for the service. + type: str + private_dns_names: + returned: success + description: The private DNS names assigned to the VPC endpoint service. + type: list + vpc_endpoint_policy_supported: + returned: success + description: Whether the service supports endpoint policies. + type: bool + acceptance_required: + returned: success + description: + Whether VPC endpoint connection requests to the service must be + accepted by the service owner. + type: bool + manages_vpc_endpoints: + returned: success + description: Whether the service manages its VPC endpoints. + type: bool + tags: + returned: success + description: A dict of tags associated with the service + type: dict + private_dns_name_verification_state: + returned: success + description: + - The verification state of the VPC endpoint service. + - Consumers of an endpoint service cannot use the private name when the state is not C(verified). + type: str +''' + +try: + import botocore +except ImportError: + pass # Handled by AnsibleAWSModule + +from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict + +from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ansible_dict_to_boto3_filter_list +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import boto3_tag_list_to_ansible_dict +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry + + +# We're using a paginator so we can't use the client decorators +@AWSRetry.jittered_backoff() +def get_services(client, module): + paginator = client.get_paginator('describe_vpc_endpoint_services') + params = {} + if module.params.get("filters"): + params['Filters'] = ansible_dict_to_boto3_filter_list(module.params.get("filters")) + + if module.params.get("service_names"): + params['ServiceNames'] = module.params.get("service_names") + + results = paginator.paginate(**params).build_full_result() + return results + + +def normalize_service(service): + normalized = camel_dict_to_snake_dict(service, ignore_list=['Tags']) + normalized["tags"] = boto3_tag_list_to_ansible_dict(service.get('Tags')) + return normalized + + +def normalize_result(result): + normalized = {} + normalized['service_details'] = [normalize_service(service) for service in result.get('ServiceDetails')] + normalized['service_names'] = result.get('ServiceNames', []) + return normalized + + +def main(): + argument_spec = dict( + filters=dict(default={}, type='dict'), + service_names=dict(type='list', elements='str'), + ) + + module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=True) + + # Validate Requirements + try: + client = module.client('ec2') + except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: + module.fail_json_aws(e, msg='Failed to connect to AWS') + + try: + results = get_services(client, module) + except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: + module.fail_json_aws(e, msg='Failed to connect to retrieve service details') + normalized_result = normalize_result(results) + + module.exit_json(changed=False, **normalized_result) + + +if __name__ == '__main__': + main() diff --git a/tests/integration/targets/ec2_vpc_endpoint_service_info/aliases b/tests/integration/targets/ec2_vpc_endpoint_service_info/aliases new file mode 100644 index 00000000000..bf2988bbc2e --- /dev/null +++ b/tests/integration/targets/ec2_vpc_endpoint_service_info/aliases @@ -0,0 +1,3 @@ +cloud/aws +shippable/aws/group2 +ec2_vpc_endpoint_service_info diff --git a/tests/integration/targets/ec2_vpc_endpoint_service_info/defaults/main.yml b/tests/integration/targets/ec2_vpc_endpoint_service_info/defaults/main.yml new file mode 100644 index 00000000000..445cc7f3c52 --- /dev/null +++ b/tests/integration/targets/ec2_vpc_endpoint_service_info/defaults/main.yml @@ -0,0 +1,3 @@ +search_service_names: +- 'com.amazonaws.{{ aws_region }}.s3' +- 'com.amazonaws.{{ aws_region }}.ec2' diff --git a/tests/integration/targets/ec2_vpc_endpoint_service_info/meta/main.yml b/tests/integration/targets/ec2_vpc_endpoint_service_info/meta/main.yml new file mode 100644 index 00000000000..1810d4bec98 --- /dev/null +++ b/tests/integration/targets/ec2_vpc_endpoint_service_info/meta/main.yml @@ -0,0 +1,2 @@ +dependencies: + - setup_remote_tmp_dir diff --git a/tests/integration/targets/ec2_vpc_endpoint_service_info/tasks/main.yml b/tests/integration/targets/ec2_vpc_endpoint_service_info/tasks/main.yml new file mode 100644 index 00000000000..40eb0a88924 --- /dev/null +++ b/tests/integration/targets/ec2_vpc_endpoint_service_info/tasks/main.yml @@ -0,0 +1,139 @@ +--- +- module_defaults: + group/aws: + aws_access_key: '{{ aws_access_key }}' + aws_secret_key: '{{ aws_secret_key }}' + security_token: '{{ security_token | default(omit) }}' + region: '{{ aws_region }}' + # Needed until added to the group in Ansible 2.9 + ec2_vpc_endpoint_service_info: + aws_access_key: '{{ aws_access_key }}' + aws_secret_key: '{{ aws_secret_key }}' + security_token: '{{ security_token | default(omit) }}' + region: '{{ aws_region }}' + + block: + + - name: 'List all available services (Check Mode)' + ec2_vpc_endpoint_service_info: + check_mode: True + register: services_check + + - name: 'Verify services (Check Mode)' + vars: + first_service: '{{ services_check.service_details[0] }}' + assert: + that: + - services_check is successful + - services_check is not changed + - '"service_names" in services_check' + - '"service_details" in services_check' + - '"acceptance_required" in first_service' + - '"availability_zones" in first_service' + - '"base_endpoint_dns_names" in first_service' + - '"manages_vpc_endpoints" in first_service' + - '"owner" in first_service' + - '"private_dns_name" in first_service' + - '"private_dns_name_verification_state" in first_service' + - '"service_id" in first_service' + - '"service_name" in first_service' + - '"service_type" in first_service' + - '"tags" in first_service' + - '"vpc_endpoint_policy_supported" in first_service' + + - name: 'List all available services' + ec2_vpc_endpoint_service_info: + register: services_info + + - name: 'Verify services' + vars: + first_service: '{{ services_info.service_details[0] }}' + assert: + that: + - services_info is successful + - services_info is not changed + - '"service_names" in services_info' + - '"service_details" in services_info' + - '"acceptance_required" in first_service' + - '"availability_zones" in first_service' + - '"base_endpoint_dns_names" in first_service' + - '"manages_vpc_endpoints" in first_service' + - '"owner" in first_service' + - '"private_dns_name" in first_service' + - '"private_dns_name_verification_state" in first_service' + - '"service_id" in first_service' + - '"service_name" in first_service' + - '"service_type" in first_service' + - '"tags" in first_service' + - '"vpc_endpoint_policy_supported" in first_service' + + - name: 'Limit services by name' + ec2_vpc_endpoint_service_info: + service_names: '{{ search_service_names }}' + register: services_info + + - name: 'Verify services' + vars: + first_service: '{{ services_info.service_details[0] }}' + # The same service sometimes pop up twice. s3 for example has + # s3.us-east-1.amazonaws.com and s3.us-east-1.vpce.amazonaws.com which are + # part of com.amazonaws.us-east-1.s3 so we need to run the results through + # the unique filter to know if we've got what we think we have + unique_names: '{{ services_info.service_names | unique | list }}' + unique_detail_names: '{{ services_info.service_details | map(attribute="service_name") | unique | list }}' + assert: + that: + - services_info is successful + - services_info is not changed + - '"service_names" in services_info' + - (unique_names | length) == (search_service_names | length) + - (unique_detail_names | length ) == (search_service_names | length) + - (unique_names | difference(search_service_names) | length) == 0 + - (unique_detail_names | difference(search_service_names) | length) == 0 + - '"service_details" in services_info' + - '"acceptance_required" in first_service' + - '"availability_zones" in first_service' + - '"base_endpoint_dns_names" in first_service' + - '"manages_vpc_endpoints" in first_service' + - '"owner" in first_service' + - '"private_dns_name" in first_service' + - '"private_dns_name_verification_state" in first_service' + - '"service_id" in first_service' + - '"service_name" in first_service' + - '"service_type" in first_service' + - '"tags" in first_service' + - '"vpc_endpoint_policy_supported" in first_service' + + - name: 'Grab single service details to test filters' + set_fact: + example_service: '{{ services_info.service_details[0] }}' + + - name: 'Limit services by filter' + ec2_vpc_endpoint_service_info: + filters: + service-name: '{{ example_service.service_name }}' + register: filtered_service + + - name: 'Verify services' + vars: + first_service: '{{ filtered_service.service_details[0] }}' + assert: + that: + - filtered_service is successful + - filtered_service is not changed + - '"service_names" in filtered_service' + - filtered_service.service_names | length == 1 + - '"service_details" in filtered_service' + - filtered_service.service_details | length == 1 + - '"acceptance_required" in first_service' + - '"availability_zones" in first_service' + - '"base_endpoint_dns_names" in first_service' + - '"manages_vpc_endpoints" in first_service' + - '"owner" in first_service' + - '"private_dns_name" in first_service' + - '"private_dns_name_verification_state" in first_service' + - '"service_id" in first_service' + - '"service_name" in first_service' + - '"service_type" in first_service' + - '"tags" in first_service' + - '"vpc_endpoint_policy_supported" in first_service' From f1128d08739c5f1bcda84fc0cf179c1d9d689a00 Mon Sep 17 00:00:00 2001 From: Jill R <4121322+jillr@users.noreply.github.com> Date: Wed, 24 Mar 2021 13:35:52 -0700 Subject: [PATCH 24/37] Stabilize and improve ec2_vpc_endpoint modules (#473) * Stabilize and improve ec2_vpc_endpoint modules - Add tagging support - Make idempotent - Better exception handling - Better check_mode support - Use module_utils for common functions - Enable retries on common AWS failures * Make endpoint deletion idempotent in check_mode * Sanity fixes * Address review feedback This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/f1d338d8412ac3aedbab9956ed82a4d28cf34ea4 --- plugins/modules/ec2_vpc_endpoint.py | 190 ++++++-- plugins/modules/ec2_vpc_endpoint_info.py | 22 +- .../targets/ec2_vpc_endpoint/tasks/main.yml | 450 +++++++++++++++++- 3 files changed, 574 insertions(+), 88 deletions(-) diff --git a/plugins/modules/ec2_vpc_endpoint.py b/plugins/modules/ec2_vpc_endpoint.py index 2bfe89008e5..2aa4441fac7 100644 --- a/plugins/modules/ec2_vpc_endpoint.py +++ b/plugins/modules/ec2_vpc_endpoint.py @@ -66,6 +66,19 @@ default: present choices: [ "present", "absent" ] type: str + tags: + description: + - A dict of tags to apply to the internet gateway. + - To remove all tags set I(tags={}) and I(purge_tags=true). + type: dict + version_added: 1.5.0 + purge_tags: + description: + - Delete any tags not specified in the task that are on the instance. + This means you have to specify all the desired tags on each task affecting an instance. + default: false + type: bool + version_added: 1.5.0 wait: description: - When specified, will wait for either available status for state present. @@ -200,58 +213,112 @@ from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule +from ansible_collections.amazon.aws.plugins.module_utils.core import normalize_boto3_result +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ansible_dict_to_boto3_filter_list +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ansible_dict_to_boto3_tag_list +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import boto3_tag_list_to_ansible_dict +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import compare_aws_tags + from ansible_collections.amazon.aws.plugins.module_utils.core import is_boto3_error_code +from ansible_collections.amazon.aws.plugins.module_utils.waiters import get_waiter -def date_handler(obj): - return obj.isoformat() if hasattr(obj, 'isoformat') else obj +def get_endpoints(client, module, endpoint_id=None): + params = dict() + if endpoint_id: + params['VpcEndpointIds'] = [endpoint_id] + else: + filters = list() + if module.params.get('service'): + filters.append({'Name': 'service-name', 'Values': [module.params.get('service')]}) + if module.params.get('vpc_id'): + filters.append({'Name': 'vpc-id', 'Values': [module.params.get('vpc_id')]}) + params['Filters'] = filters + try: + result = client.describe_vpc_endpoints(aws_retry=True, **params) + except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e: + module.fail_json_aws(e, msg="Failed to get endpoints") + # normalize iso datetime fields in result + normalized_result = normalize_boto3_result(result) + return normalized_result -def wait_for_status(client, module, resource_id, status): - polling_increment_secs = 15 - max_retries = (module.params.get('wait_timeout') // polling_increment_secs) - status_achieved = False - for x in range(0, max_retries): - try: - resource = get_endpoints(client, module, resource_id)['VpcEndpoints'][0] - if resource['State'] == status: - status_achieved = True - break - else: - time.sleep(polling_increment_secs) - except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: - module.fail_json_aws(e, msg='Failure while waiting for status') +def match_endpoints(route_table_ids, service_name, vpc_id, endpoint): + found = False + sorted_route_table_ids = [] - return status_achieved, resource + if route_table_ids: + sorted_route_table_ids = sorted(route_table_ids) + if endpoint['VpcId'] == vpc_id and endpoint['ServiceName'] == service_name: + sorted_endpoint_rt_ids = sorted(endpoint['RouteTableIds']) + if sorted_endpoint_rt_ids == sorted_route_table_ids: -def get_endpoints(client, module, resource_id=None): - params = dict() - if resource_id: - params['VpcEndpointIds'] = [resource_id] + found = True + return found - result = json.loads(json.dumps(client.describe_vpc_endpoints(**params), default=date_handler)) - return result + +def ensure_tags(client, module, vpc_endpoint_id): + changed = False + tags = module.params['tags'] + purge_tags = module.params['purge_tags'] + + filters = ansible_dict_to_boto3_filter_list({'resource-id': vpc_endpoint_id}) + try: + current_tags = client.describe_tags(aws_retry=True, Filters=filters) + except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e: + module.fail_json_aws(e, msg="Failed to describe tags for VPC Endpoint: {0}".format(vpc_endpoint_id)) + + tags_to_set, tags_to_unset = compare_aws_tags(boto3_tag_list_to_ansible_dict(current_tags.get('Tags')), tags, purge_tags=purge_tags) + if purge_tags and not tags: + tags_to_unset = current_tags + + if tags_to_unset: + changed = True + if not module.check_mode: + try: + client.delete_tags(aws_retry=True, Resources=[vpc_endpoint_id], Tags=[dict(Key=tagkey) for tagkey in tags_to_unset]) + except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e: + module.fail_json_aws(e, msg="Unable to delete tags {0}".format(tags_to_unset)) + + if tags_to_set: + changed = True + if not module.check_mode: + try: + client.create_tags(aws_retry=True, Resources=[vpc_endpoint_id], Tags=ansible_dict_to_boto3_tag_list(tags_to_set)) + except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e: + module.fail_json_aws(e, msg="Unable to add tags {0}".format(tags_to_set)) + return changed def setup_creation(client, module): - vpc_id = module.params.get('vpc_id') + endpoint_id = module.params.get('vpc_endpoint_id') + route_table_ids = module.params.get('route_table_ids') service_name = module.params.get('service') + vpc_id = module.params.get('vpc_id') + changed = False - if module.params.get('route_table_ids'): - route_table_ids = module.params.get('route_table_ids') - existing_endpoints = get_endpoints(client, module) - for endpoint in existing_endpoints['VpcEndpoints']: - if endpoint['VpcId'] == vpc_id and endpoint['ServiceName'] == service_name: - sorted_endpoint_rt_ids = sorted(endpoint['RouteTableIds']) - sorted_route_table_ids = sorted(route_table_ids) - if sorted_endpoint_rt_ids == sorted_route_table_ids: - return False, camel_dict_to_snake_dict(endpoint) + if not endpoint_id: + # Try to use the module parameters to match any existing endpoints + all_endpoints = get_endpoints(client, module, endpoint_id) + if len(all_endpoints['VpcEndpoints']) > 0: + for endpoint in all_endpoints['VpcEndpoints']: + if match_endpoints(route_table_ids, service_name, vpc_id, endpoint): + endpoint_id = endpoint['VpcEndpointId'] + break + + if endpoint_id: + # If we have an endpoint now, just ensure tags and exit + if module.params.get('tags'): + changed = ensure_tags(client, module, endpoint_id) + normalized_result = get_endpoints(client, module, endpoint_id=endpoint_id)['VpcEndpoints'][0] + return changed, camel_dict_to_snake_dict(normalized_result, ignore_list=['Tags']) changed, result = create_vpc_endpoint(client, module) - return changed, json.loads(json.dumps(result, default=date_handler)) + return changed, camel_dict_to_snake_dict(result, ignore_list=['Tags']) def create_vpc_endpoint(client, module): @@ -261,7 +328,11 @@ def create_vpc_endpoint(client, module): params['VpcId'] = module.params.get('vpc_id') params['VpcEndpointType'] = module.params.get('vpc_endpoint_type') params['ServiceName'] = module.params.get('service') - params['DryRun'] = module.check_mode + + if module.check_mode: + changed = True + result = 'Would have created VPC Endpoint if not in check mode' + module.exit_json(changed=changed, result=result) if module.params.get('route_table_ids'): params['RouteTableIds'] = module.params.get('route_table_ids') @@ -292,16 +363,18 @@ def create_vpc_endpoint(client, module): try: changed = True - result = camel_dict_to_snake_dict(client.create_vpc_endpoint(**params)['VpcEndpoint']) + result = client.create_vpc_endpoint(aws_retry=True, **params)['VpcEndpoint'] if token_provided and (request_time > result['creation_timestamp'].replace(tzinfo=None)): changed = False elif module.params.get('wait') and not module.check_mode: - status_achieved, result = wait_for_status(client, module, result['vpc_endpoint_id'], 'available') - if not status_achieved: - module.fail_json(msg='Error waiting for vpc endpoint to become available - please check the AWS console') - except is_boto3_error_code('DryRunOperation'): - changed = True - result = 'Would have created VPC Endpoint if not in check mode' + try: + waiter = get_waiter(client, 'vpc_endpoint_exists') + waiter.wait(VpcEndpointIds=[result['VpcEndpointId']], WaiterConfig=dict(Delay=15, MaxAttempts=module.params.get('wait_timeout') // 15)) + except botocore.exceptions.WaiterError as e: + module.fail_json_aws(msg='Error waiting for vpc endpoint to become available - please check the AWS console') + except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: # pylint: disable=duplicate-except + module.fail_json_aws(e, msg='Failure while waiting for status') + except is_boto3_error_code('IdempotentParameterMismatch'): # pylint: disable=duplicate-except module.fail_json(msg="IdempotentParameterMismatch - updates of endpoints are not allowed by the API") except is_boto3_error_code('RouteAlreadyExists'): # pylint: disable=duplicate-except @@ -309,19 +382,38 @@ def create_vpc_endpoint(client, module): except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: # pylint: disable=duplicate-except module.fail_json_aws(e, msg="Failed to create VPC.") - return changed, result + if module.params.get('tags'): + ensure_tags(client, module, result['VpcEndpointId']) + + # describe and normalize iso datetime fields in result after adding tags + normalized_result = get_endpoints(client, module, endpoint_id=result['VpcEndpointId'])['VpcEndpoints'][0] + return changed, normalized_result def setup_removal(client, module): params = dict() changed = False - params['DryRun'] = module.check_mode + + if module.check_mode: + try: + exists = client.describe_vpc_endpoints(aws_retry=True, VpcEndpointIds=[module.params.get('vpc_endpoint_id')]) + if exists: + result = {'msg': 'Would have deleted VPC Endpoint if not in check mode'} + changed = True + except is_boto3_error_code('InvalidVpcEndpointId.NotFound'): + result = {'msg': 'Endpoint does not exist, nothing to delete.'} + changed = False + except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e: # pylint: disable=duplicate-except + module.fail_json_aws(e, msg="Failed to get endpoints") + + return changed, result + if isinstance(module.params.get('vpc_endpoint_id'), string_types): params['VpcEndpointIds'] = [module.params.get('vpc_endpoint_id')] else: params['VpcEndpointIds'] = module.params.get('vpc_endpoint_id') try: - result = client.delete_vpc_endpoints(**params)['Unsuccessful'] + result = client.delete_vpc_endpoints(aws_retry=True, **params)['Unsuccessful'] if len(result) < len(params['VpcEndpointIds']): changed = True # For some reason delete_vpc_endpoints doesn't throw exceptions it @@ -332,9 +424,7 @@ def setup_removal(client, module): raise botocore.exceptions.ClientError(r, 'delete_vpc_endpoints') except is_boto3_error_code('InvalidVpcEndpoint.NotFound'): continue - except is_boto3_error_code('DryRunOperation'): - changed = True - result = 'Would have deleted VPC Endpoint if not in check mode' + except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: # pylint: disable=duplicate-except module.fail_json_aws(e, "Failed to delete VPC endpoint") return changed, result @@ -353,6 +443,8 @@ def main(): route_table_ids=dict(type='list', elements='str'), vpc_endpoint_id=dict(), client_token=dict(no_log=False), + tags=dict(type='dict'), + purge_tags=dict(type='bool', default=False), ) module = AnsibleAWSModule( argument_spec=argument_spec, @@ -373,7 +465,7 @@ def main(): date='2022-12-01', collection_name='community.aws') try: - ec2 = module.client('ec2') + ec2 = module.client('ec2', retry_decorator=AWSRetry.jittered_backoff()) except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: module.fail_json_aws(e, msg='Failed to connect to AWS') diff --git a/plugins/modules/ec2_vpc_endpoint_info.py b/plugins/modules/ec2_vpc_endpoint_info.py index 7706a00c915..425e0c63ec7 100644 --- a/plugins/modules/ec2_vpc_endpoint_info.py +++ b/plugins/modules/ec2_vpc_endpoint_info.py @@ -120,14 +120,12 @@ from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule +from ansible_collections.amazon.aws.plugins.module_utils.core import is_boto3_error_code +from ansible_collections.amazon.aws.plugins.module_utils.core import normalize_boto3_result from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ansible_dict_to_boto3_filter_list -def date_handler(obj): - return obj.isoformat() if hasattr(obj, 'isoformat') else obj - - @AWSRetry.exponential_backoff() def get_supported_services(client, module): results = list() @@ -149,16 +147,14 @@ def get_endpoints(client, module): params['Filters'] = ansible_dict_to_boto3_filter_list(module.params.get('filters')) if module.params.get('vpc_endpoint_ids'): params['VpcEndpointIds'] = module.params.get('vpc_endpoint_ids') - while True: - response = client.describe_vpc_endpoints(**params) - results.extend(response['VpcEndpoints']) - if 'NextToken' in response: - params['NextToken'] = response['NextToken'] - else: - break try: - results = json.loads(json.dumps(results, default=date_handler)) - except Exception as e: + paginator = client.get_paginator('describe_vpc_endpoints') + results = paginator.paginate(**params).build_full_result()['VpcEndpoints'] + + results = normalize_boto3_result(results) + except is_boto3_error_code('InvalidVpcEndpointId.NotFound'): + module.exit_json(msg='VpcEndpoint {0} does not exist'.format(module.params.get('vpc_endpoint_ids')), vpc_endpoints=[]) + except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e: # pylint: disable=duplicate-except module.fail_json_aws(e, msg="Failed to get endpoints") return dict(vpc_endpoints=[camel_dict_to_snake_dict(result) for result in results]) diff --git a/tests/integration/targets/ec2_vpc_endpoint/tasks/main.yml b/tests/integration/targets/ec2_vpc_endpoint/tasks/main.yml index a8fdbec889d..daa2a103624 100644 --- a/tests/integration/targets/ec2_vpc_endpoint/tasks/main.yml +++ b/tests/integration/targets/ec2_vpc_endpoint/tasks/main.yml @@ -137,6 +137,7 @@ state: present vpc_id: '{{ vpc_id }}' service: '{{ endpoint_service_a }}' + wait: true register: create_endpoint - name: Check standard return values assert: @@ -183,6 +184,7 @@ - '"creation_timestamp" in first_endpoint' - '"policy_document" in first_endpoint' - '"route_table_ids" in first_endpoint' + - first_endpoint.route_table_ids | length == 0 - '"service_name" in first_endpoint' - '"state" in first_endpoint' - '"vpc_endpoint_id" in first_endpoint' @@ -215,6 +217,7 @@ - '"creation_timestamp" in first_endpoint' - '"policy_document" in first_endpoint' - '"route_table_ids" in first_endpoint' + - first_endpoint.route_table_ids | length == 0 - '"service_name" in first_endpoint' - first_endpoint.service_name == endpoint_service_a - '"state" in first_endpoint' @@ -276,25 +279,408 @@ vars: first_endpoint: '{{ endpoint_info.vpc_endpoints[0] }}' -# ec2_vpc_endpoint is not idempotent without explicitly passing the endpoint ID -# - name: Create minimal endpoint - idempotency (check mode) + + # matches on parameters without explicitly passing the endpoint ID + - name: Create minimal endpoint - idempotency (check mode) + ec2_vpc_endpoint: + state: present + vpc_id: '{{ vpc_id }}' + service: '{{ endpoint_service_a }}' + register: create_endpoint_idem_check + check_mode: True + - assert: + that: + - create_endpoint_idem_check is not changed + + - name: Create minimal endpoint - idempotency + ec2_vpc_endpoint: + state: present + vpc_id: '{{ vpc_id }}' + service: '{{ endpoint_service_a }}' + register: create_endpoint_idem + - assert: + that: + - create_endpoint_idem is not changed + + - name: Delete minimal endpoint by ID (check_mode) + ec2_vpc_endpoint: + state: absent + vpc_endpoint_id: "{{ endpoint_id }}" + check_mode: true + register: endpoint_delete_check + - assert: + that: + - endpoint_delete_check is changed + + + - name: Delete minimal endpoint by ID + ec2_vpc_endpoint: + state: absent + vpc_endpoint_id: "{{ endpoint_id }}" + register: endpoint_delete_check + - assert: + that: + - endpoint_delete_check is changed + + - name: Delete minimal endpoint by ID - idempotency (check_mode) + ec2_vpc_endpoint: + state: absent + vpc_endpoint_id: "{{ endpoint_id }}" + check_mode: true + register: endpoint_delete_check + - assert: + that: + - endpoint_delete_check is not changed + + - name: Delete minimal endpoint by ID - idempotency + ec2_vpc_endpoint: + state: absent + vpc_endpoint_id: "{{ endpoint_id }}" + register: endpoint_delete_check + - assert: + that: + - endpoint_delete_check is not changed + + - name: Fetch Endpoints by ID (expect failed) + ec2_vpc_endpoint_info: + query: endpoints + vpc_endpoint_ids: "{{ endpoint_id }}" + ignore_errors: True + register: endpoint_info + - name: Assert endpoint does not exist + assert: + that: + - endpoint_info is successful + - '"does not exist" in endpoint_info.msg' + - endpoint_info.vpc_endpoints | length == 0 + + # Attempt to create an endpoint with a route table + - name: Create an endpoint with route table (check mode) + ec2_vpc_endpoint: + state: present + vpc_id: '{{ vpc_id }}' + service: '{{ endpoint_service_a }}' + route_table_ids: + - '{{ rtb_empty_id }}' + register: create_endpoint_check + check_mode: True + - name: Assert changed + assert: + that: + - create_endpoint_check is changed + + - name: Create an endpoint with route table + ec2_vpc_endpoint: + state: present + vpc_id: '{{ vpc_id }}' + service: '{{ endpoint_service_a }}' + route_table_ids: + - '{{ rtb_empty_id }}' + wait: true + register: create_rtb_endpoint + - name: Check standard return values + assert: + that: + - create_rtb_endpoint is changed + - '"result" in create_rtb_endpoint' + - '"creation_timestamp" in create_rtb_endpoint.result' + - '"dns_entries" in create_rtb_endpoint.result' + - '"groups" in create_rtb_endpoint.result' + - '"network_interface_ids" in create_rtb_endpoint.result' + - '"owner_id" in create_rtb_endpoint.result' + - '"policy_document" in create_rtb_endpoint.result' + - '"private_dns_enabled" in create_rtb_endpoint.result' + - '"route_table_ids" in create_rtb_endpoint.result' + - create_rtb_endpoint.result.route_table_ids | length == 1 + - create_rtb_endpoint.result.route_table_ids[0] == '{{ rtb_empty_id }}' + - create_rtb_endpoint.result.private_dns_enabled == False + - '"requester_managed" in create_rtb_endpoint.result' + - create_rtb_endpoint.result.requester_managed == False + - '"service_name" in create_rtb_endpoint.result' + - create_rtb_endpoint.result.service_name == endpoint_service_a + - '"state" in create_endpoint.result' + - create_rtb_endpoint.result.state == "available" + - '"vpc_endpoint_id" in create_rtb_endpoint.result' + - create_rtb_endpoint.result.vpc_endpoint_id.startswith("vpce-") + - '"vpc_endpoint_type" in create_rtb_endpoint.result' + - create_rtb_endpoint.result.vpc_endpoint_type == "Gateway" + - '"vpc_id" in create_rtb_endpoint.result' + - create_rtb_endpoint.result.vpc_id == vpc_id + + - name: Save Endpoint info in a fact + set_fact: + rtb_endpoint_id: '{{ create_rtb_endpoint.result.vpc_endpoint_id }}' + + - name: Create an endpoint with route table - idempotency (check mode) + ec2_vpc_endpoint: + state: present + vpc_id: '{{ vpc_id }}' + service: '{{ endpoint_service_a }}' + route_table_ids: + - '{{ rtb_empty_id }}' + register: create_endpoint_check + check_mode: True + - name: Assert changed + assert: + that: + - create_endpoint_check is not changed + + - name: Create an endpoint with route table - idempotency + ec2_vpc_endpoint: + state: present + vpc_id: '{{ vpc_id }}' + service: '{{ endpoint_service_a }}' + route_table_ids: + - '{{ rtb_empty_id }}' + register: create_endpoint_check + check_mode: True + - name: Assert changed + assert: + that: + - create_endpoint_check is not changed + +# # Endpoint modifications are not yet supported by the module +# # A Change the route table for the endpoint +# - name: Change the route table for the endpoint (check_mode) # ec2_vpc_endpoint: # state: present # vpc_id: '{{ vpc_id }}' +# vpc_endpoint_id: "{{ rtb_endpoint_id }}" # service: '{{ endpoint_service_a }}' -# register: create_endpoint_idem_check +# route_table_ids: +# - '{{ rtb_igw_id }}' # check_mode: True +# register: check_two_rtbs_endpoint +# +# - name: Assert second route table would be added +# assert: +# that: +# - check_two_rtbs_endpoint.changed +# +# - name: Change the route table for the endpoint +# ec2_vpc_endpoint: +# state: present +# vpc_id: '{{ vpc_id }}' +# vpc_endpoint_id: "{{ rtb_endpoint_id }}" +# service: '{{ endpoint_service_a }}' +# route_table_ids: +# - '{{ rtb_igw_id }}' +# register: two_rtbs_endpoint # -# - name: Create minimal endpoint - idempotency +# - name: Assert second route table would be added +# assert: +# that: +# - check_two_rtbs_endpoint.changed +# - two_rtbs_endpoint.result.route_table_ids | length == 1 +# - two_rtbs_endpoint.result.route_table_ids[0] == '{{ rtb_igw_id }}' +# +# - name: Change the route table for the endpoint - idempotency (check_mode) # ec2_vpc_endpoint: # state: present # vpc_id: '{{ vpc_id }}' +# vpc_endpoint_id: "{{ rtb_endpoint_id }}" # service: '{{ endpoint_service_a }}' -# register: create_endpoint_idem +# route_table_ids: +# - '{{ rtb_igw_id }}' +# check_mode: True +# register: check_two_rtbs_endpoint +# +# - name: Assert route table would not change +# assert: +# that: +# - not check_two_rtbs_endpoint.changed +# +# - name: Change the route table for the endpoint - idempotency +# ec2_vpc_endpoint: +# state: present +# vpc_id: '{{ vpc_id }}' +# vpc_endpoint_id: "{{ rtb_endpoint_id }}" +# service: '{{ endpoint_service_a }}' +# route_table_ids: +# - '{{ rtb_igw_id }}' +# register: two_rtbs_endpoint +# +# - name: Assert route table would not change +# assert: +# that: +# - not check_two_rtbs_endpoint.changed + + - name: Tag the endpoint (check_mode) + ec2_vpc_endpoint: + state: present + vpc_id: '{{ vpc_id }}' + vpc_endpoint_id: "{{ rtb_endpoint_id }}" + service: '{{ endpoint_service_a }}' + route_table_ids: + - '{{ rtb_empty_id }}' + tags: + camelCase: "helloWorld" + PascalCase: "HelloWorld" + snake_case: "hello_world" + "Title Case": "Hello World" + "lowercase spaced": "hello world" + check_mode: true + register: check_tag_vpc_endpoint + + - name: Assert tags would have changed + assert: + that: + - check_tag_vpc_endpoint.changed + + - name: Tag the endpoint + ec2_vpc_endpoint: + state: present + vpc_id: '{{ vpc_id }}' + vpc_endpoint_id: "{{ rtb_endpoint_id }}" + service: '{{ endpoint_service_a }}' + route_table_ids: + - '{{ rtb_igw_id }}' + tags: + camelCase: "helloWorld" + PascalCase: "HelloWorld" + snake_case: "hello_world" + "Title Case": "Hello World" + "lowercase spaced": "hello world" + register: tag_vpc_endpoint + + - name: Assert tags are successful + assert: + that: + - tag_vpc_endpoint.changed + - tag_vpc_endpoint.result.tags | length == 5 + - endpoint_tags["camelCase"] == "helloWorld" + - endpoint_tags["PascalCase"] == "HelloWorld" + - endpoint_tags["snake_case"] == "hello_world" + - endpoint_tags["Title Case"] == "Hello World" + - endpoint_tags["lowercase spaced"] == "hello world" + vars: + endpoint_tags: "{{ tag_vpc_endpoint.result.tags | items2dict(key_name='Key', value_name='Value') }}" + + - name: Query by tag + ec2_vpc_endpoint_info: + query: endpoints + filters: + "tag:camelCase": + - "helloWorld" + register: tag_result + + - name: Assert tag lookup found endpoint + assert: + that: + - tag_result is successful + - '"vpc_endpoints" in tag_result' + - first_endpoint.vpc_endpoint_id == rtb_endpoint_id + vars: + first_endpoint: '{{ tag_result.vpc_endpoints[0] }}' + + - name: Tag the endpoint - idempotency (check_mode) + ec2_vpc_endpoint: + state: present + vpc_id: '{{ vpc_id }}' + vpc_endpoint_id: "{{ rtb_endpoint_id }}" + service: '{{ endpoint_service_a }}' + route_table_ids: + - '{{ rtb_igw_id }}' + tags: + camelCase: "helloWorld" + PascalCase: "HelloWorld" + snake_case: "hello_world" + "Title Case": "Hello World" + "lowercase spaced": "hello world" + register: tag_vpc_endpoint_again + + - name: Assert tags would not change + assert: + that: + - not tag_vpc_endpoint_again.changed + + - name: Tag the endpoint - idempotency + ec2_vpc_endpoint: + state: present + vpc_id: '{{ vpc_id }}' + vpc_endpoint_id: "{{ rtb_endpoint_id }}" + service: '{{ endpoint_service_a }}' + route_table_ids: + - '{{ rtb_igw_id }}' + tags: + camelCase: "helloWorld" + PascalCase: "HelloWorld" + snake_case: "hello_world" + "Title Case": "Hello World" + "lowercase spaced": "hello world" + register: tag_vpc_endpoint_again + + - name: Assert tags would not change + assert: + that: + - not tag_vpc_endpoint_again.changed + + - name: Add a tag (check_mode) + ec2_vpc_endpoint: + state: present + vpc_id: '{{ vpc_id }}' + vpc_endpoint_id: "{{ rtb_endpoint_id }}" + service: '{{ endpoint_service_a }}' + route_table_ids: + - '{{ rtb_igw_id }}' + tags: + new_tag: "ANewTag" + check_mode: true + register: check_tag_vpc_endpoint + + - name: Assert tags would have changed + assert: + that: + - check_tag_vpc_endpoint.changed + + - name: Add a tag (purge_tags=False) + ec2_vpc_endpoint: + state: present + vpc_id: '{{ vpc_id }}' + vpc_endpoint_id: "{{ rtb_endpoint_id }}" + service: '{{ endpoint_service_a }}' + route_table_ids: + - '{{ rtb_igw_id }}' + tags: + new_tag: "ANewTag" + register: add_tag_vpc_endpoint + + - name: Assert tags changed + assert: + that: + - add_tag_vpc_endpoint.changed + - add_tag_vpc_endpoint.result.tags | length == 6 + - endpoint_tags["camelCase"] == "helloWorld" + - endpoint_tags["PascalCase"] == "HelloWorld" + - endpoint_tags["snake_case"] == "hello_world" + - endpoint_tags["Title Case"] == "Hello World" + - endpoint_tags["lowercase spaced"] == "hello world" + - endpoint_tags["new_tag"] == "ANewTag" + vars: + endpoint_tags: "{{ add_tag_vpc_endpoint.result.tags | items2dict(key_name='Key', value_name='Value') }}" + + - name: Add a tag (purge_tags=True) + ec2_vpc_endpoint: + state: present + vpc_id: '{{ vpc_id }}' + vpc_endpoint_id: "{{ rtb_endpoint_id }}" + service: '{{ endpoint_service_a }}' + route_table_ids: + - '{{ rtb_igw_id }}' + tags: + another_new_tag: "AnotherNewTag" + purge_tags: True + register: purge_tag_vpc_endpoint + + - name: Assert tags changed + assert: + that: + - purge_tag_vpc_endpoint.changed + - purge_tag_vpc_endpoint.result.tags | length == 1 + - endpoint_tags["another_new_tag"] == "AnotherNewTag" + vars: + endpoint_tags: "{{ purge_tag_vpc_endpoint.result.tags | items2dict(key_name='Key', value_name='Value') }}" - # Deletion - # Delete the routes first - you can't delete an endpoint with a route - # attached. - name: Delete minimal route table (no routes) ec2_vpc_route_table: state: absent @@ -314,35 +700,24 @@ that: - rtb_delete is changed - - name: Delete endpoint by ID (check_mode) + - name: Delete route table endpoint by ID ec2_vpc_endpoint: state: absent - vpc_endpoint_id: "{{ endpoint_id }}" - check_mode: true + vpc_endpoint_id: "{{ rtb_endpoint_id }}" register: endpoint_delete_check - assert: that: - endpoint_delete_check is changed - - name: Delete endpoint by ID + - name: Delete minimal endpoint by ID - idempotency (check_mode) ec2_vpc_endpoint: state: absent - vpc_endpoint_id: "{{ endpoint_id }}" + vpc_endpoint_id: "{{ rtb_endpoint_id }}" + check_mode: true register: endpoint_delete_check - assert: that: - - endpoint_delete_check is changed - -# XXX Bug: uses AWS's check mode which only checks permissions -# - name: Delete endpoint by ID - idempotency (check_mode) -# ec2_vpc_endpoint: -# state: absent -# vpc_endpoint_id: "{{ endpoint_id }}" -# check_mode: true -# register: endpoint_delete_check -# - assert: -# that: -# - endpoint_delete_check is not changed + - endpoint_delete_check is not changed - name: Delete endpoint by ID - idempotency ec2_vpc_endpoint: @@ -377,6 +752,8 @@ # ============================================================ # BEGIN POST-TEST CLEANUP always: + # Delete the routes first - you can't delete an endpoint with a route + # attached. - name: Delete minimal route table (no routes) ec2_vpc_route_table: state: absent @@ -397,10 +774,31 @@ vpc_endpoint_id: "{{ create_endpoint.result.vpc_endpoint_id }}" ignore_errors: True + - name: Delete endpoint + ec2_vpc_endpoint: + state: absent + vpc_endpoint_id: "{{ create_rtb_endpoint.result.vpc_endpoint_id }}" + ignore_errors: True + + - name: Query any remain endpoints we created (idempotency work is ongoing) # FIXME + ec2_vpc_endpoint_info: + query: endpoints + filters: + vpc-id: + - '{{ vpc_id }}' + register: test_endpoints + + - name: Delete all endpoints + ec2_vpc_endpoint: + state: absent + vpc_endpoint_id: '{{ item.vpc_endpoint_id }}' + with_items: '{{ test_endpoints.vpc_endpoints }}' + ignore_errors: True + - name: Remove IGW ec2_vpc_igw: state: absent - vpc_id: "{{ vpc_creation.vpc.id }}" + vpc_id: "{{ vpc_id }}" register: igw_deletion retries: 10 delay: 5 From e42c3303295b73f0623c43d02ab106b4ec74ade0 Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Sat, 10 Apr 2021 12:13:51 +0200 Subject: [PATCH 25/37] Update ec2_vpc_endpoint_info AWS retries This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/8acde773c1c89333ec10a90a311117f00d11167c --- plugins/modules/ec2_vpc_endpoint_info.py | 34 ++++++++++++++---------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/plugins/modules/ec2_vpc_endpoint_info.py b/plugins/modules/ec2_vpc_endpoint_info.py index 425e0c63ec7..d990a908943 100644 --- a/plugins/modules/ec2_vpc_endpoint_info.py +++ b/plugins/modules/ec2_vpc_endpoint_info.py @@ -126,21 +126,28 @@ from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ansible_dict_to_boto3_filter_list -@AWSRetry.exponential_backoff() +@AWSRetry.jittered_backoff() +def _describe_endpoints(client, **params): + paginator = client.get_paginator('describe_vpc_endpoints') + return paginator.paginate(**params).build_full_result() + + +@AWSRetry.jittered_backoff() +def _describe_endpoint_services(client, **params): + paginator = client.get_paginator('describe_vpc_endpoint_services') + return paginator.paginate(**params).build_full_result() + + def get_supported_services(client, module): - results = list() - params = dict() - while True: - response = client.describe_vpc_endpoint_services(**params) - results.extend(response['ServiceNames']) - if 'NextToken' in response: - params['NextToken'] = response['NextToken'] - else: - break + try: + services = _describe_endpoint_services(client) + except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e: + module.fail_json_aws(e, msg="Failed to get endpoint servicess") + + results = list(services['ServiceNames']) return dict(service_names=results) -@AWSRetry.exponential_backoff() def get_endpoints(client, module): results = list() params = dict() @@ -148,14 +155,13 @@ def get_endpoints(client, module): if module.params.get('vpc_endpoint_ids'): params['VpcEndpointIds'] = module.params.get('vpc_endpoint_ids') try: - paginator = client.get_paginator('describe_vpc_endpoints') - results = paginator.paginate(**params).build_full_result()['VpcEndpoints'] - + results = _describe_endpoints(client, **params)['VpcEndpoints'] results = normalize_boto3_result(results) except is_boto3_error_code('InvalidVpcEndpointId.NotFound'): module.exit_json(msg='VpcEndpoint {0} does not exist'.format(module.params.get('vpc_endpoint_ids')), vpc_endpoints=[]) except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e: # pylint: disable=duplicate-except module.fail_json_aws(e, msg="Failed to get endpoints") + return dict(vpc_endpoints=[camel_dict_to_snake_dict(result) for result in results]) From 54bbedb9b4f8bc035ad21508779fa58eb58faf7c Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Sat, 10 Apr 2021 13:20:00 +0200 Subject: [PATCH 26/37] Add a unique tag to test against This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/a0d4d9627193810e30e2eba09557608fdcad6f42 --- .../targets/ec2_vpc_endpoint/tasks/main.yml | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/integration/targets/ec2_vpc_endpoint/tasks/main.yml b/tests/integration/targets/ec2_vpc_endpoint/tasks/main.yml index daa2a103624..0bd2beed8c5 100644 --- a/tests/integration/targets/ec2_vpc_endpoint/tasks/main.yml +++ b/tests/integration/targets/ec2_vpc_endpoint/tasks/main.yml @@ -536,6 +536,7 @@ route_table_ids: - '{{ rtb_igw_id }}' tags: + testPrefix: '{{ resource_prefix }}' camelCase: "helloWorld" PascalCase: "HelloWorld" snake_case: "hello_world" @@ -547,7 +548,8 @@ assert: that: - tag_vpc_endpoint.changed - - tag_vpc_endpoint.result.tags | length == 5 + - tag_vpc_endpoint.result.tags | length == 6 + - endpoint_tags["testPrefix"] == resource_prefix - endpoint_tags["camelCase"] == "helloWorld" - endpoint_tags["PascalCase"] == "HelloWorld" - endpoint_tags["snake_case"] == "hello_world" @@ -560,8 +562,8 @@ ec2_vpc_endpoint_info: query: endpoints filters: - "tag:camelCase": - - "helloWorld" + "tag:testPrefix": + - "{{ resource_prefix }}" register: tag_result - name: Assert tag lookup found endpoint @@ -582,6 +584,7 @@ route_table_ids: - '{{ rtb_igw_id }}' tags: + testPrefix: '{{ resource_prefix }}' camelCase: "helloWorld" PascalCase: "HelloWorld" snake_case: "hello_world" @@ -603,6 +606,7 @@ route_table_ids: - '{{ rtb_igw_id }}' tags: + testPrefix: '{{ resource_prefix }}' camelCase: "helloWorld" PascalCase: "HelloWorld" snake_case: "hello_world" @@ -649,7 +653,8 @@ assert: that: - add_tag_vpc_endpoint.changed - - add_tag_vpc_endpoint.result.tags | length == 6 + - add_tag_vpc_endpoint.result.tags | length == 7 + - endpoint_tags["testPrefix"] == resource_prefix - endpoint_tags["camelCase"] == "helloWorld" - endpoint_tags["PascalCase"] == "HelloWorld" - endpoint_tags["snake_case"] == "hello_world" From 35858f7bdd971ed8e70fd0fbcc17efe42ff37a82 Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Thu, 6 May 2021 21:01:46 +0200 Subject: [PATCH 27/37] Update the default module requirements from python 2.6/boto to python 3.6/boto3 This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/c097c55293be0834a2b9d394733ec28965d142d7 --- plugins/modules/ec2_vpc_endpoint.py | 1 - plugins/modules/ec2_vpc_endpoint_info.py | 1 - plugins/modules/ec2_vpc_endpoint_service_info.py | 1 - 3 files changed, 3 deletions(-) diff --git a/plugins/modules/ec2_vpc_endpoint.py b/plugins/modules/ec2_vpc_endpoint.py index 2aa4441fac7..62424f93a11 100644 --- a/plugins/modules/ec2_vpc_endpoint.py +++ b/plugins/modules/ec2_vpc_endpoint.py @@ -14,7 +14,6 @@ - Creates AWS VPC endpoints. - Deletes AWS VPC endpoints. - This module supports check mode. -requirements: [ boto3 ] options: vpc_id: description: diff --git a/plugins/modules/ec2_vpc_endpoint_info.py b/plugins/modules/ec2_vpc_endpoint_info.py index d990a908943..fabeb46afe4 100644 --- a/plugins/modules/ec2_vpc_endpoint_info.py +++ b/plugins/modules/ec2_vpc_endpoint_info.py @@ -12,7 +12,6 @@ description: - Gets various details related to AWS VPC endpoints. - This module was called C(ec2_vpc_endpoint_facts) before Ansible 2.9. The usage did not change. -requirements: [ boto3 ] options: query: description: diff --git a/plugins/modules/ec2_vpc_endpoint_service_info.py b/plugins/modules/ec2_vpc_endpoint_service_info.py index 2afd0e5e906..8dee0652b84 100644 --- a/plugins/modules/ec2_vpc_endpoint_service_info.py +++ b/plugins/modules/ec2_vpc_endpoint_service_info.py @@ -11,7 +11,6 @@ version_added: 1.5.0 description: - Gets details related to AWS VPC Endpoint Services. -requirements: [ boto3 ] options: filters: description: From de996184fe69522c844843c0059d020957aa60b2 Mon Sep 17 00:00:00 2001 From: jillr Date: Thu, 29 Apr 2021 21:58:50 +0000 Subject: [PATCH 28/37] Remove shippable references from repo This collection has been operating on Zuul CI for some weeks now This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/4e0d83c65568a99a24307e37a14e6e0b173c948b --- tests/integration/targets/ec2_vpc_endpoint/aliases | 1 - tests/integration/targets/ec2_vpc_endpoint_service_info/aliases | 1 - 2 files changed, 2 deletions(-) diff --git a/tests/integration/targets/ec2_vpc_endpoint/aliases b/tests/integration/targets/ec2_vpc_endpoint/aliases index 68d272f2799..ce6ba529062 100644 --- a/tests/integration/targets/ec2_vpc_endpoint/aliases +++ b/tests/integration/targets/ec2_vpc_endpoint/aliases @@ -1,4 +1,3 @@ cloud/aws -shippable/aws/group2 ec2_vpc_endpoint_info diff --git a/tests/integration/targets/ec2_vpc_endpoint_service_info/aliases b/tests/integration/targets/ec2_vpc_endpoint_service_info/aliases index bf2988bbc2e..760a04f5d2b 100644 --- a/tests/integration/targets/ec2_vpc_endpoint_service_info/aliases +++ b/tests/integration/targets/ec2_vpc_endpoint_service_info/aliases @@ -1,3 +1,2 @@ cloud/aws -shippable/aws/group2 ec2_vpc_endpoint_service_info From fa42e02455c8babc5669aa1951a90fc63e48448a Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Fri, 9 Jul 2021 09:59:33 +0200 Subject: [PATCH 29/37] Remove unused imports This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/6d420e5a51e07674799d28e140ef035d8700da6f --- plugins/modules/ec2_vpc_endpoint.py | 1 - plugins/modules/ec2_vpc_endpoint_info.py | 2 -- 2 files changed, 3 deletions(-) diff --git a/plugins/modules/ec2_vpc_endpoint.py b/plugins/modules/ec2_vpc_endpoint.py index 62424f93a11..75ba2479afe 100644 --- a/plugins/modules/ec2_vpc_endpoint.py +++ b/plugins/modules/ec2_vpc_endpoint.py @@ -200,7 +200,6 @@ import datetime import json -import time import traceback try: diff --git a/plugins/modules/ec2_vpc_endpoint_info.py b/plugins/modules/ec2_vpc_endpoint_info.py index fabeb46afe4..f84434cb9af 100644 --- a/plugins/modules/ec2_vpc_endpoint_info.py +++ b/plugins/modules/ec2_vpc_endpoint_info.py @@ -109,8 +109,6 @@ vpc_id: "vpc-1111ffff" ''' -import json - try: import botocore except ImportError: From 0297ae6b05a6cd6b4d38c8d61c3c3ff10d764097 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A9ri=20Le=20Bouder?= Date: Wed, 14 Jul 2021 12:31:27 +0200 Subject: [PATCH 30/37] tests: disable ec2_vpc_endpoint See: https://github.com/ansible-collections/community.aws/issues/642 This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/13ab51298913f9a813ed442da83727dff8e44f09 --- tests/integration/targets/ec2_vpc_endpoint/aliases | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/targets/ec2_vpc_endpoint/aliases b/tests/integration/targets/ec2_vpc_endpoint/aliases index ce6ba529062..506820fc14b 100644 --- a/tests/integration/targets/ec2_vpc_endpoint/aliases +++ b/tests/integration/targets/ec2_vpc_endpoint/aliases @@ -1,3 +1,3 @@ cloud/aws - +disabled ec2_vpc_endpoint_info From d313a8b9b2aac39dac15a467cafcd6ba43b0d988 Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Sat, 31 Jul 2021 15:51:26 +0200 Subject: [PATCH 31/37] Attempt to fixup ec2_vpc_endpoint_service_info test failures This commit was initially merged in https://github.com/ansible-collections/community.aws See: https://github.com/ansible-collections/community.aws/commit/f2594a90fe51b60a890bbd72f67e1af054f58980 --- .../ec2_vpc_endpoint_service_info/tasks/main.yml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/tests/integration/targets/ec2_vpc_endpoint_service_info/tasks/main.yml b/tests/integration/targets/ec2_vpc_endpoint_service_info/tasks/main.yml index 40eb0a88924..22b290a34ff 100644 --- a/tests/integration/targets/ec2_vpc_endpoint_service_info/tasks/main.yml +++ b/tests/integration/targets/ec2_vpc_endpoint_service_info/tasks/main.yml @@ -5,13 +5,9 @@ aws_secret_key: '{{ aws_secret_key }}' security_token: '{{ security_token | default(omit) }}' region: '{{ aws_region }}' - # Needed until added to the group in Ansible 2.9 - ec2_vpc_endpoint_service_info: - aws_access_key: '{{ aws_access_key }}' - aws_secret_key: '{{ aws_secret_key }}' - security_token: '{{ security_token | default(omit) }}' - region: '{{ aws_region }}' - + collections: + - amazon.aws + - community.aws block: - name: 'List all available services (Check Mode)' From 5227180dc4282ee36f7187b9a37bc2835da2e06f Mon Sep 17 00:00:00 2001 From: Alina Buzachis Date: Thu, 26 Aug 2021 15:23:20 +0200 Subject: [PATCH 32/37] Update runtime --- meta/runtime.yml | 66 ++++++++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 28 deletions(-) diff --git a/meta/runtime.yml b/meta/runtime.yml index 7e23cbe5577..7801ec07115 100644 --- a/meta/runtime.yml +++ b/meta/runtime.yml @@ -49,81 +49,91 @@ action_groups: - ec2_vpc_subnet - ec2_vpc_subnet_info - s3_bucket - + - ec2_vpc_endpoint_facts + - ec2_vpc_endpoint + - ec2_vpc_endpoint_info + - ec2_vpc_endpoint_service_info plugin_routing: modules: aws_az_facts: deprecation: removal_date: 2022-06-01 warning_text: >- - aws_az_facts was renamed in Ansible 2.9 to aws_az_info. - Please update your tasks. + aws_az_facts was renamed in Ansible 2.9 to aws_az_info. + Please update your tasks. aws_caller_facts: deprecation: removal_date: 2021-12-01 warning_text: >- - aws_caller_facts was renamed in Ansible 2.9 to aws_caller_info. - Please update your tasks. + aws_caller_facts was renamed in Ansible 2.9 to aws_caller_info. + Please update your tasks. cloudformation_facts: deprecation: removal_date: 2021-12-01 warning_text: >- - cloudformation_facts has been deprecated and will be removed. - The cloudformation_info module returns the same information, but - not as ansible_facts. See the module documentation for more - information. + cloudformation_facts has been deprecated and will be removed. + The cloudformation_info module returns the same information, but + not as ansible_facts. See the module documentation for more + information. ec2: deprecation: removal_version: 4.0.0 warning_text: >- - The ec2 module is based upon a deprecated version of the AWS SDKs - and is deprecated in favor of the ec2_instance module. - Please update your tasks. + The ec2 module is based upon a deprecated version of the AWS SDKs + and is deprecated in favor of the ec2_instance module. + Please update your tasks. ec2_ami_facts: deprecation: removal_date: 2021-12-01 warning_text: >- - ec2_ami_facts was renamed in Ansible 2.9 to ec2_ami_info. - Please update your tasks. + ec2_ami_facts was renamed in Ansible 2.9 to ec2_ami_info. + Please update your tasks. ec2_eni_facts: deprecation: removal_date: 2021-12-01 warning_text: >- - ec2_eni_facts was renamed in Ansible 2.9 to ec2_eni_info. - Please update your tasks. + ec2_eni_facts was renamed in Ansible 2.9 to ec2_eni_info. + Please update your tasks. ec2_group_facts: deprecation: removal_date: 2021-12-01 warning_text: >- - ec2_group_facts was renamed in Ansible 2.9 to ec2_group_info. - Please update your tasks. + ec2_group_facts was renamed in Ansible 2.9 to ec2_group_info. + Please update your tasks. ec2_snapshot_facts: deprecation: removal_date: 2021-12-01 warning_text: >- - ec2_snapshot_facts was renamed in Ansible 2.9 to ec2_snapshot_info. - Please update your tasks. + ec2_snapshot_facts was renamed in Ansible 2.9 to ec2_snapshot_info. + Please update your tasks. ec2_vol_facts: deprecation: removal_date: 2021-12-01 warning_text: >- - ec2_vol_facts was renamed in Ansible 2.9 to ec2_vol_info. - Please update your tasks. + ec2_vol_facts was renamed in Ansible 2.9 to ec2_vol_info. + Please update your tasks. ec2_vpc_dhcp_option_facts: deprecation: removal_date: 2021-12-01 warning_text: >- - ec2_vpc_dhcp_option_facts was renamed in Ansible 2.9 to - ec2_vpc_dhcp_option_info. Please update your tasks. + ec2_vpc_dhcp_option_facts was renamed in Ansible 2.9 to + ec2_vpc_dhcp_option_info. Please update your tasks. ec2_vpc_net_facts: deprecation: removal_date: 2021-12-01 warning_text: >- - ec2_vpc_net_facts was renamed in Ansible 2.9 to ec2_vpc_net_info. - Please update your tasks. + ec2_vpc_net_facts was renamed in Ansible 2.9 to ec2_vpc_net_info. + Please update your tasks. ec2_vpc_subnet_facts: deprecation: removal_date: 2021-12-01 warning_text: >- - ec2_vpc_subnet_facts was renamed in Ansible 2.9 to - ec2_vpc_subnet_info. Please update your tasks. + ec2_vpc_subnet_facts was renamed in Ansible 2.9 to + ec2_vpc_subnet_info. Please update your tasks. + ec2_vpc_endpoint_facts: + deprecation: + removal_date: 2021-12-01 + warning_text: >- + ec2_vpc_endpoint_facts was renamed in Ansible 2.9 to + ec2_vpc_endpoint_info. + Please update your tasks. From 675634cd36d2a0bc16a478c825d82c3630176f0b Mon Sep 17 00:00:00 2001 From: Alina Buzachis Date: Thu, 26 Aug 2021 15:23:20 +0200 Subject: [PATCH 33/37] Update FQDN --- plugins/modules/ec2_vpc_endpoint.py | 12 +- plugins/modules/ec2_vpc_endpoint_facts.py | 211 +++++++++++++++++- plugins/modules/ec2_vpc_endpoint_info.py | 14 +- .../modules/ec2_vpc_endpoint_service_info.py | 2 +- 4 files changed, 224 insertions(+), 15 deletions(-) mode change 120000 => 100755 plugins/modules/ec2_vpc_endpoint_facts.py diff --git a/plugins/modules/ec2_vpc_endpoint.py b/plugins/modules/ec2_vpc_endpoint.py index 75ba2479afe..b7ef2547173 100644 --- a/plugins/modules/ec2_vpc_endpoint.py +++ b/plugins/modules/ec2_vpc_endpoint.py @@ -30,7 +30,7 @@ version_added: 1.5.0 service: description: - - An AWS supported vpc endpoint service. Use the M(community.aws.ec2_vpc_endpoint_info) + - An AWS supported vpc endpoint service. Use the M(amazon.aws.ec2_vpc_endpoint_info) module to describe the supported endpoint services. - Required when creating an endpoint. required: false @@ -123,7 +123,7 @@ # Note: These examples do not set authentication details, see the AWS Guide for details. - name: Create new vpc endpoint with a json template for policy - community.aws.ec2_vpc_endpoint: + amazon.aws.ec2_vpc_endpoint: state: present region: ap-southeast-2 vpc_id: vpc-12345678 @@ -135,7 +135,7 @@ register: new_vpc_endpoint - name: Create new vpc endpoint with the default policy - community.aws.ec2_vpc_endpoint: + amazon.aws.ec2_vpc_endpoint: state: present region: ap-southeast-2 vpc_id: vpc-12345678 @@ -146,7 +146,7 @@ register: new_vpc_endpoint - name: Create new vpc endpoint with json file - community.aws.ec2_vpc_endpoint: + amazon.aws.ec2_vpc_endpoint: state: present region: ap-southeast-2 vpc_id: vpc-12345678 @@ -158,7 +158,7 @@ register: new_vpc_endpoint - name: Delete newly created vpc endpoint - community.aws.ec2_vpc_endpoint: + amazon.aws.ec2_vpc_endpoint: state: absent vpc_endpoint_id: "{{ new_vpc_endpoint.result['VpcEndpointId'] }}" region: ap-southeast-2 @@ -460,7 +460,7 @@ def main(): if module.params.get('policy_file'): module.deprecate('The policy_file option has been deprecated and' ' will be removed after 2022-12-01', - date='2022-12-01', collection_name='community.aws') + date='2022-12-01', collection_name='amazon.aws') try: ec2 = module.client('ec2', retry_decorator=AWSRetry.jittered_backoff()) diff --git a/plugins/modules/ec2_vpc_endpoint_facts.py b/plugins/modules/ec2_vpc_endpoint_facts.py deleted file mode 120000 index d2a144a7b86..00000000000 --- a/plugins/modules/ec2_vpc_endpoint_facts.py +++ /dev/null @@ -1 +0,0 @@ -ec2_vpc_endpoint_info.py \ No newline at end of file diff --git a/plugins/modules/ec2_vpc_endpoint_facts.py b/plugins/modules/ec2_vpc_endpoint_facts.py new file mode 100755 index 00000000000..49a74b8af46 --- /dev/null +++ b/plugins/modules/ec2_vpc_endpoint_facts.py @@ -0,0 +1,210 @@ +#!/usr/bin/python +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + + +DOCUMENTATION = r''' +module: ec2_vpc_endpoint_info +short_description: Retrieves AWS VPC endpoints details using AWS methods. +version_added: 1.0.0 +description: + - Gets various details related to AWS VPC endpoints. + - This module was called C(ec2_vpc_endpoint_facts) before Ansible 2.9. The usage did not change. +options: + query: + description: + - Defaults to C(endpoints). + - Specifies the query action to take. + - I(query=endpoints) returns information about AWS VPC endpoints. + - Retrieving information about services using I(query=services) has been + deprecated in favour of the M(ec2_vpc_endpoint_service_info) module. + - The I(query) option has been deprecated and will be removed after 2022-12-01. + required: False + choices: + - services + - endpoints + type: str + vpc_endpoint_ids: + description: + - The IDs of specific endpoints to retrieve the details of. + type: list + elements: str + filters: + description: + - A dict of filters to apply. Each dict item consists of a filter key and a filter value. + See U(https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeVpcEndpoints.html) + for possible filters. + type: dict +author: Karen Cheng (@Etherdaemon) +extends_documentation_fragment: +- amazon.aws.aws +- amazon.aws.ec2 + +''' + +EXAMPLES = r''' +# Simple example of listing all support AWS services for VPC endpoints +- name: List supported AWS endpoint services + amazon.aws.ec2_vpc_endpoint_info: + query: services + region: ap-southeast-2 + register: supported_endpoint_services + +- name: Get all endpoints in ap-southeast-2 region + amazon.aws.ec2_vpc_endpoint_info: + query: endpoints + region: ap-southeast-2 + register: existing_endpoints + +- name: Get all endpoints with specific filters + amazon.aws.ec2_vpc_endpoint_info: + query: endpoints + region: ap-southeast-2 + filters: + vpc-id: + - vpc-12345678 + - vpc-87654321 + vpc-endpoint-state: + - available + - pending + register: existing_endpoints + +- name: Get details on specific endpoint + amazon.aws.ec2_vpc_endpoint_info: + query: endpoints + region: ap-southeast-2 + vpc_endpoint_ids: + - vpce-12345678 + register: endpoint_details +''' + +RETURN = r''' +service_names: + description: AWS VPC endpoint service names + returned: I(query) is C(services) + type: list + sample: + service_names: + - com.amazonaws.ap-southeast-2.s3 +vpc_endpoints: + description: + - A list of endpoints that match the query. Each endpoint has the keys creation_timestamp, + policy_document, route_table_ids, service_name, state, vpc_endpoint_id, vpc_id. + returned: I(query) is C(endpoints) + type: list + sample: + vpc_endpoints: + - creation_timestamp: "2017-02-16T11:06:48+00:00" + policy_document: > + "{\"Version\":\"2012-10-17\",\"Id\":\"Policy1450910922815\", + \"Statement\":[{\"Sid\":\"Stmt1450910920641\",\"Effect\":\"Allow\", + \"Principal\":\"*\",\"Action\":\"s3:*\",\"Resource\":[\"arn:aws:s3:::*/*\",\"arn:aws:s3:::*\"]}]}" + route_table_ids: + - rtb-abcd1234 + service_name: "com.amazonaws.ap-southeast-2.s3" + state: "available" + vpc_endpoint_id: "vpce-abbad0d0" + vpc_id: "vpc-1111ffff" +''' + +try: + import botocore +except ImportError: + pass # Handled by AnsibleAWSModule + +from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict + +from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule +from ansible_collections.amazon.aws.plugins.module_utils.core import is_boto3_error_code +from ansible_collections.amazon.aws.plugins.module_utils.core import normalize_boto3_result +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ansible_dict_to_boto3_filter_list + + +@AWSRetry.jittered_backoff() +def _describe_endpoints(client, **params): + paginator = client.get_paginator('describe_vpc_endpoints') + return paginator.paginate(**params).build_full_result() + + +@AWSRetry.jittered_backoff() +def _describe_endpoint_services(client, **params): + paginator = client.get_paginator('describe_vpc_endpoint_services') + return paginator.paginate(**params).build_full_result() + + +def get_supported_services(client, module): + try: + services = _describe_endpoint_services(client) + except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e: + module.fail_json_aws(e, msg="Failed to get endpoint servicess") + + results = list(services['ServiceNames']) + return dict(service_names=results) + + +def get_endpoints(client, module): + results = list() + params = dict() + params['Filters'] = ansible_dict_to_boto3_filter_list(module.params.get('filters')) + if module.params.get('vpc_endpoint_ids'): + params['VpcEndpointIds'] = module.params.get('vpc_endpoint_ids') + try: + results = _describe_endpoints(client, **params)['VpcEndpoints'] + results = normalize_boto3_result(results) + except is_boto3_error_code('InvalidVpcEndpointId.NotFound'): + module.exit_json(msg='VpcEndpoint {0} does not exist'.format(module.params.get('vpc_endpoint_ids')), vpc_endpoints=[]) + except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e: # pylint: disable=duplicate-except + module.fail_json_aws(e, msg="Failed to get endpoints") + + return dict(vpc_endpoints=[camel_dict_to_snake_dict(result) for result in results]) + + +def main(): + argument_spec = dict( + query=dict(choices=['services', 'endpoints'], required=False), + filters=dict(default={}, type='dict'), + vpc_endpoint_ids=dict(type='list', elements='str'), + ) + + module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=True) + if module._name == 'ec2_vpc_endpoint_facts': + module.deprecate("The 'ec2_vpc_endpoint_facts' module has been renamed to 'ec2_vpc_endpoint_info'", date='2021-12-01', collection_name='amazon.aws') + + # Validate Requirements + try: + connection = module.client('ec2') + except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: + module.fail_json_aws(e, msg='Failed to connect to AWS') + + query = module.params.get('query') + if query == 'endpoints': + module.deprecate('The query option has been deprecated and' + ' will be removed after 2022-12-01. Searching for' + ' `endpoints` is now the default and after' + ' 2022-12-01 this module will only support fetching' + ' endpoints.', + date='2022-12-01', collection_name='amazon.aws') + elif query == 'services': + module.deprecate('Support for fetching service information with this ' + 'module has been deprecated and will be removed after' + ' 2022-12-01. ' + 'Please use the ec2_vpc_endpoint_service_info module ' + 'instead.', date='2022-12-01', + collection_name='amazon.aws') + else: + query = 'endpoints' + + invocations = { + 'services': get_supported_services, + 'endpoints': get_endpoints, + } + results = invocations[query](connection, module) + + module.exit_json(**results) + + +if __name__ == '__main__': + main() diff --git a/plugins/modules/ec2_vpc_endpoint_info.py b/plugins/modules/ec2_vpc_endpoint_info.py index f84434cb9af..49a74b8af46 100644 --- a/plugins/modules/ec2_vpc_endpoint_info.py +++ b/plugins/modules/ec2_vpc_endpoint_info.py @@ -47,19 +47,19 @@ EXAMPLES = r''' # Simple example of listing all support AWS services for VPC endpoints - name: List supported AWS endpoint services - community.aws.ec2_vpc_endpoint_info: + amazon.aws.ec2_vpc_endpoint_info: query: services region: ap-southeast-2 register: supported_endpoint_services - name: Get all endpoints in ap-southeast-2 region - community.aws.ec2_vpc_endpoint_info: + amazon.aws.ec2_vpc_endpoint_info: query: endpoints region: ap-southeast-2 register: existing_endpoints - name: Get all endpoints with specific filters - community.aws.ec2_vpc_endpoint_info: + amazon.aws.ec2_vpc_endpoint_info: query: endpoints region: ap-southeast-2 filters: @@ -72,7 +72,7 @@ register: existing_endpoints - name: Get details on specific endpoint - community.aws.ec2_vpc_endpoint_info: + amazon.aws.ec2_vpc_endpoint_info: query: endpoints region: ap-southeast-2 vpc_endpoint_ids: @@ -171,7 +171,7 @@ def main(): module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=True) if module._name == 'ec2_vpc_endpoint_facts': - module.deprecate("The 'ec2_vpc_endpoint_facts' module has been renamed to 'ec2_vpc_endpoint_info'", date='2021-12-01', collection_name='community.aws') + module.deprecate("The 'ec2_vpc_endpoint_facts' module has been renamed to 'ec2_vpc_endpoint_info'", date='2021-12-01', collection_name='amazon.aws') # Validate Requirements try: @@ -186,14 +186,14 @@ def main(): ' `endpoints` is now the default and after' ' 2022-12-01 this module will only support fetching' ' endpoints.', - date='2022-12-01', collection_name='community.aws') + date='2022-12-01', collection_name='amazon.aws') elif query == 'services': module.deprecate('Support for fetching service information with this ' 'module has been deprecated and will be removed after' ' 2022-12-01. ' 'Please use the ec2_vpc_endpoint_service_info module ' 'instead.', date='2022-12-01', - collection_name='community.aws') + collection_name='amazon.aws') else: query = 'endpoints' diff --git a/plugins/modules/ec2_vpc_endpoint_service_info.py b/plugins/modules/ec2_vpc_endpoint_service_info.py index 8dee0652b84..974ed5dd944 100644 --- a/plugins/modules/ec2_vpc_endpoint_service_info.py +++ b/plugins/modules/ec2_vpc_endpoint_service_info.py @@ -35,7 +35,7 @@ EXAMPLES = r''' # Simple example of listing all supported AWS services for VPC endpoints - name: List supported AWS endpoint services - community.aws.ec2_vpc_endpoint_service_info: + amazon.aws.ec2_vpc_endpoint_service_info: region: ap-southeast-2 register: supported_endpoint_services ''' From b3504cfbfbbc762085cc1661ca1eadaa92d71775 Mon Sep 17 00:00:00 2001 From: Alina Buzachis Date: Thu, 26 Aug 2021 15:23:20 +0200 Subject: [PATCH 34/37] Remove collection reference inside the tests --- .../ec2_vpc_endpoint/defaults/main.yml | 7 +- .../targets/ec2_vpc_endpoint/tasks/main.yml | 546 +++++++++--------- 2 files changed, 276 insertions(+), 277 deletions(-) diff --git a/tests/integration/targets/ec2_vpc_endpoint/defaults/main.yml b/tests/integration/targets/ec2_vpc_endpoint/defaults/main.yml index f0041c402e5..3869e983b9f 100644 --- a/tests/integration/targets/ec2_vpc_endpoint/defaults/main.yml +++ b/tests/integration/targets/ec2_vpc_endpoint/defaults/main.yml @@ -1,8 +1,7 @@ ---- vpc_name: '{{ resource_prefix }}-vpc' vpc_seed: '{{ resource_prefix }}' -vpc_cidr: '10.{{ 256 | random(seed=vpc_seed) }}.22.0/24' +vpc_cidr: 10.{{ 256 | random(seed=vpc_seed) }}.22.0/24 # S3 and EC2 should generally be available... -endpoint_service_a: 'com.amazonaws.{{ aws_region }}.s3' -endpoint_service_b: 'com.amazonaws.{{ aws_region }}.ec2' +endpoint_service_a: com.amazonaws.{{ aws_region }}.s3 +endpoint_service_b: com.amazonaws.{{ aws_region }}.ec2 diff --git a/tests/integration/targets/ec2_vpc_endpoint/tasks/main.yml b/tests/integration/targets/ec2_vpc_endpoint/tasks/main.yml index 0bd2beed8c5..b3ef4e23315 100644 --- a/tests/integration/targets/ec2_vpc_endpoint/tasks/main.yml +++ b/tests/integration/targets/ec2_vpc_endpoint/tasks/main.yml @@ -1,50 +1,46 @@ ---- - name: ec2_vpc_endpoint tests - collections: - - amazon.aws - module_defaults: group/aws: - aws_access_key: "{{ aws_access_key }}" - aws_secret_key: "{{ aws_secret_key }}" - security_token: "{{ security_token | default(omit) }}" - region: "{{ aws_region }}" + aws_access_key: '{{ aws_access_key }}' + aws_secret_key: '{{ aws_secret_key }}' + security_token: '{{ security_token | default(omit) }}' + region: '{{ aws_region }}' block: # ============================================================ # BEGIN PRE-TEST SETUP - name: create a VPC ec2_vpc_net: state: present - name: "{{ vpc_name }}" - cidr_block: "{{ vpc_cidr }}" + name: '{{ vpc_name }}' + cidr_block: '{{ vpc_cidr }}' tags: - AnsibleTest: 'ec2_vpc_endpoint' + AnsibleTest: ec2_vpc_endpoint AnsibleRun: '{{ resource_prefix }}' register: vpc_creation - name: Assert success assert: that: - - vpc_creation is successful + - vpc_creation is successful - name: Create an IGW ec2_vpc_igw: - vpc_id: "{{ vpc_creation.vpc.id }}" + vpc_id: '{{ vpc_creation.vpc.id }}' state: present tags: - Name: "{{ resource_prefix }}" - AnsibleTest: 'ec2_vpc_endpoint' + Name: '{{ resource_prefix }}' + AnsibleTest: ec2_vpc_endpoint AnsibleRun: '{{ resource_prefix }}' register: igw_creation - name: Assert success assert: that: - - igw_creation is successful + - igw_creation is successful - name: Create a minimal route table (no routes) ec2_vpc_route_table: vpc_id: '{{ vpc_creation.vpc.id }}' tags: - AnsibleTest: 'ec2_vpc_endpoint' + AnsibleTest: ec2_vpc_endpoint AnsibleRun: '{{ resource_prefix }}' Name: '{{ resource_prefix }}-empty' subnets: [] @@ -55,13 +51,13 @@ ec2_vpc_route_table: vpc_id: '{{ vpc_creation.vpc.id }}' tags: - AnsibleTest: 'ec2_vpc_endpoint' + AnsibleTest: ec2_vpc_endpoint AnsibleRun: '{{ resource_prefix }}' Name: '{{ resource_prefix }}-igw' subnets: [] routes: - - dest: 0.0.0.0/0 - gateway_id: "{{ igw_creation.gateway_id }}" + - dest: 0.0.0.0/0 + gateway_id: '{{ igw_creation.gateway_id }}' register: rtb_creation_igw - name: Save VPC info in a fact @@ -78,30 +74,30 @@ ec2_vpc_endpoint_info: query: endpoints register: endpoint_info - check_mode: True + check_mode: true - name: Assert success assert: that: # May be run in parallel, the only thing we can guarantee is # - we shouldn't error # - we should return 'vpc_endpoints' (even if it's empty) - - endpoint_info is successful - - '"vpc_endpoints" in endpoint_info' + - endpoint_info is successful + - '"vpc_endpoints" in endpoint_info' - name: Fetch Services in check_mode ec2_vpc_endpoint_info: query: services register: endpoint_info - check_mode: True + check_mode: true - name: Assert success assert: that: - - endpoint_info is successful - - '"service_names" in endpoint_info' + - endpoint_info is successful + - '"service_names" in endpoint_info' # This is just 2 arbitrary AWS services that should (generally) be # available. The actual list will vary over time and between regions - - endpoint_service_a in endpoint_info.service_names - - endpoint_service_b in endpoint_info.service_names + - endpoint_service_a in endpoint_info.service_names + - endpoint_service_b in endpoint_info.service_names # Fetch services without check mode # Note: Filters not supported on services via this module, this is all we can test for now @@ -112,12 +108,12 @@ - name: Assert success assert: that: - - endpoint_info is successful - - '"service_names" in endpoint_info' + - endpoint_info is successful + - '"service_names" in endpoint_info' # This is just 2 arbitrary AWS services that should (generally) be # available. The actual list will vary over time and between regions - - endpoint_service_a in endpoint_info.service_names - - endpoint_service_b in endpoint_info.service_names + - endpoint_service_a in endpoint_info.service_names + - endpoint_service_b in endpoint_info.service_names # Attempt to create an endpoint - name: Create minimal endpoint (check mode) @@ -126,11 +122,11 @@ vpc_id: '{{ vpc_id }}' service: '{{ endpoint_service_a }}' register: create_endpoint_check - check_mode: True + check_mode: true - name: Assert changed assert: that: - - create_endpoint_check is changed + - create_endpoint_check is changed - name: Create minimal endpoint ec2_vpc_endpoint: @@ -142,28 +138,28 @@ - name: Check standard return values assert: that: - - create_endpoint is changed - - '"result" in create_endpoint' - - '"creation_timestamp" in create_endpoint.result' - - '"dns_entries" in create_endpoint.result' - - '"groups" in create_endpoint.result' - - '"network_interface_ids" in create_endpoint.result' - - '"owner_id" in create_endpoint.result' - - '"policy_document" in create_endpoint.result' - - '"private_dns_enabled" in create_endpoint.result' - - create_endpoint.result.private_dns_enabled == False - - '"requester_managed" in create_endpoint.result' - - create_endpoint.result.requester_managed == False - - '"service_name" in create_endpoint.result' - - create_endpoint.result.service_name == endpoint_service_a - - '"state" in create_endpoint.result' - - create_endpoint.result.state == "available" - - '"vpc_endpoint_id" in create_endpoint.result' - - create_endpoint.result.vpc_endpoint_id.startswith("vpce-") - - '"vpc_endpoint_type" in create_endpoint.result' - - create_endpoint.result.vpc_endpoint_type == "Gateway" - - '"vpc_id" in create_endpoint.result' - - create_endpoint.result.vpc_id == vpc_id + - create_endpoint is changed + - '"result" in create_endpoint' + - '"creation_timestamp" in create_endpoint.result' + - '"dns_entries" in create_endpoint.result' + - '"groups" in create_endpoint.result' + - '"network_interface_ids" in create_endpoint.result' + - '"owner_id" in create_endpoint.result' + - '"policy_document" in create_endpoint.result' + - '"private_dns_enabled" in create_endpoint.result' + - create_endpoint.result.private_dns_enabled == False + - '"requester_managed" in create_endpoint.result' + - create_endpoint.result.requester_managed == False + - '"service_name" in create_endpoint.result' + - create_endpoint.result.service_name == endpoint_service_a + - '"state" in create_endpoint.result' + - create_endpoint.result.state == "available" + - '"vpc_endpoint_id" in create_endpoint.result' + - create_endpoint.result.vpc_endpoint_id.startswith("vpce-") + - '"vpc_endpoint_type" in create_endpoint.result' + - create_endpoint.result.vpc_endpoint_type == "Gateway" + - '"vpc_id" in create_endpoint.result' + - create_endpoint.result.vpc_id == vpc_id - name: Save Endpoint info in a fact set_fact: @@ -179,28 +175,29 @@ that: # We're fetching all endpoints, there's no guarantee what the values # will be - - endpoint_info is successful - - '"vpc_endpoints" in endpoint_info' - - '"creation_timestamp" in first_endpoint' - - '"policy_document" in first_endpoint' - - '"route_table_ids" in first_endpoint' - - first_endpoint.route_table_ids | length == 0 - - '"service_name" in first_endpoint' - - '"state" in first_endpoint' - - '"vpc_endpoint_id" in first_endpoint' - - '"vpc_id" in first_endpoint' + - endpoint_info is successful + - '"vpc_endpoints" in endpoint_info' + - '"creation_timestamp" in first_endpoint' + - '"policy_document" in first_endpoint' + - '"route_table_ids" in first_endpoint' + - first_endpoint.route_table_ids | length == 0 + - '"service_name" in first_endpoint' + - '"state" in first_endpoint' + - '"vpc_endpoint_id" in first_endpoint' + - '"vpc_id" in first_endpoint' # Not yet documented, but returned - - '"dns_entries" in first_endpoint' - - '"groups" in first_endpoint' - - '"network_interface_ids" in first_endpoint' - - '"owner_id" in first_endpoint' - - '"private_dns_enabled" in first_endpoint' - - '"requester_managed" in first_endpoint' - - '"subnet_ids" in first_endpoint' - - '"tags" in first_endpoint' - - '"vpc_endpoint_type" in first_endpoint' + - '"dns_entries" in first_endpoint' + - '"groups" in first_endpoint' + - '"network_interface_ids" in first_endpoint' + - '"owner_id" in first_endpoint' + - '"private_dns_enabled" in first_endpoint' + - '"requester_managed" in first_endpoint' + - '"subnet_ids" in first_endpoint' + - '"tags" in first_endpoint' + - '"vpc_endpoint_type" in first_endpoint' # Make sure our endpoint is included - - endpoint_id in ( endpoint_info | community.general.json_query("vpc_endpoints[*].vpc_endpoint_id") | list | flatten ) + - endpoint_id in ( endpoint_info | community.general.json_query("vpc_endpoints[*].vpc_endpoint_id") + | list | flatten ) vars: first_endpoint: '{{ endpoint_info.vpc_endpoints[0] }}' @@ -212,32 +209,32 @@ - name: Assert success assert: that: - - endpoint_info is successful - - '"vpc_endpoints" in endpoint_info' - - '"creation_timestamp" in first_endpoint' - - '"policy_document" in first_endpoint' - - '"route_table_ids" in first_endpoint' - - first_endpoint.route_table_ids | length == 0 - - '"service_name" in first_endpoint' - - first_endpoint.service_name == endpoint_service_a - - '"state" in first_endpoint' - - first_endpoint.state == "available" - - '"vpc_endpoint_id" in first_endpoint' - - first_endpoint.vpc_endpoint_id == endpoint_id - - '"vpc_id" in first_endpoint' - - first_endpoint.vpc_id == vpc_id + - endpoint_info is successful + - '"vpc_endpoints" in endpoint_info' + - '"creation_timestamp" in first_endpoint' + - '"policy_document" in first_endpoint' + - '"route_table_ids" in first_endpoint' + - first_endpoint.route_table_ids | length == 0 + - '"service_name" in first_endpoint' + - first_endpoint.service_name == endpoint_service_a + - '"state" in first_endpoint' + - first_endpoint.state == "available" + - '"vpc_endpoint_id" in first_endpoint' + - first_endpoint.vpc_endpoint_id == endpoint_id + - '"vpc_id" in first_endpoint' + - first_endpoint.vpc_id == vpc_id # Not yet documented, but returned - - '"dns_entries" in first_endpoint' - - '"groups" in first_endpoint' - - '"network_interface_ids" in first_endpoint' - - '"owner_id" in first_endpoint' - - '"private_dns_enabled" in first_endpoint' - - first_endpoint.private_dns_enabled == False - - '"requester_managed" in first_endpoint' - - first_endpoint.requester_managed == False - - '"subnet_ids" in first_endpoint' - - '"tags" in first_endpoint' - - '"vpc_endpoint_type" in first_endpoint' + - '"dns_entries" in first_endpoint' + - '"groups" in first_endpoint' + - '"network_interface_ids" in first_endpoint' + - '"owner_id" in first_endpoint' + - '"private_dns_enabled" in first_endpoint' + - first_endpoint.private_dns_enabled == False + - '"requester_managed" in first_endpoint' + - first_endpoint.requester_managed == False + - '"subnet_ids" in first_endpoint' + - '"tags" in first_endpoint' + - '"vpc_endpoint_type" in first_endpoint' vars: first_endpoint: '{{ endpoint_info.vpc_endpoints[0] }}' @@ -251,31 +248,31 @@ - name: Assert success assert: that: - - endpoint_info is successful - - '"vpc_endpoints" in endpoint_info' - - '"creation_timestamp" in first_endpoint' - - '"policy_document" in first_endpoint' - - '"route_table_ids" in first_endpoint' - - '"service_name" in first_endpoint' - - first_endpoint.service_name == endpoint_service_a - - '"state" in first_endpoint' - - first_endpoint.state == "available" - - '"vpc_endpoint_id" in first_endpoint' - - first_endpoint.vpc_endpoint_id == endpoint_id - - '"vpc_id" in first_endpoint' - - first_endpoint.vpc_id == vpc_id + - endpoint_info is successful + - '"vpc_endpoints" in endpoint_info' + - '"creation_timestamp" in first_endpoint' + - '"policy_document" in first_endpoint' + - '"route_table_ids" in first_endpoint' + - '"service_name" in first_endpoint' + - first_endpoint.service_name == endpoint_service_a + - '"state" in first_endpoint' + - first_endpoint.state == "available" + - '"vpc_endpoint_id" in first_endpoint' + - first_endpoint.vpc_endpoint_id == endpoint_id + - '"vpc_id" in first_endpoint' + - first_endpoint.vpc_id == vpc_id # Not yet documented, but returned - - '"dns_entries" in first_endpoint' - - '"groups" in first_endpoint' - - '"network_interface_ids" in first_endpoint' - - '"owner_id" in first_endpoint' - - '"private_dns_enabled" in first_endpoint' - - first_endpoint.private_dns_enabled == False - - '"requester_managed" in first_endpoint' - - first_endpoint.requester_managed == False - - '"subnet_ids" in first_endpoint' - - '"tags" in first_endpoint' - - '"vpc_endpoint_type" in first_endpoint' + - '"dns_entries" in first_endpoint' + - '"groups" in first_endpoint' + - '"network_interface_ids" in first_endpoint' + - '"owner_id" in first_endpoint' + - '"private_dns_enabled" in first_endpoint' + - first_endpoint.private_dns_enabled == False + - '"requester_managed" in first_endpoint' + - first_endpoint.requester_managed == False + - '"subnet_ids" in first_endpoint' + - '"tags" in first_endpoint' + - '"vpc_endpoint_type" in first_endpoint' vars: first_endpoint: '{{ endpoint_info.vpc_endpoints[0] }}' @@ -287,10 +284,10 @@ vpc_id: '{{ vpc_id }}' service: '{{ endpoint_service_a }}' register: create_endpoint_idem_check - check_mode: True + check_mode: true - assert: that: - - create_endpoint_idem_check is not changed + - create_endpoint_idem_check is not changed - name: Create minimal endpoint - idempotency ec2_vpc_endpoint: @@ -300,59 +297,59 @@ register: create_endpoint_idem - assert: that: - - create_endpoint_idem is not changed + - create_endpoint_idem is not changed - name: Delete minimal endpoint by ID (check_mode) ec2_vpc_endpoint: state: absent - vpc_endpoint_id: "{{ endpoint_id }}" + vpc_endpoint_id: '{{ endpoint_id }}' check_mode: true register: endpoint_delete_check - assert: that: - - endpoint_delete_check is changed + - endpoint_delete_check is changed - name: Delete minimal endpoint by ID ec2_vpc_endpoint: state: absent - vpc_endpoint_id: "{{ endpoint_id }}" + vpc_endpoint_id: '{{ endpoint_id }}' register: endpoint_delete_check - assert: that: - - endpoint_delete_check is changed + - endpoint_delete_check is changed - name: Delete minimal endpoint by ID - idempotency (check_mode) ec2_vpc_endpoint: state: absent - vpc_endpoint_id: "{{ endpoint_id }}" + vpc_endpoint_id: '{{ endpoint_id }}' check_mode: true register: endpoint_delete_check - assert: that: - - endpoint_delete_check is not changed + - endpoint_delete_check is not changed - name: Delete minimal endpoint by ID - idempotency ec2_vpc_endpoint: state: absent - vpc_endpoint_id: "{{ endpoint_id }}" + vpc_endpoint_id: '{{ endpoint_id }}' register: endpoint_delete_check - assert: that: - - endpoint_delete_check is not changed + - endpoint_delete_check is not changed - name: Fetch Endpoints by ID (expect failed) ec2_vpc_endpoint_info: query: endpoints - vpc_endpoint_ids: "{{ endpoint_id }}" - ignore_errors: True + vpc_endpoint_ids: '{{ endpoint_id }}' + ignore_errors: true register: endpoint_info - name: Assert endpoint does not exist assert: that: - - endpoint_info is successful - - '"does not exist" in endpoint_info.msg' - - endpoint_info.vpc_endpoints | length == 0 + - endpoint_info is successful + - '"does not exist" in endpoint_info.msg' + - endpoint_info.vpc_endpoints | length == 0 # Attempt to create an endpoint with a route table - name: Create an endpoint with route table (check mode) @@ -361,13 +358,13 @@ vpc_id: '{{ vpc_id }}' service: '{{ endpoint_service_a }}' route_table_ids: - - '{{ rtb_empty_id }}' + - '{{ rtb_empty_id }}' register: create_endpoint_check - check_mode: True + check_mode: true - name: Assert changed assert: that: - - create_endpoint_check is changed + - create_endpoint_check is changed - name: Create an endpoint with route table ec2_vpc_endpoint: @@ -375,37 +372,37 @@ vpc_id: '{{ vpc_id }}' service: '{{ endpoint_service_a }}' route_table_ids: - - '{{ rtb_empty_id }}' + - '{{ rtb_empty_id }}' wait: true register: create_rtb_endpoint - name: Check standard return values assert: that: - - create_rtb_endpoint is changed - - '"result" in create_rtb_endpoint' - - '"creation_timestamp" in create_rtb_endpoint.result' - - '"dns_entries" in create_rtb_endpoint.result' - - '"groups" in create_rtb_endpoint.result' - - '"network_interface_ids" in create_rtb_endpoint.result' - - '"owner_id" in create_rtb_endpoint.result' - - '"policy_document" in create_rtb_endpoint.result' - - '"private_dns_enabled" in create_rtb_endpoint.result' - - '"route_table_ids" in create_rtb_endpoint.result' - - create_rtb_endpoint.result.route_table_ids | length == 1 - - create_rtb_endpoint.result.route_table_ids[0] == '{{ rtb_empty_id }}' - - create_rtb_endpoint.result.private_dns_enabled == False - - '"requester_managed" in create_rtb_endpoint.result' - - create_rtb_endpoint.result.requester_managed == False - - '"service_name" in create_rtb_endpoint.result' - - create_rtb_endpoint.result.service_name == endpoint_service_a - - '"state" in create_endpoint.result' - - create_rtb_endpoint.result.state == "available" - - '"vpc_endpoint_id" in create_rtb_endpoint.result' - - create_rtb_endpoint.result.vpc_endpoint_id.startswith("vpce-") - - '"vpc_endpoint_type" in create_rtb_endpoint.result' - - create_rtb_endpoint.result.vpc_endpoint_type == "Gateway" - - '"vpc_id" in create_rtb_endpoint.result' - - create_rtb_endpoint.result.vpc_id == vpc_id + - create_rtb_endpoint is changed + - '"result" in create_rtb_endpoint' + - '"creation_timestamp" in create_rtb_endpoint.result' + - '"dns_entries" in create_rtb_endpoint.result' + - '"groups" in create_rtb_endpoint.result' + - '"network_interface_ids" in create_rtb_endpoint.result' + - '"owner_id" in create_rtb_endpoint.result' + - '"policy_document" in create_rtb_endpoint.result' + - '"private_dns_enabled" in create_rtb_endpoint.result' + - '"route_table_ids" in create_rtb_endpoint.result' + - create_rtb_endpoint.result.route_table_ids | length == 1 + - create_rtb_endpoint.result.route_table_ids[0] == '{{ rtb_empty_id }}' + - create_rtb_endpoint.result.private_dns_enabled == False + - '"requester_managed" in create_rtb_endpoint.result' + - create_rtb_endpoint.result.requester_managed == False + - '"service_name" in create_rtb_endpoint.result' + - create_rtb_endpoint.result.service_name == endpoint_service_a + - '"state" in create_endpoint.result' + - create_rtb_endpoint.result.state == "available" + - '"vpc_endpoint_id" in create_rtb_endpoint.result' + - create_rtb_endpoint.result.vpc_endpoint_id.startswith("vpce-") + - '"vpc_endpoint_type" in create_rtb_endpoint.result' + - create_rtb_endpoint.result.vpc_endpoint_type == "Gateway" + - '"vpc_id" in create_rtb_endpoint.result' + - create_rtb_endpoint.result.vpc_id == vpc_id - name: Save Endpoint info in a fact set_fact: @@ -417,13 +414,13 @@ vpc_id: '{{ vpc_id }}' service: '{{ endpoint_service_a }}' route_table_ids: - - '{{ rtb_empty_id }}' + - '{{ rtb_empty_id }}' register: create_endpoint_check - check_mode: True + check_mode: true - name: Assert changed assert: that: - - create_endpoint_check is not changed + - create_endpoint_check is not changed - name: Create an endpoint with route table - idempotency ec2_vpc_endpoint: @@ -431,13 +428,13 @@ vpc_id: '{{ vpc_id }}' service: '{{ endpoint_service_a }}' route_table_ids: - - '{{ rtb_empty_id }}' + - '{{ rtb_empty_id }}' register: create_endpoint_check - check_mode: True + check_mode: true - name: Assert changed assert: that: - - create_endpoint_check is not changed + - create_endpoint_check is not changed # # Endpoint modifications are not yet supported by the module # # A Change the route table for the endpoint @@ -509,69 +506,70 @@ ec2_vpc_endpoint: state: present vpc_id: '{{ vpc_id }}' - vpc_endpoint_id: "{{ rtb_endpoint_id }}" + vpc_endpoint_id: '{{ rtb_endpoint_id }}' service: '{{ endpoint_service_a }}' route_table_ids: - - '{{ rtb_empty_id }}' + - '{{ rtb_empty_id }}' tags: - camelCase: "helloWorld" - PascalCase: "HelloWorld" - snake_case: "hello_world" - "Title Case": "Hello World" - "lowercase spaced": "hello world" + camelCase: helloWorld + PascalCase: HelloWorld + snake_case: hello_world + Title Case: Hello World + lowercase spaced: hello world check_mode: true register: check_tag_vpc_endpoint - name: Assert tags would have changed assert: that: - - check_tag_vpc_endpoint.changed + - check_tag_vpc_endpoint.changed - name: Tag the endpoint ec2_vpc_endpoint: state: present vpc_id: '{{ vpc_id }}' - vpc_endpoint_id: "{{ rtb_endpoint_id }}" + vpc_endpoint_id: '{{ rtb_endpoint_id }}' service: '{{ endpoint_service_a }}' route_table_ids: - - '{{ rtb_igw_id }}' + - '{{ rtb_igw_id }}' tags: testPrefix: '{{ resource_prefix }}' - camelCase: "helloWorld" - PascalCase: "HelloWorld" - snake_case: "hello_world" - "Title Case": "Hello World" - "lowercase spaced": "hello world" + camelCase: helloWorld + PascalCase: HelloWorld + snake_case: hello_world + Title Case: Hello World + lowercase spaced: hello world register: tag_vpc_endpoint - name: Assert tags are successful assert: that: - - tag_vpc_endpoint.changed - - tag_vpc_endpoint.result.tags | length == 6 - - endpoint_tags["testPrefix"] == resource_prefix - - endpoint_tags["camelCase"] == "helloWorld" - - endpoint_tags["PascalCase"] == "HelloWorld" - - endpoint_tags["snake_case"] == "hello_world" - - endpoint_tags["Title Case"] == "Hello World" - - endpoint_tags["lowercase spaced"] == "hello world" + - tag_vpc_endpoint.changed + - tag_vpc_endpoint.result.tags | length == 6 + - endpoint_tags["testPrefix"] == resource_prefix + - endpoint_tags["camelCase"] == "helloWorld" + - endpoint_tags["PascalCase"] == "HelloWorld" + - endpoint_tags["snake_case"] == "hello_world" + - endpoint_tags["Title Case"] == "Hello World" + - endpoint_tags["lowercase spaced"] == "hello world" vars: - endpoint_tags: "{{ tag_vpc_endpoint.result.tags | items2dict(key_name='Key', value_name='Value') }}" + endpoint_tags: "{{ tag_vpc_endpoint.result.tags | items2dict(key_name='Key',\ + \ value_name='Value') }}" - name: Query by tag ec2_vpc_endpoint_info: query: endpoints filters: - "tag:testPrefix": - - "{{ resource_prefix }}" + tag:testPrefix: + - '{{ resource_prefix }}' register: tag_result - name: Assert tag lookup found endpoint assert: that: - - tag_result is successful - - '"vpc_endpoints" in tag_result' - - first_endpoint.vpc_endpoint_id == rtb_endpoint_id + - tag_result is successful + - '"vpc_endpoints" in tag_result' + - first_endpoint.vpc_endpoint_id == rtb_endpoint_id vars: first_endpoint: '{{ tag_result.vpc_endpoints[0] }}' @@ -579,159 +577,161 @@ ec2_vpc_endpoint: state: present vpc_id: '{{ vpc_id }}' - vpc_endpoint_id: "{{ rtb_endpoint_id }}" + vpc_endpoint_id: '{{ rtb_endpoint_id }}' service: '{{ endpoint_service_a }}' route_table_ids: - - '{{ rtb_igw_id }}' + - '{{ rtb_igw_id }}' tags: testPrefix: '{{ resource_prefix }}' - camelCase: "helloWorld" - PascalCase: "HelloWorld" - snake_case: "hello_world" - "Title Case": "Hello World" - "lowercase spaced": "hello world" + camelCase: helloWorld + PascalCase: HelloWorld + snake_case: hello_world + Title Case: Hello World + lowercase spaced: hello world register: tag_vpc_endpoint_again - name: Assert tags would not change assert: that: - - not tag_vpc_endpoint_again.changed + - not tag_vpc_endpoint_again.changed - name: Tag the endpoint - idempotency ec2_vpc_endpoint: state: present vpc_id: '{{ vpc_id }}' - vpc_endpoint_id: "{{ rtb_endpoint_id }}" + vpc_endpoint_id: '{{ rtb_endpoint_id }}' service: '{{ endpoint_service_a }}' route_table_ids: - - '{{ rtb_igw_id }}' + - '{{ rtb_igw_id }}' tags: testPrefix: '{{ resource_prefix }}' - camelCase: "helloWorld" - PascalCase: "HelloWorld" - snake_case: "hello_world" - "Title Case": "Hello World" - "lowercase spaced": "hello world" + camelCase: helloWorld + PascalCase: HelloWorld + snake_case: hello_world + Title Case: Hello World + lowercase spaced: hello world register: tag_vpc_endpoint_again - name: Assert tags would not change assert: that: - - not tag_vpc_endpoint_again.changed + - not tag_vpc_endpoint_again.changed - name: Add a tag (check_mode) ec2_vpc_endpoint: state: present vpc_id: '{{ vpc_id }}' - vpc_endpoint_id: "{{ rtb_endpoint_id }}" + vpc_endpoint_id: '{{ rtb_endpoint_id }}' service: '{{ endpoint_service_a }}' route_table_ids: - - '{{ rtb_igw_id }}' + - '{{ rtb_igw_id }}' tags: - new_tag: "ANewTag" + new_tag: ANewTag check_mode: true register: check_tag_vpc_endpoint - name: Assert tags would have changed assert: that: - - check_tag_vpc_endpoint.changed + - check_tag_vpc_endpoint.changed - name: Add a tag (purge_tags=False) ec2_vpc_endpoint: state: present vpc_id: '{{ vpc_id }}' - vpc_endpoint_id: "{{ rtb_endpoint_id }}" + vpc_endpoint_id: '{{ rtb_endpoint_id }}' service: '{{ endpoint_service_a }}' route_table_ids: - - '{{ rtb_igw_id }}' + - '{{ rtb_igw_id }}' tags: - new_tag: "ANewTag" + new_tag: ANewTag register: add_tag_vpc_endpoint - name: Assert tags changed assert: that: - - add_tag_vpc_endpoint.changed - - add_tag_vpc_endpoint.result.tags | length == 7 - - endpoint_tags["testPrefix"] == resource_prefix - - endpoint_tags["camelCase"] == "helloWorld" - - endpoint_tags["PascalCase"] == "HelloWorld" - - endpoint_tags["snake_case"] == "hello_world" - - endpoint_tags["Title Case"] == "Hello World" - - endpoint_tags["lowercase spaced"] == "hello world" - - endpoint_tags["new_tag"] == "ANewTag" + - add_tag_vpc_endpoint.changed + - add_tag_vpc_endpoint.result.tags | length == 7 + - endpoint_tags["testPrefix"] == resource_prefix + - endpoint_tags["camelCase"] == "helloWorld" + - endpoint_tags["PascalCase"] == "HelloWorld" + - endpoint_tags["snake_case"] == "hello_world" + - endpoint_tags["Title Case"] == "Hello World" + - endpoint_tags["lowercase spaced"] == "hello world" + - endpoint_tags["new_tag"] == "ANewTag" vars: - endpoint_tags: "{{ add_tag_vpc_endpoint.result.tags | items2dict(key_name='Key', value_name='Value') }}" + endpoint_tags: "{{ add_tag_vpc_endpoint.result.tags | items2dict(key_name='Key',\ + \ value_name='Value') }}" - name: Add a tag (purge_tags=True) ec2_vpc_endpoint: state: present vpc_id: '{{ vpc_id }}' - vpc_endpoint_id: "{{ rtb_endpoint_id }}" + vpc_endpoint_id: '{{ rtb_endpoint_id }}' service: '{{ endpoint_service_a }}' route_table_ids: - - '{{ rtb_igw_id }}' + - '{{ rtb_igw_id }}' tags: - another_new_tag: "AnotherNewTag" - purge_tags: True + another_new_tag: AnotherNewTag + purge_tags: true register: purge_tag_vpc_endpoint - name: Assert tags changed assert: that: - - purge_tag_vpc_endpoint.changed - - purge_tag_vpc_endpoint.result.tags | length == 1 - - endpoint_tags["another_new_tag"] == "AnotherNewTag" + - purge_tag_vpc_endpoint.changed + - purge_tag_vpc_endpoint.result.tags | length == 1 + - endpoint_tags["another_new_tag"] == "AnotherNewTag" vars: - endpoint_tags: "{{ purge_tag_vpc_endpoint.result.tags | items2dict(key_name='Key', value_name='Value') }}" + endpoint_tags: "{{ purge_tag_vpc_endpoint.result.tags | items2dict(key_name='Key',\ + \ value_name='Value') }}" - name: Delete minimal route table (no routes) ec2_vpc_route_table: state: absent lookup: id - route_table_id: "{{ rtb_empty_id }}" + route_table_id: '{{ rtb_empty_id }}' register: rtb_delete - assert: that: - - rtb_delete is changed + - rtb_delete is changed - name: Delete minimal route table (IGW route) ec2_vpc_route_table: state: absent lookup: id - route_table_id: "{{ rtb_igw_id }}" + route_table_id: '{{ rtb_igw_id }}' - assert: that: - - rtb_delete is changed + - rtb_delete is changed - name: Delete route table endpoint by ID ec2_vpc_endpoint: state: absent - vpc_endpoint_id: "{{ rtb_endpoint_id }}" + vpc_endpoint_id: '{{ rtb_endpoint_id }}' register: endpoint_delete_check - assert: that: - - endpoint_delete_check is changed + - endpoint_delete_check is changed - name: Delete minimal endpoint by ID - idempotency (check_mode) ec2_vpc_endpoint: state: absent - vpc_endpoint_id: "{{ rtb_endpoint_id }}" + vpc_endpoint_id: '{{ rtb_endpoint_id }}' check_mode: true register: endpoint_delete_check - assert: that: - - endpoint_delete_check is not changed + - endpoint_delete_check is not changed - name: Delete endpoint by ID - idempotency ec2_vpc_endpoint: state: absent - vpc_endpoint_id: "{{ endpoint_id }}" + vpc_endpoint_id: '{{ endpoint_id }}' register: endpoint_delete_check - assert: that: - - endpoint_delete_check is not changed + - endpoint_delete_check is not changed - name: Create interface endpoint ec2_vpc_endpoint: @@ -743,16 +743,16 @@ - name: Check that the interface endpoint was created properly assert: that: - - create_interface_endpoint is changed - - create_interface_endpoint.result.vpc_endpoint_type == "Interface" + - create_interface_endpoint is changed + - create_interface_endpoint.result.vpc_endpoint_type == "Interface" - name: Delete interface endpoint ec2_vpc_endpoint: state: absent - vpc_endpoint_id: "{{ create_interface_endpoint.result.vpc_endpoint_id }}" + vpc_endpoint_id: '{{ create_interface_endpoint.result.vpc_endpoint_id }}' register: interface_endpoint_delete_check - assert: that: - - interface_endpoint_delete_check is changed + - interface_endpoint_delete_check is changed # ============================================================ # BEGIN POST-TEST CLEANUP @@ -763,34 +763,34 @@ ec2_vpc_route_table: state: absent lookup: id - route_table_id: "{{ rtb_creation_empty.route_table.id }}" - ignore_errors: True + route_table_id: '{{ rtb_creation_empty.route_table.id }}' + ignore_errors: true - name: Delete minimal route table (IGW route) ec2_vpc_route_table: state: absent lookup: id - route_table_id: "{{ rtb_creation_igw.route_table.id }}" - ignore_errors: True + route_table_id: '{{ rtb_creation_igw.route_table.id }}' + ignore_errors: true - name: Delete endpoint ec2_vpc_endpoint: state: absent - vpc_endpoint_id: "{{ create_endpoint.result.vpc_endpoint_id }}" - ignore_errors: True + vpc_endpoint_id: '{{ create_endpoint.result.vpc_endpoint_id }}' + ignore_errors: true - name: Delete endpoint ec2_vpc_endpoint: state: absent - vpc_endpoint_id: "{{ create_rtb_endpoint.result.vpc_endpoint_id }}" - ignore_errors: True + vpc_endpoint_id: '{{ create_rtb_endpoint.result.vpc_endpoint_id }}' + ignore_errors: true - name: Query any remain endpoints we created (idempotency work is ongoing) # FIXME ec2_vpc_endpoint_info: query: endpoints filters: vpc-id: - - '{{ vpc_id }}' + - '{{ vpc_id }}' register: test_endpoints - name: Delete all endpoints @@ -798,12 +798,12 @@ state: absent vpc_endpoint_id: '{{ item.vpc_endpoint_id }}' with_items: '{{ test_endpoints.vpc_endpoints }}' - ignore_errors: True + ignore_errors: true - name: Remove IGW ec2_vpc_igw: state: absent - vpc_id: "{{ vpc_id }}" + vpc_id: '{{ vpc_id }}' register: igw_deletion retries: 10 delay: 5 @@ -813,6 +813,6 @@ - name: Remove VPC ec2_vpc_net: state: absent - name: "{{ vpc_name }}" - cidr_block: "{{ vpc_cidr }}" + name: '{{ vpc_name }}' + cidr_block: '{{ vpc_cidr }}' ignore_errors: true From 22dea44c94d55b6b704ada9a909bbefefd6e82a8 Mon Sep 17 00:00:00 2001 From: Alina Buzachis Date: Thu, 26 Aug 2021 15:23:20 +0200 Subject: [PATCH 35/37] Add changelog fragment --- changelogs/fragments/migrate_ec2_vpc_endpoint.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 changelogs/fragments/migrate_ec2_vpc_endpoint.yml diff --git a/changelogs/fragments/migrate_ec2_vpc_endpoint.yml b/changelogs/fragments/migrate_ec2_vpc_endpoint.yml new file mode 100644 index 00000000000..a1db66a3e9f --- /dev/null +++ b/changelogs/fragments/migrate_ec2_vpc_endpoint.yml @@ -0,0 +1,13 @@ +major_changes: +- ec2_vpc_endpoint_facts - The module has been migrated from the ``community.aws`` + collection. Playbooks using the Fully Qualified Collection Name for this module + should be updated to use ``amazon.aws.ec2_vpc_endpoint_info``. +- ec2_vpc_endpoint - The module has been migrated from the ``community.aws`` collection. + Playbooks using the Fully Qualified Collection Name for this module should be updated + to use ``amazon.aws.ec2_vpc_endpoint``. +- ec2_vpc_endpoint_info - The module has been migrated from the ``community.aws`` + collection. Playbooks using the Fully Qualified Collection Name for this module + should be updated to use ``amazon.aws.ec2_vpc_endpoint_info``. +- ec2_vpc_endpoint_service_info - The module has been migrated from the ``community.aws`` + collection. Playbooks using the Fully Qualified Collection Name for this module + should be updated to use ``amazon.aws.ec2_vpc_endpoint_service_info``. From 743f554f6522a74e68d679a9a56dbede04488d11 Mon Sep 17 00:00:00 2001 From: Alina Buzachis Date: Thu, 26 Aug 2021 15:23:20 +0200 Subject: [PATCH 36/37] Add symlink for facts module --- plugins/modules/ec2_vpc_endpoint_facts.py | 211 +--------------------- 1 file changed, 1 insertion(+), 210 deletions(-) mode change 100755 => 120000 plugins/modules/ec2_vpc_endpoint_facts.py diff --git a/plugins/modules/ec2_vpc_endpoint_facts.py b/plugins/modules/ec2_vpc_endpoint_facts.py deleted file mode 100755 index 49a74b8af46..00000000000 --- a/plugins/modules/ec2_vpc_endpoint_facts.py +++ /dev/null @@ -1,210 +0,0 @@ -#!/usr/bin/python -# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - -from __future__ import absolute_import, division, print_function -__metaclass__ = type - - -DOCUMENTATION = r''' -module: ec2_vpc_endpoint_info -short_description: Retrieves AWS VPC endpoints details using AWS methods. -version_added: 1.0.0 -description: - - Gets various details related to AWS VPC endpoints. - - This module was called C(ec2_vpc_endpoint_facts) before Ansible 2.9. The usage did not change. -options: - query: - description: - - Defaults to C(endpoints). - - Specifies the query action to take. - - I(query=endpoints) returns information about AWS VPC endpoints. - - Retrieving information about services using I(query=services) has been - deprecated in favour of the M(ec2_vpc_endpoint_service_info) module. - - The I(query) option has been deprecated and will be removed after 2022-12-01. - required: False - choices: - - services - - endpoints - type: str - vpc_endpoint_ids: - description: - - The IDs of specific endpoints to retrieve the details of. - type: list - elements: str - filters: - description: - - A dict of filters to apply. Each dict item consists of a filter key and a filter value. - See U(https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeVpcEndpoints.html) - for possible filters. - type: dict -author: Karen Cheng (@Etherdaemon) -extends_documentation_fragment: -- amazon.aws.aws -- amazon.aws.ec2 - -''' - -EXAMPLES = r''' -# Simple example of listing all support AWS services for VPC endpoints -- name: List supported AWS endpoint services - amazon.aws.ec2_vpc_endpoint_info: - query: services - region: ap-southeast-2 - register: supported_endpoint_services - -- name: Get all endpoints in ap-southeast-2 region - amazon.aws.ec2_vpc_endpoint_info: - query: endpoints - region: ap-southeast-2 - register: existing_endpoints - -- name: Get all endpoints with specific filters - amazon.aws.ec2_vpc_endpoint_info: - query: endpoints - region: ap-southeast-2 - filters: - vpc-id: - - vpc-12345678 - - vpc-87654321 - vpc-endpoint-state: - - available - - pending - register: existing_endpoints - -- name: Get details on specific endpoint - amazon.aws.ec2_vpc_endpoint_info: - query: endpoints - region: ap-southeast-2 - vpc_endpoint_ids: - - vpce-12345678 - register: endpoint_details -''' - -RETURN = r''' -service_names: - description: AWS VPC endpoint service names - returned: I(query) is C(services) - type: list - sample: - service_names: - - com.amazonaws.ap-southeast-2.s3 -vpc_endpoints: - description: - - A list of endpoints that match the query. Each endpoint has the keys creation_timestamp, - policy_document, route_table_ids, service_name, state, vpc_endpoint_id, vpc_id. - returned: I(query) is C(endpoints) - type: list - sample: - vpc_endpoints: - - creation_timestamp: "2017-02-16T11:06:48+00:00" - policy_document: > - "{\"Version\":\"2012-10-17\",\"Id\":\"Policy1450910922815\", - \"Statement\":[{\"Sid\":\"Stmt1450910920641\",\"Effect\":\"Allow\", - \"Principal\":\"*\",\"Action\":\"s3:*\",\"Resource\":[\"arn:aws:s3:::*/*\",\"arn:aws:s3:::*\"]}]}" - route_table_ids: - - rtb-abcd1234 - service_name: "com.amazonaws.ap-southeast-2.s3" - state: "available" - vpc_endpoint_id: "vpce-abbad0d0" - vpc_id: "vpc-1111ffff" -''' - -try: - import botocore -except ImportError: - pass # Handled by AnsibleAWSModule - -from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict - -from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule -from ansible_collections.amazon.aws.plugins.module_utils.core import is_boto3_error_code -from ansible_collections.amazon.aws.plugins.module_utils.core import normalize_boto3_result -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ansible_dict_to_boto3_filter_list - - -@AWSRetry.jittered_backoff() -def _describe_endpoints(client, **params): - paginator = client.get_paginator('describe_vpc_endpoints') - return paginator.paginate(**params).build_full_result() - - -@AWSRetry.jittered_backoff() -def _describe_endpoint_services(client, **params): - paginator = client.get_paginator('describe_vpc_endpoint_services') - return paginator.paginate(**params).build_full_result() - - -def get_supported_services(client, module): - try: - services = _describe_endpoint_services(client) - except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e: - module.fail_json_aws(e, msg="Failed to get endpoint servicess") - - results = list(services['ServiceNames']) - return dict(service_names=results) - - -def get_endpoints(client, module): - results = list() - params = dict() - params['Filters'] = ansible_dict_to_boto3_filter_list(module.params.get('filters')) - if module.params.get('vpc_endpoint_ids'): - params['VpcEndpointIds'] = module.params.get('vpc_endpoint_ids') - try: - results = _describe_endpoints(client, **params)['VpcEndpoints'] - results = normalize_boto3_result(results) - except is_boto3_error_code('InvalidVpcEndpointId.NotFound'): - module.exit_json(msg='VpcEndpoint {0} does not exist'.format(module.params.get('vpc_endpoint_ids')), vpc_endpoints=[]) - except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e: # pylint: disable=duplicate-except - module.fail_json_aws(e, msg="Failed to get endpoints") - - return dict(vpc_endpoints=[camel_dict_to_snake_dict(result) for result in results]) - - -def main(): - argument_spec = dict( - query=dict(choices=['services', 'endpoints'], required=False), - filters=dict(default={}, type='dict'), - vpc_endpoint_ids=dict(type='list', elements='str'), - ) - - module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=True) - if module._name == 'ec2_vpc_endpoint_facts': - module.deprecate("The 'ec2_vpc_endpoint_facts' module has been renamed to 'ec2_vpc_endpoint_info'", date='2021-12-01', collection_name='amazon.aws') - - # Validate Requirements - try: - connection = module.client('ec2') - except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: - module.fail_json_aws(e, msg='Failed to connect to AWS') - - query = module.params.get('query') - if query == 'endpoints': - module.deprecate('The query option has been deprecated and' - ' will be removed after 2022-12-01. Searching for' - ' `endpoints` is now the default and after' - ' 2022-12-01 this module will only support fetching' - ' endpoints.', - date='2022-12-01', collection_name='amazon.aws') - elif query == 'services': - module.deprecate('Support for fetching service information with this ' - 'module has been deprecated and will be removed after' - ' 2022-12-01. ' - 'Please use the ec2_vpc_endpoint_service_info module ' - 'instead.', date='2022-12-01', - collection_name='amazon.aws') - else: - query = 'endpoints' - - invocations = { - 'services': get_supported_services, - 'endpoints': get_endpoints, - } - results = invocations[query](connection, module) - - module.exit_json(**results) - - -if __name__ == '__main__': - main() diff --git a/plugins/modules/ec2_vpc_endpoint_facts.py b/plugins/modules/ec2_vpc_endpoint_facts.py new file mode 120000 index 00000000000..d2a144a7b86 --- /dev/null +++ b/plugins/modules/ec2_vpc_endpoint_facts.py @@ -0,0 +1 @@ +ec2_vpc_endpoint_info.py \ No newline at end of file From a6d109deb97be1c84f24c9d7bbd1ff5ee00d3cd0 Mon Sep 17 00:00:00 2001 From: Alina Buzachis Date: Thu, 26 Aug 2021 15:23:20 +0200 Subject: [PATCH 37/37] Update ignore files --- tests/sanity/ignore-2.9.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/sanity/ignore-2.9.txt b/tests/sanity/ignore-2.9.txt index e3a87479510..058072baedc 100644 --- a/tests/sanity/ignore-2.9.txt +++ b/tests/sanity/ignore-2.9.txt @@ -17,3 +17,5 @@ plugins/modules/ec2_vpc_dhcp_option.py pylint:ansible-deprecated-no-version # W plugins/modules/ec2_vpc_dhcp_option_info.py pylint:ansible-deprecated-no-version # We use dates for deprecations, Ansible 2.9 only supports this for compatability plugins/modules/ec2_vpc_net_info.py pylint:ansible-deprecated-no-version # We use dates for deprecations, Ansible 2.9 only supports this for compatability plugins/modules/ec2_vpc_subnet_info.py pylint:ansible-deprecated-no-version # We use dates for deprecations, Ansible 2.9 only supports this for compatability +plugins/modules/ec2_vpc_endpoint.py pylint:ansible-deprecated-no-version +plugins/modules/ec2_vpc_endpoint_info.py pylint:ansible-deprecated-no-version \ No newline at end of file