Debian Codegraph @

ansible_collections/community/aws/plugins/modules/networkfirewall_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: networkfirewall_info
9 short_description: describe AWS Network Firewall firewalls
10 version_added: 4.0.0
11 description:
12 - A module for describing AWS Network Firewall firewalls.
13 options:
14 arn:
15 description:
16 - The ARN of the Network Firewall.
17 - Mutually exclusive with I(name) and I(vpc_ids).
18 required: false
19 type: str
20 name:
21 description:
22 - The name of the Network Firewall.
23 - Mutually exclusive with I(arn) and I(vpc_ids).
24 required: false
25 type: str
26 vpc_ids:
27 description:
28 - A List of VPCs to retrieve the firewalls for.
29 - Mutually exclusive with I(name) and I(arn).
30 required: false
31 type: list
32 elements: str
33 aliases: ['vpcs', 'vpc_id']
34
35 author:
36 - Mark Chappell (@tremble)
37 extends_documentation_fragment:
38 - amazon.aws.common.modules
39 - amazon.aws.region.modules
40 - amazon.aws.boto3
41 """
42
43 EXAMPLES = r"""
44
45 # Describe all firewalls in an account
46 - community.aws.networkfirewall_info: {}
47
48 # Describe a firewall by ARN
49 - community.aws.networkfirewall_info:
50 arn: arn:aws:network-firewall:us-east-1:123456789012:firewall/ExampleFirewall
51
52 # Describe a firewall by name
53 - community.aws.networkfirewall_info:
54 name: ExampleFirewall
55 """
56
57 RETURN = r"""
58 firewall_list:
59 description: A list of ARNs of the matching firewalls.
60 type: list
61 elements: str
62 returned: When a firewall name isn't specified
63 example: ['arn:aws:network-firewall:us-east-1:123456789012:firewall/Example1',
64 'arn:aws:network-firewall:us-east-1:123456789012:firewall/Example2']
65
66 firewalls:
67 description: The details of the firewalls
68 returned: success
69 type: list
70 elements: dict
71 contains:
72 firewall:
73 description: The details of the firewall
74 type: dict
75 returned: success
76 contains:
77 delete_protection:
78 description: A flag indicating whether it is possible to delete the firewall.
79 type: str
80 returned: success
81 example: true
82 description:
83 description: A description of the firewall.
84 type: str
85 returned: success
86 example: "Description"
87 firewall_arn:
88 description: The ARN of the firewall.
89 type: str
90 returned: success
91 example: "arn:aws:network-firewall:us-east-1:123456789012:firewall/ExampleFirewall"
92 firewall_id:
93 description: A unique ID for the firewall.
94 type: str
95 returned: success
96 example: "12345678-abcd-1234-abcd-123456789abc"
97 firewall_name:
98 description: The name of the firewall.
99 type: str
100 returned: success
101 example: "ExampleFirewall"
102 firewall_policy_arn:
103 description: The ARN of the firewall policy used by the firewall.
104 type: str
105 returned: success
106 example: "arn:aws:network-firewall:us-east-1:123456789012:firewall-policy/ExamplePolicy"
107 firewall_policy_change_protection:
108 description:
109 - A flag indicating whether it is possible to change which firewall
110 policy is used by the firewall.
111 type: bool
112 returned: success
113 example: false
114 subnet_change_protection:
115 description:
116 - A flag indicating whether it is possible to change which subnets
117 the firewall endpoints are in.
118 type: bool
119 returned: success
120 example: true
121 subnet_mappings:
122 description: A list of the subnets the firewall endpoints are in.
123 type: list
124 elements: dict
125 contains:
126 subnet_id:
127 description: The ID of the subnet.
128 type: str
129 returned: success
130 example: "subnet-12345678"
131 tags:
132 description: The tags associated with the firewall.
133 type: dict
134 returned: success
135 example: '{"SomeTag": "SomeValue"}'
136 vpc_id:
137 description: The ID of the VPC that the firewall is used by.
138 type: str
139 returned: success
140 example: "vpc-0123456789abcdef0"
141 firewall_metadata:
142 description: Metadata about the firewall
143 type: dict
144 returned: success
145 contains:
146 configuration_sync_state_summary:
147 description:
148 - A short summary of the synchronization status of the
149 policy and rule groups.
150 type: str
151 returned: success
152 example: "IN_SYNC"
153 status:
154 description:
155 - A short summary of the status of the firewall endpoints.
156 type: str
157 returned: success
158 example: "READY"
159 sync_states:
160 description:
161 - A description, broken down by availability zone, of the status
162 of the firewall endpoints as well as the synchronization status
163 of the policies and rule groups.
164 type: dict
165 returned: success
166 example:
167 {
168 "us-east-1a": {
169 "attachment": {
170 "endpoint_id": "vpce-123456789abcdef01",
171 "status": "READY",
172 "subnet_id": "subnet-12345678"
173 },
174 "config": {
175 "arn:aws:network-firewall:us-east-1:123456789012:firewall-policy/Ansible-Example": {
176 "sync_status": "IN_SYNC",
177 "update_token": "abcdef01-0000-0000-0000-123456789abc"
178 },
179 "arn:aws:network-firewall:us-east-1:123456789012:stateful-rulegroup/ExampleDomainList": {
180 "sync_status": "IN_SYNC",
181 "update_token": "12345678-0000-0000-0000-abcdef012345"
182 }
183 }
184 }
185 }
186 """
187
188 from ansible_collections.community.aws.plugins.module_utils.modules import AnsibleCommunityAWSModule as AnsibleAWSModule
189 from ansible_collections.community.aws.plugins.module_utils.networkfirewall import NetworkFirewallManager
190
191
192 def main():
193 argument_spec = dict(
194 name=dict(type="str", required=False),
195 arn=dict(type="str", required=False),
196 vpc_ids=dict(type="list", required=False, elements="str", aliases=["vpcs", "vpc_id"]),
197 )
198
199 module = AnsibleAWSModule(
200 argument_spec=argument_spec,
201 supports_check_mode=True,
202 mutually_exclusive=[
203 ["arn", "name", "vpc_ids"],
204 ],
205 )
206
207 arn = module.params.get("arn")
208 name = module.params.get("name")
209 vpcs = module.params.get("vpc_ids")
210
211 manager = NetworkFirewallManager(module)
212
213 results = dict(changed=False)
214
215 if name or arn:
216 firewall = manager.get_firewall(name=name, arn=arn)
217 if firewall:
218 results["firewalls"] = [firewall]
219 else:
220 results["firewalls"] = []
221 else:
222 if vpcs:
223 firewall_list = manager.list(vpc_ids=vpcs)
224 else:
225 firewall_list = manager.list()
226 results["firewall_list"] = firewall_list
227 firewalls = [manager.get_firewall(arn=f) for f in firewall_list]
228 results["firewalls"] = firewalls
229
230 module.exit_json(**results)
231
232
233 if __name__ == "__main__":
234 main()