Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright (c) 2017, 2018 Michael De La Rue
5 # Copyright (c) 2017, 2018 Will Thames
6 # Copyright (c) 2017 Ansible Project
7 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
8
9 DOCUMENTATION = r"""
10 ---
11 module: rds_instance_info
12 version_added: 5.0.0
13 short_description: obtain information about one or more RDS instances
14 description:
15 - Obtain information about one or more RDS instances.
16 - This module was originally added to C(community.aws) in release 1.0.0.
17 options:
18 db_instance_identifier:
19 description:
20 - The RDS instance's unique identifier.
21 required: false
22 aliases:
23 - id
24 type: str
25 filters:
26 description:
27 - A filter that specifies one or more DB instances to describe.
28 See U(https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_DescribeDBInstances.html)
29 type: dict
30 author:
31 - "Will Thames (@willthames)"
32 - "Michael De La Rue (@mikedlr)"
33 extends_documentation_fragment:
34 - amazon.aws.common.modules
35 - amazon.aws.region.modules
36 - amazon.aws.boto3
37 """
38
39 EXAMPLES = r"""
40 - name: Get information about an instance
41 amazon.aws.rds_instance_info:
42 db_instance_identifier: new-database
43 register: new_database_info
44
45 - name: Get all RDS instances
46 amazon.aws.rds_instance_info:
47 """
48
49 RETURN = r"""
50 instances:
51 description: List of RDS instances
52 returned: always
53 type: complex
54 contains:
55 allocated_storage:
56 description: Gigabytes of storage allocated to the database.
57 returned: always
58 type: int
59 sample: 10
60 auto_minor_version_upgrade:
61 description: Whether minor version upgrades happen automatically.
62 returned: always
63 type: bool
64 sample: true
65 availability_zone:
66 description: Availability Zone in which the database resides.
67 returned: always
68 type: str
69 sample: us-west-2b
70 backup_retention_period:
71 description: Days for which backups are retained.
72 returned: always
73 type: int
74 sample: 7
75 ca_certificate_identifier:
76 description: ID for the CA certificate.
77 returned: always
78 type: str
79 sample: rds-ca-2015
80 copy_tags_to_snapshot:
81 description: Whether DB tags should be copied to the snapshot.
82 returned: always
83 type: bool
84 sample: false
85 db_instance_arn:
86 description: ARN of the database instance.
87 returned: always
88 type: str
89 sample: arn:aws:rds:us-west-2:123456789012:db:helloworld-rds
90 db_instance_class:
91 description: Instance class of the database instance.
92 returned: always
93 type: str
94 sample: db.t3.small
95 db_instance_identifier:
96 description: Database instance identifier.
97 returned: always
98 type: str
99 sample: helloworld-rds
100 db_instance_port:
101 description: Port used by the database instance.
102 returned: always
103 type: int
104 sample: 0
105 db_instance_status:
106 description: Status of the database instance.
107 returned: always
108 type: str
109 sample: available
110 db_name:
111 description: Name of the database.
112 returned: always
113 type: str
114 sample: management
115 db_parameter_groups:
116 description: List of database parameter groups.
117 returned: always
118 type: complex
119 contains:
120 db_parameter_group_name:
121 description: Name of the database parameter group.
122 returned: always
123 type: str
124 sample: psql-pg-helloworld
125 parameter_apply_status:
126 description: Whether the parameter group has been applied.
127 returned: always
128 type: str
129 sample: in-sync
130 db_security_groups:
131 description: List of security groups used by the database instance.
132 returned: always
133 type: list
134 sample: []
135 db_subnet_group:
136 description: List of subnet groups.
137 returned: always
138 type: complex
139 contains:
140 db_subnet_group_description:
141 description: Description of the DB subnet group.
142 returned: always
143 type: str
144 sample: My database subnet group
145 db_subnet_group_name:
146 description: Name of the database subnet group.
147 returned: always
148 type: str
149 sample: my-subnet-group
150 subnet_group_status:
151 description: Subnet group status.
152 returned: always
153 type: str
154 sample: Complete
155 subnets:
156 description: List of subnets in the subnet group.
157 returned: always
158 type: complex
159 contains:
160 subnet_availability_zone:
161 description: Availability zone of the subnet.
162 returned: always
163 type: complex
164 contains:
165 name:
166 description: Name of the availability zone.
167 returned: always
168 type: str
169 sample: us-west-2c
170 subnet_identifier:
171 description: Subnet ID.
172 returned: always
173 type: str
174 sample: subnet-abcd1234
175 subnet_status:
176 description: Subnet status.
177 returned: always
178 type: str
179 sample: Active
180 vpc_id:
181 description: VPC id of the subnet group.
182 returned: always
183 type: str
184 sample: vpc-abcd1234
185 dbi_resource_id:
186 description: AWS Region-unique, immutable identifier for the DB instance.
187 returned: always
188 type: str
189 sample: db-AAAAAAAAAAAAAAAAAAAAAAAAAA
190 deletion_protection:
191 description: C(True) if the DB instance has deletion protection enabled, C(False) if not.
192 returned: always
193 type: bool
194 sample: False
195 version_added: 3.3.0
196 version_added_collection: community.aws
197 domain_memberships:
198 description: List of domain memberships.
199 returned: always
200 type: list
201 sample: []
202 endpoint:
203 description: Database endpoint
204 returned: always
205 type: complex
206 contains:
207 address:
208 description: Database endpoint address.
209 returned: always
210 type: str
211 sample: helloworld-rds.ctrqpe3so1sf.us-west-2.rds.amazonaws.com
212 hosted_zone_id:
213 description: Route 53 hosted zone ID.
214 returned: always
215 type: str
216 sample: Z1PABCD0000000
217 port:
218 description: Database endpoint port.
219 returned: always
220 type: int
221 sample: 5432
222 engine:
223 description: Database engine.
224 returned: always
225 type: str
226 sample: postgres
227 engine_version:
228 description: Database engine version.
229 returned: always
230 type: str
231 sample: 9.5.10
232 iam_database_authentication_enabled:
233 description: Whether database authentication through IAM is enabled.
234 returned: always
235 type: bool
236 sample: false
237 instance_create_time:
238 description: Date and time the instance was created.
239 returned: always
240 type: str
241 sample: '2017-10-10T04:00:07.434000+00:00'
242 iops:
243 description: The Provisioned IOPS value for the DB instance.
244 returned: always
245 type: int
246 sample: 1000
247 kms_key_id:
248 description: KMS Key ID.
249 returned: always
250 type: str
251 sample: arn:aws:kms:us-west-2:123456789012:key/abcd1234-0000-abcd-1111-0123456789ab
252 latest_restorable_time:
253 description: Latest time to which a database can be restored with point-in-time restore.
254 returned: always
255 type: str
256 sample: '2018-05-17T00:03:56+00:00'
257 license_model:
258 description: License model.
259 returned: always
260 type: str
261 sample: postgresql-license
262 master_username:
263 description: Database master username.
264 returned: always
265 type: str
266 sample: dbadmin
267 monitoring_interval:
268 description: Interval, in seconds, between points when Enhanced Monitoring metrics are collected for the DB instance.
269 returned: always
270 type: int
271 sample: 0
272 multi_az:
273 description: Whether Multi-AZ is on.
274 returned: always
275 type: bool
276 sample: false
277 option_group_memberships:
278 description: List of option groups.
279 returned: always
280 type: complex
281 contains:
282 option_group_name:
283 description: Option group name.
284 returned: always
285 type: str
286 sample: default:postgres-9-5
287 status:
288 description: Status of option group.
289 returned: always
290 type: str
291 sample: in-sync
292 pending_modified_values:
293 description: Modified values pending application.
294 returned: always
295 type: complex
296 contains: {}
297 performance_insights_enabled:
298 description: Whether performance insights are enabled.
299 returned: always
300 type: bool
301 sample: false
302 preferred_backup_window:
303 description: Preferred backup window.
304 returned: always
305 type: str
306 sample: 04:00-05:00
307 preferred_maintenance_window:
308 description: Preferred maintenance window.
309 returned: always
310 type: str
311 sample: mon:05:00-mon:05:30
312 publicly_accessible:
313 description: Whether the DB is publicly accessible.
314 returned: always
315 type: bool
316 sample: false
317 read_replica_db_instance_identifiers:
318 description: List of database instance read replicas.
319 returned: always
320 type: list
321 sample: []
322 storage_encrypted:
323 description: Whether the storage is encrypted.
324 returned: always
325 type: bool
326 sample: true
327 storage_type:
328 description: Storage type of the Database instance.
329 returned: always
330 type: str
331 sample: gp2
332 tags:
333 description: Tags used by the database instance.
334 returned: always
335 type: complex
336 contains: {}
337 vpc_security_groups:
338 description: List of VPC security groups.
339 returned: always
340 type: complex
341 contains:
342 status:
343 description: Status of the VPC security group.
344 returned: always
345 type: str
346 sample: active
347 vpc_security_group_id:
348 description: VPC Security Group ID.
349 returned: always
350 type: str
351 sample: sg-abcd1234
352 """
353
354 from typing import Any
355 from typing import Dict
356 from typing import List
357 from typing import Optional
358 from typing import Union
359
360 from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict
361
362 from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
363 from ansible_collections.amazon.aws.plugins.module_utils.rds import AnsibleRDSError
364 from ansible_collections.amazon.aws.plugins.module_utils.rds import describe_db_instances
365 from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_list_to_ansible_dict
366 from ansible_collections.amazon.aws.plugins.module_utils.transformation import ansible_dict_to_boto3_filter_list
367
368
369 def instance_info(
370 client, module: AnsibleAWSModule, instance_name: Optional[str], filters: Optional[Dict[str, Union[str, List]]]
371 ) -> List[Dict[str, Any]]:
372 """
373 Returns attributes of db instance(s), with instances optionally filtered by provided name and additional filters.
374
375 Parameters:
376 client: boto3 rds client
377 module: AnsibleAWSModule
378 instance_name (str, optional): Unique identifier of db instance to describe
379 filters (dict, optional): Additional boto3-supported filters specifying db instance(s) to describe
380
381 Returns:
382 instances (list): List of instance attribute dicts converted from CamelCase to snake_case format
383 """
384 params = {}
385 if instance_name:
386 params["DBInstanceIdentifier"] = instance_name
387 if filters:
388 params["Filters"] = ansible_dict_to_boto3_filter_list(filters)
389
390 results = describe_db_instances(client, **params)
391 for instance in results:
392 instance["Tags"] = boto3_tag_list_to_ansible_dict(instance.pop("TagList"))
393
394 return [camel_dict_to_snake_dict(instance, ignore_list=["Tags"]) for instance in results]
395
396
397 def main():
398 argument_spec = dict(
399 db_instance_identifier=dict(aliases=["id"]),
400 filters=dict(type="dict"),
401 )
402
403 module = AnsibleAWSModule(
404 argument_spec=argument_spec,
405 supports_check_mode=True,
406 )
407
408 client = module.client("rds")
409
410 instance_name = module.params.get("db_instance_identifier")
411 filters = module.params.get("filters")
412
413 try:
414 module.exit_json(changed=False, instances=instance_info(client, module, instance_name, filters))
415 except AnsibleRDSError as e:
416 module.fail_json_aws(e)
417
418
419 if __name__ == "__main__":
420 main()