Skip to content

Commit

Permalink
Update FQDN
Browse files Browse the repository at this point in the history
  • Loading branch information
jillr committed Aug 20, 2021
1 parent 277de28 commit dec7979
Show file tree
Hide file tree
Showing 3 changed files with 192 additions and 9 deletions.
6 changes: 3 additions & 3 deletions plugins/modules/ec2_vpc_igw.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@
# Ensure that the VPC has an Internet Gateway.
# The Internet Gateway ID is can be accessed via {{igw.gateway_id}} for use in setting up NATs etc.
- name: Create Internet gateway
community.aws.ec2_vpc_igw:
amazon.aws.ec2_vpc_igw:
vpc_id: vpc-abcdefgh
state: present
register: igw
- name: Create Internet gateway with tags
community.aws.ec2_vpc_igw:
amazon.aws.ec2_vpc_igw:
vpc_id: vpc-abcdefgh
state: present
tags:
Expand All @@ -64,7 +64,7 @@
register: igw
- name: Delete Internet gateway
community.aws.ec2_vpc_igw:
amazon.aws.ec2_vpc_igw:
state: absent
vpc_id: vpc-abcdefgh
register: vpc_igw_delete
Expand Down
1 change: 0 additions & 1 deletion plugins/modules/ec2_vpc_igw_facts.py

This file was deleted.

184 changes: 184 additions & 0 deletions plugins/modules/ec2_vpc_igw_facts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
#!/usr/bin/python
# Copyright: Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import absolute_import, division, print_function
__metaclass__ = type


DOCUMENTATION = r'''
---
module: ec2_vpc_igw_info
version_added: 1.0.0
short_description: Gather information about internet gateways in AWS
description:
- Gather information about internet gateways in AWS.
- This module was called C(ec2_vpc_igw_facts) before Ansible 2.9. The usage did not change.
author: "Nick Aslanidis (@naslanidis)"
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_DescribeInternetGateways.html) for possible filters.
type: dict
internet_gateway_ids:
description:
- Get details of specific Internet Gateway ID. Provide this value as a list.
type: list
elements: str
convert_tags:
description:
- Convert tags from boto3 format (list of dictionaries) to the standard dictionary format.
- This currently defaults to C(False). The default will be changed to C(True) after 2022-06-22.
type: bool
version_added: 1.3.0
extends_documentation_fragment:
- amazon.aws.aws
- amazon.aws.ec2
'''

EXAMPLES = r'''
# # Note: These examples do not set authentication details, see the AWS Guide for details.
- name: Gather information about all Internet Gateways for an account or profile
amazon.aws.ec2_vpc_igw_info:
region: ap-southeast-2
profile: production
register: igw_info
- name: Gather information about a filtered list of Internet Gateways
amazon.aws.ec2_vpc_igw_info:
region: ap-southeast-2
profile: production
filters:
"tag:Name": "igw-123"
register: igw_info
- name: Gather information about a specific internet gateway by InternetGatewayId
amazon.aws.ec2_vpc_igw_info:
region: ap-southeast-2
profile: production
internet_gateway_ids: igw-c1231234
register: igw_info
'''

RETURN = r'''
changed:
description: True if listing the internet gateways succeeds.
type: bool
returned: always
sample: "false"
internet_gateways:
description: The internet gateways for the account.
returned: always
type: complex
contains:
attachments:
description: Any VPCs attached to the internet gateway
returned: I(state=present)
type: complex
contains:
state:
description: The current state of the attachment
returned: I(state=present)
type: str
sample: available
vpc_id:
description: The ID of the VPC.
returned: I(state=present)
type: str
sample: vpc-02123b67
internet_gateway_id:
description: The ID of the internet gateway
returned: I(state=present)
type: str
sample: igw-2123634d
tags:
description: Any tags assigned to the internet gateway
returned: I(state=present)
type: dict
sample:
tags:
"Ansible": "Test"
'''

try:
import botocore
except ImportError:
pass # Handled by AnsibleAWSModule

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 AWSRetry
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 ansible_dict_to_boto3_filter_list
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import camel_dict_to_snake_dict


