Debian Codegraph @

ansible_collections/amazon/aws/plugins/modules/aws_region_info.py

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright (c) 2017 Ansible Project
5 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 DOCUMENTATION = r"""
8 module: aws_region_info
9 short_description: Gather information about AWS regions
10 version_added: 1.0.0
11 version_added_collection: community.aws
12 description:
13 - Gather information about AWS regions.
14 author:
15 - 'Henrique Rodrigues (@Sodki)'
16 options:
17 filters:
18 description:
19 - A dict of filters to apply.
20 - Each dict item consists of a filter key and a filter value.
21 - See U(https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeRegions.html) for possible filters.
22 - Filter names and values are case sensitive.
23 - You can use underscores instead of dashes (-) in the filter keys.
24 - Filter keys with underscores will take precedence in case of conflict.
25 default: {}
26 type: dict
27 extends_documentation_fragment:
28 - amazon.aws.common.modules
29 - amazon.aws.region.modules
30 - amazon.aws.boto3
31 """
32
33 EXAMPLES = r"""
34 # Note: These examples do not set authentication details, see the AWS Guide for details.
35
36 # Gather information about all regions
37 - amazon.aws.aws_region_info:
38
39 # Gather information about a single region
40 - amazon.aws.aws_region_info:
41 filters:
42 region-name: eu-west-1
43 """
44
45 RETURN = r"""
46 regions:
47 returned: on success
48 description:
49 - Information about the regions that match the provided filters. Retruns information about all the regions if no filters specified.
50 - Each element consists of a dict with all the information related to that region.
51 type: list
52 elements: dict
53 sample: "[{
54 'endpoint': 'ec2.us-west-1.amazonaws.com',
55 'region_name': 'us-west-1'
56 }]"
57 contains:
58 endpoint:
59 description: The Region service endpoint.
60 type: str
61 sample: "ec2.us-east-2.amazonaws.com"
62 opt_in_status:
63 description: The Region opt-in status.
64 type: str
65 sample: "opt-in-not-required"
66 region_name:
67 description: The name of the Region.
68 type: str
69 sample: "us-east-2"
70 """
71
72 try:
73 from botocore.exceptions import BotoCoreError
74 from botocore.exceptions import ClientError
75 except ImportError:
76 pass # Handled by AnsibleAWSModule
77
78 from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict
79
80 from ansible_collections.amazon.aws.plugins.module_utils.ec2 import describe_regions
81 from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
82 from ansible_collections.amazon.aws.plugins.module_utils.transformation import sanitize_filters_to_boto3_filter_list
83
84
85 def main():
86 argument_spec = dict(
87 filters=dict(default={}, type="dict"),
88 )
89
90 module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=True)
91
92 connection = module.client("ec2")
93
94 # Sanitize filters
95 sanitized_filters = sanitize_filters_to_boto3_filter_list(module.params.get("filters"))
96 try:
97 regions = describe_regions(connection, Filters=sanitized_filters)
98 except (BotoCoreError, ClientError) as e:
99 module.fail_json_aws(e, msg="Unable to describe regions.")
100
101 module.exit_json(regions=[camel_dict_to_snake_dict(r) for r in regions])
102
103
104 if __name__ == "__main__":
105 main()