Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: 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: ec2_transit_gateway_vpc_attachment_info
9 short_description: describes AWS Transit Gateway VPC attachments
10 version_added: 4.0.0
11 version_added_collection: community.aws
12 description:
13 - Describes AWS Transit Gateway VPC Attachments.
14 options:
15 id:
16 description:
17 - The ID of the Transit Gateway Attachment.
18 - Mutually exclusive with O(name) and O(filters).
19 type: str
20 required: false
21 aliases: ["attachment_id"]
22 name:
23 description:
24 - The V(Name) tag of the Transit Gateway attachment.
25 type: str
26 required: false
27 filters:
28 description:
29 - A dictionary of filters to apply. Each dict item consists of a filter key and a filter value.
30 - Setting a V(tag:Name) filter will override the O(name) parameter.
31 type: dict
32 required: false
33 include_deleted:
34 description:
35 - If O(include_deleted=True), then attachments in a deleted state will
36 also be returned.
37 - Setting a V(state) filter will override the O(include_deleted) parameter.
38 type: bool
39 required: false
40 default: false
41 author:
42 - Mark Chappell (@tremble)
43 - Alina Buzachis (@alinabuzachis)
44 extends_documentation_fragment:
45 - amazon.aws.common.modules
46 - amazon.aws.region.modules
47 - amazon.aws.boto3
48 """
49
50 EXAMPLES = r"""
51 - name: Describe a specific Transit Gateway attachment
52 amazon.aws.ec2_transit_gateway_vpc_attachment_info:
53 id: "tgw-attach-0123456789abcdef0"
54
55 - name: Describe all attachments attached to a transit gateway
56 amazon.aws.ec2_transit_gateway_vpc_attachment_info:
57 filters:
58 transit-gateway-id: "tgw-0fedcba9876543210"
59
60 - name: Describe all attachments in an account
61 amazon.aws.ec2_transit_gateway_vpc_attachment_info:
62 """
63
64 RETURN = r"""
65 attachments:
66 description: The attributes of the Transit Gateway attachments.
67 type: list
68 elements: dict
69 returned: success
70 contains:
71 creation_time:
72 description:
73 - An ISO 8601 date time stamp of when the attachment was created.
74 type: str
75 returned: success
76 sample: "2022-03-10T16:40:26+00:00"
77 options:
78 description:
79 - Additional VPC attachment options.
80 type: dict
81 returned: success
82 contains:
83 appliance_mode_support:
84 description:
85 - Indicates whether appliance mode support is enabled.
86 type: str
87 returned: success
88 sample: "enable"
89 dns_support:
90 description:
91 - Indicates whether DNS support is enabled.
92 type: str
93 returned: success
94 sample: "disable"
95 ipv6_support:
96 description:
97 - Indicates whether IPv6 support is disabled.
98 type: str
99 returned: success
100 sample: "disable"
101 security_group_referencing_support:
102 description:
103 - Indicated weather security group referencing support is disabled.
104 type: str
105 returned: success
106 sample: "enable"
107 state:
108 description:
109 - The state of the attachment.
110 type: str
111 returned: success
112 sample: "deleting"
113 subnet_ids:
114 description:
115 - The IDs of the subnets in use by the attachment.
116 type: list
117 elements: str
118 returned: success
119 sample: ["subnet-0123456789abcdef0", "subnet-11111111111111111"]
120 tags:
121 description:
122 - A dictionary representing the resource tags.
123 type: dict
124 returned: success
125 transit_gateway_attachment_id:
126 description:
127 - The ID of the attachment.
128 type: str
129 returned: success
130 sample: "tgw-attach-0c0c5fd0b0f01d1c9"
131 transit_gateway_id:
132 description:
133 - The ID of the transit gateway that the attachment is connected to.
134 type: str
135 returned: success
136 sample: "tgw-0123456789abcdef0"
137 vpc_id:
138 description:
139 - The ID of the VPC that the attachment is connected to.
140 type: str
141 returned: success
142 sample: "vpc-0123456789abcdef0"
143 vpc_owner_id:
144 description:
145 - The ID of the account that the VPC belongs to.
146 type: str
147 returned: success
148 sample: "123456789012"
149 """
150
151 from typing import Any
152 from typing import Dict
153 from typing import List
154
155 from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AnsibleEC2Error
156 from ansible_collections.amazon.aws.plugins.module_utils.ec2 import describe_transit_gateway_vpc_attachments
157 from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
158 from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list
159 from ansible_collections.amazon.aws.plugins.module_utils.transformation import boto3_resource_to_ansible_dict
160 from ansible_collections.amazon.aws.plugins.module_utils.transitgateway import get_states
161
162
163 def main():
164 argument_spec = dict(
165 id=dict(type="str", required=False, aliases=["attachment_id"]),
166 name=dict(type="str", required=False),
167 filters=dict(type="dict", required=False),
168 include_deleted=dict(type="bool", required=False, default=False),
169 )
170
171 mutually_exclusive = [
172 ["id", "name"],
173 ["id", "filters"],
174 ]
175
176 module = AnsibleAWSModule(
177 argument_spec=argument_spec,
178 supports_check_mode=True,
179 mutually_exclusive=mutually_exclusive,
180 )
181
182 name = module.params.get("name")
183 attachment_id = module.params.get("id")
184 opt_filters = module.params.get("filters")
185 include_deleted = module.params.get("include_deleted")
186
187 client = module.client("ec2")
188
189 params: Dict[str, Any] = {}
190 filters: Dict[str, Any] = {}
191 attachments: List[Dict[str, Any]] = []
192
193 if attachment_id:
194 params["TransitGatewayAttachmentIds"] = [attachment_id]
195
196 # Add filter by name if provided
197 if name:
198 filters["tag:Name"] = name
199
200 # Include only active states if "include_deleted" is False
201 if not include_deleted:
202 filters["state"] = get_states()
203
204 # Include any additional filters provided by the user
205 if opt_filters:
206 filters.update(opt_filters)
207
208 if filters:
209 params["Filters"] = ansible_dict_to_boto3_filter_list(filters)
210
211 try:
212 result = describe_transit_gateway_vpc_attachments(client, **params)
213 except AnsibleEC2Error as e:
214 module.fail_json_aws_error(e)
215
216 if result:
217 attachments = [boto3_resource_to_ansible_dict(attachment) for attachment in result]
218
219 module.exit_json(changed=False, attachments=attachments, filters=filters)
220
221
222 if __name__ == "__main__":
223 main()