def get_internet_gateway_info(internet_gateway, convert_tags):
if convert_tags:
tags = boto3_tag_list_to_ansible_dict(internet_gateway['Tags'])
ignore_list = ["Tags"]
else:
tags = internet_gateway['Tags']
ignore_list = []
internet_gateway_info = {'InternetGatewayId': internet_gateway['InternetGatewayId'],
'Attachments': internet_gateway['Attachments'],
'Tags': tags}

internet_gateway_info = camel_dict_to_snake_dict(internet_gateway_info, ignore_list=ignore_list)
return internet_gateway_info


def list_internet_gateways(connection, module):
params = dict()

params['Filters'] = ansible_dict_to_boto3_filter_list(module.params.get('filters'))
convert_tags = module.params.get('convert_tags')

if module.params.get("internet_gateway_ids"):
params['InternetGatewayIds'] = module.params.get("internet_gateway_ids")

try:
all_internet_gateways = connection.describe_internet_gateways(aws_retry=True, **params)
except is_boto3_error_code('InvalidInternetGatewayID.NotFound'):
module.fail_json('InternetGateway not found')
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: # pylint: disable=duplicate-except
module.fail_json_aws(e, 'Unable to describe internet gateways')

return [get_internet_gateway_info(igw, convert_tags)
for igw in all_internet_gateways['InternetGateways']]


def main():
argument_spec = dict(
filters=dict(type='dict', default=dict()),
internet_gateway_ids=dict(type='list', default=None, elements='str'),
convert_tags=dict(type='bool'),
)

module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=True)
if module._name == 'ec2_vpc_igw_facts':
module.deprecate("The 'ec2_vpc_igw_facts' module has been renamed to 'ec2_vpc_igw_info'", date='2021-12-01', collection_name='amazon.aws')

if module.params.get('convert_tags') is None:
module.deprecate('This module currently returns boto3 style tags by default. '
'This default has been deprecated and the module will return a simple dictionary in future. '
'This behaviour can be controlled through the convert_tags parameter.',
date='2021-12-01', collection_name='amazon.aws')

# Validate Requirements
try:
connection = 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')

# call your function here
results = list_internet_gateways(connection, module)

module.exit_json(internet_gateways=results)


if __name__ == '__main__':
main()
10 changes: 5 additions & 5 deletions plugins/modules/ec2_vpc_igw_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,21 @@
# # Note: These examples do not set authentication details, see the AWS Guide for details.
- name: Gather information about all Internet Gateways for an account or profile
community.aws.ec2_vpc_igw_info:
amazon.aws.ec2_vpc_igw_info:
region: ap-southeast-2
profile: production
register: igw_info
- name: Gather information about a filtered list of Internet Gateways
community.aws.ec2_vpc_igw_info:
amazon.aws.ec2_vpc_igw_info:
region: ap-southeast-2
profile: production
filters:
"tag:Name": "igw-123"
register: igw_info
- name: Gather information about a specific internet gateway by InternetGatewayId
community.aws.ec2_vpc_igw_info:
amazon.aws.ec2_vpc_igw_info:
region: ap-southeast-2
profile: production
internet_gateway_ids: igw-c1231234
Expand Down Expand Up @@ -160,13 +160,13 @@ def main():

module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=True)
if module._name == 'ec2_vpc_igw_facts':
module.deprecate("The 'ec2_vpc_igw_facts' module has been renamed to 'ec2_vpc_igw_info'", date='2021-12-01', collection_name='community.aws')
module.deprecate("The 'ec2_vpc_igw_facts' module has been renamed to 'ec2_vpc_igw_info'", date='2021-12-01', collection_name='amazon.aws')

if module.params.get('convert_tags') is None:
module.deprecate('This module currently returns boto3 style tags by default. '
'This default has been deprecated and the module will return a simple dictionary in future. '
'This behaviour can be controlled through the convert_tags parameter.',
date='2021-12-01', collection_name='community.aws')
date='2021-12-01', collection_name='amazon.aws')

# Validate Requirements
try:
Expand Down

0 comments on commit dec7979

Please sign in to comment.