Skip to content

Commit

Permalink
Merge branch 'main' into patch-7
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditya Putta authored Oct 12, 2023
2 parents d6dcd63 + d7fae9d commit f12a6c6
Show file tree
Hide file tree
Showing 38 changed files with 3,166 additions and 1 deletion.
5 changes: 5 additions & 0 deletions changelogs/fragments/migrate_aws_region_info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
major_changes:
- aws_region_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.aws_region_info``.
7 changes: 7 additions & 0 deletions changelogs/fragments/migrate_iam_access_key.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
major_changes:
- iam_access_key - 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.iam_access_key``.
- iam_access_key_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.iam_access_key_info``.
4 changes: 4 additions & 0 deletions changelogs/fragments/migrate_iam_mfa_device_info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
major_changes:
- iam_mfa_device_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.iam_mfa_device_info`` (https://github.com/ansible-collections/amazon.aws/pull/1761).
4 changes: 4 additions & 0 deletions changelogs/fragments/migrate_iam_password_policy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
major_changes:
- iam_password_policy - 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.iam_password_policy``.
8 changes: 8 additions & 0 deletions changelogs/fragments/migrate_s3_bucket_info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
major_changes:
- aws_s3_bucket_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.aws_s3_bucket_info``.
- s3_bucket_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.s3_bucket_info``.
4 changes: 4 additions & 0 deletions changelogs/fragments/migrate_sts_assume_role.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
major_changes:
- sts_assume_role - 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.sts_assume_role``.
11 changes: 11 additions & 0 deletions meta/runtime.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ action_groups:
- autoscaling_group_info
- aws_az_info
- aws_caller_info
- aws_region_info
- aws_s3
- aws_s3_bucket_info
- backup_plan
- backup_plan_info
- backup_selection
Expand Down Expand Up @@ -68,10 +70,14 @@ action_groups:
- elb_application_lb_info
- elb_classic_lb
- execute_lambda
- iam_access_key
- iam_access_key_info
- iam_group
- iam_instance_profile
- iam_instance_profile_info
- iam_managed_policy
- iam_mfa_device_info
- iam_password_policy
- iam_policy
- iam_policy_info
- iam_role
Expand Down Expand Up @@ -104,8 +110,10 @@ action_groups:
- route53_info
- route53_zone
- s3_bucket
- s3_bucket_info
- s3_object
- s3_object_info
- sts_assume_role
plugin_routing:
action:
aws_s3:
Expand All @@ -120,6 +128,9 @@ plugin_routing:
aws_s3:
# Deprecation for this alias should not *start* prior to 2024-09-01
redirect: amazon.aws.s3_object
aws_s3_bucket_info:
# Deprecation for this alias should not *start* prior to 2024-09-01
redirect: amazon.aws.s3_bucket_info
ec2_asg:
# Deprecation for this alias should not *start* prior to 2024-09-01
redirect: amazon.aws.autoscaling_group
Expand Down
6 changes: 6 additions & 0 deletions plugins/modules/aws_az_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
amazon.aws.aws_az_info:
filters:
zone-name: eu-west-1a
- name: Gather information in a availability zones based on their state, such as "available"
amazon.aws.aws_az_info:
region: us-east-1
filters:
state: available
"""

RETURN = r"""
Expand Down
98 changes: 98 additions & 0 deletions plugins/modules/aws_region_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# Copyright (c) 2017 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

DOCUMENTATION = r"""
module: aws_region_info
short_description: Gather information about AWS regions
version_added: 1.0.0
version_added_collection: community.aws
description:
- Gather information about AWS regions.
author:
- 'Henrique Rodrigues (@Sodki)'
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_DescribeRegions.html) for possible filters.
- Filter names and values are case sensitive.
- You can use underscores instead of dashes (-) in the filter keys.
- Filter keys with underscores will take precedence in case of conflict.
default: {}
type: dict
extends_documentation_fragment:
- amazon.aws.common.modules
- amazon.aws.region.modules
- amazon.aws.boto3
"""

EXAMPLES = r"""
# Note: These examples do not set authentication details, see the AWS Guide for details.
# Gather information about all regions
- amazon.aws.aws_region_info:
# Gather information about a single region
- amazon.aws.aws_region_info:
filters:
region-name: eu-west-1
"""

RETURN = r"""
regions:
returned: on success
description: >
Regions that match the provided filters. Each element consists of a dict with all the information related
to that region.
type: list
sample: "[{
'endpoint': 'ec2.us-west-1.amazonaws.com',
'region_name': 'us-west-1'
}]"
"""

try:
from botocore.exceptions import BotoCoreError
from botocore.exceptions import ClientError
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.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list


def main():
argument_spec = dict(
filters=dict(default={}, type="dict"),
)

module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=True)

connection = module.client("ec2", retry_decorator=AWSRetry.jittered_backoff())

# Replace filter key underscores with dashes, for compatibility
sanitized_filters = dict(module.params.get("filters"))
for k in module.params.get("filters").keys():
if "_" in k:
sanitized_filters[k.replace("_", "-")] = sanitized_filters[k]
del sanitized_filters[k]

try:
regions = connection.describe_regions(
aws_retry=True, Filters=ansible_dict_to_boto3_filter_list(sanitized_filters)
)
except (BotoCoreError, ClientError) as e:
module.fail_json_aws(e, msg="Unable to describe regions.")

module.exit_json(regions=[camel_dict_to_snake_dict(r) for r in regions["Regions"]])


if __name__ == "__main__":
main()
Loading

0 comments on commit f12a6c6

Please sign in to comment.