| 1 |
#!/usr/bin/python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
|
| 4 |
# Copyright (c) 2024 Aubin Bikouo (@abikouo) |
| 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: rds_engine_versions_info |
| 9 |
version_added: 7.6.0 |
| 10 |
short_description: Describes the properties of specific versions of DB engines |
| 11 |
description: |
| 12 |
- Obtain information about a specific versions of DB engines. |
| 13 |
options: |
| 14 |
engine: |
| 15 |
description: |
| 16 |
- The database engine to return version details for. |
| 17 |
type: str |
| 18 |
choices: |
| 19 |
- aurora-mysql |
| 20 |
- aurora-postgresql |
| 21 |
- custom-oracle-ee |
| 22 |
- db2-ae |
| 23 |
- db2-se |
| 24 |
- mariadb |
| 25 |
- mysql |
| 26 |
- oracle-ee |
| 27 |
- oracle-ee-cdb |
| 28 |
- oracle-se2 |
| 29 |
- oracle-se2-cdb |
| 30 |
- postgres |
| 31 |
- sqlserver-ee |
| 32 |
- sqlserver-se |
| 33 |
- sqlserver-ex |
| 34 |
- sqlserver-web |
| 35 |
engine_version: |
| 36 |
description: |
| 37 |
- A specific database engine version to return details for. |
| 38 |
type: str |
| 39 |
db_parameter_group_family: |
| 40 |
description: |
| 41 |
- The name of a specific RDS parameter group family to return details for. |
| 42 |
type: str |
| 43 |
default_only: |
| 44 |
description: |
| 45 |
- Specifies whether to return only the default version of the specified engine |
| 46 |
or the engine and major version combination. |
| 47 |
type: bool |
| 48 |
default: false |
| 49 |
filters: |
| 50 |
description: |
| 51 |
- A filter that specifies one or more DB engine versions to describe. |
| 52 |
See U(https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_DescribeDBEngineVersions.html). |
| 53 |
type: dict |
| 54 |
author: |
| 55 |
- Aubin Bikouo (@abikouo) |
| 56 |
extends_documentation_fragment: |
| 57 |
- amazon.aws.common.modules |
| 58 |
- amazon.aws.region.modules |
| 59 |
- amazon.aws.boto3 |
| 60 |
""" |
| 61 |
|
| 62 |
EXAMPLES = r""" |
| 63 |
- name: List all of the available parameter group families for the Aurora PostgreSQL DB engine |
| 64 |
amazon.aws.rds_engine_versions_info: |
| 65 |
engine: aurora-postgresql |
| 66 |
|
| 67 |
- name: List all of the available parameter group families for the Aurora PostgreSQL DB engine on a specific version |
| 68 |
amazon.aws.rds_engine_versions_info: |
| 69 |
engine: aurora-postgresql |
| 70 |
engine_version: 16.1 |
| 71 |
|
| 72 |
- name: Get default engine version for DB parameter group family postgres16 |
| 73 |
amazon.aws.rds_engine_versions_info: |
| 74 |
engine: postgres |
| 75 |
default_only: true |
| 76 |
db_parameter_group_family: postgres16 |
| 77 |
""" |
| 78 |
|
| 79 |
RETURN = r""" |
| 80 |
db_engine_versions: |
| 81 |
description: List of RDS engine versions. |
| 82 |
returned: always |
| 83 |
type: list |
| 84 |
contains: |
| 85 |
engine: |
| 86 |
description: |
| 87 |
- The name of the database engine. |
| 88 |
type: str |
| 89 |
engine_version: |
| 90 |
description: |
| 91 |
- The version number of the database engine. |
| 92 |
type: str |
| 93 |
db_parameter_group_family: |
| 94 |
description: |
| 95 |
- The name of the DB parameter group family for the database engine. |
| 96 |
type: str |
| 97 |
db_engine_description: |
| 98 |
description: |
| 99 |
- The description of the database engine. |
| 100 |
type: str |
| 101 |
db_engine_version_description: |
| 102 |
description: |
| 103 |
- The description of the database engine version. |
| 104 |
type: str |
| 105 |
default_character_set: |
| 106 |
description: |
| 107 |
- The default character set for new instances of this engine version. |
| 108 |
type: dict |
| 109 |
sample: { |
| 110 |
"character_set_description": "Unicode 5.0 UTF-8 Universal character set", |
| 111 |
"character_set_name": "AL32UTF8" |
| 112 |
} |
| 113 |
image: |
| 114 |
description: |
| 115 |
- The EC2 image |
| 116 |
type: complex |
| 117 |
contains: |
| 118 |
image_id: |
| 119 |
description: |
| 120 |
- A value that indicates the ID of the AMI. |
| 121 |
type: str |
| 122 |
status: |
| 123 |
description: |
| 124 |
- A value that indicates the status of a custom engine version (CEV). |
| 125 |
type: str |
| 126 |
db_engine_media_type: |
| 127 |
description: |
| 128 |
- A value that indicates the source media provider of the AMI based on the usage operation. |
| 129 |
type: str |
| 130 |
supported_character_sets: |
| 131 |
description: |
| 132 |
- A list of the character sets supported by this engine for the CharacterSetName parameter of the CreateDBInstance operation. |
| 133 |
type: list |
| 134 |
elements: dict |
| 135 |
contains: |
| 136 |
character_set_name: |
| 137 |
description: |
| 138 |
- The name of the character set. |
| 139 |
type: str |
| 140 |
character_set_description: |
| 141 |
description: |
| 142 |
- The description of the character set. |
| 143 |
type: str |
| 144 |
supported_nchar_character_sets: |
| 145 |
description: |
| 146 |
- A list of the character sets supported by the Oracle DB engine. |
| 147 |
type: list |
| 148 |
elements: dict |
| 149 |
contains: |
| 150 |
character_set_name: |
| 151 |
description: |
| 152 |
- The name of the character set. |
| 153 |
type: str |
| 154 |
character_set_description: |
| 155 |
description: |
| 156 |
- The description of the character set. |
| 157 |
type: str |
| 158 |
valid_upgrade_target: |
| 159 |
description: |
| 160 |
- A list of engine versions that this database engine version can be upgraded to. |
| 161 |
type: list |
| 162 |
elements: dict |
| 163 |
sample: [ |
| 164 |
{ |
| 165 |
"auto_upgrade": false, |
| 166 |
"description": "Aurora PostgreSQL (Compatible with PostgreSQL 15.5)", |
| 167 |
"engine": "aurora-postgresql", |
| 168 |
"engine_version": "15.5", |
| 169 |
"is_major_version_upgrade": false, |
| 170 |
"supported_engine_modes": [ |
| 171 |
"provisioned" |
| 172 |
], |
| 173 |
"supports_babelfish": true, |
| 174 |
"supports_global_databases": true, |
| 175 |
"supports_integrations": false, |
| 176 |
"supports_local_write_forwarding": true, |
| 177 |
"supports_parallel_query": false |
| 178 |
} |
| 179 |
] |
| 180 |
supported_timezones: |
| 181 |
description: |
| 182 |
- A list of the time zones supported by this engine for the Timezone parameter of the CreateDBInstance action. |
| 183 |
type: list |
| 184 |
elements: dict |
| 185 |
sample: [ |
| 186 |
{"TimezoneName": "xxx"} |
| 187 |
] |
| 188 |
exportable_log_types: |
| 189 |
description: |
| 190 |
- The types of logs that the database engine has available for export to CloudWatch Logs. |
| 191 |
type: list |
| 192 |
elements: str |
| 193 |
supports_log_exports_to_cloudwatchLogs: |
| 194 |
description: |
| 195 |
- Indicates whether the engine version supports exporting the log types specified by ExportableLogTypes to CloudWatch Logs. |
| 196 |
type: bool |
| 197 |
supports_read_replica: |
| 198 |
description: |
| 199 |
- Indicates whether the database engine version supports read replicas. |
| 200 |
type: bool |
| 201 |
supported_engine_modes: |
| 202 |
description: |
| 203 |
- A list of the supported DB engine modes. |
| 204 |
type: list |
| 205 |
elements: str |
| 206 |
supported_feature_names: |
| 207 |
description: |
| 208 |
- A list of features supported by the DB engine. |
| 209 |
type: list |
| 210 |
elements: str |
| 211 |
sample: [ |
| 212 |
"Comprehend", |
| 213 |
"Lambda", |
| 214 |
"s3Export", |
| 215 |
"s3Import", |
| 216 |
"SageMaker" |
| 217 |
] |
| 218 |
status: |
| 219 |
description: |
| 220 |
- The status of the DB engine version, either available or deprecated. |
| 221 |
type: str |
| 222 |
supports_parallel_query: |
| 223 |
description: |
| 224 |
- Indicates whether you can use Aurora parallel query with a specific DB engine version. |
| 225 |
type: bool |
| 226 |
supports_global_databases: |
| 227 |
description: |
| 228 |
- Indicates whether you can use Aurora global databases with a specific DB engine version. |
| 229 |
type: bool |
| 230 |
major_engine_version: |
| 231 |
description: |
| 232 |
- The major engine version of the CEV. |
| 233 |
type: str |
| 234 |
database_installation_files_s3_bucket_name: |
| 235 |
description: |
| 236 |
- The name of the Amazon S3 bucket that contains your database installation files. |
| 237 |
type: str |
| 238 |
database_installation_files_s3_prefix: |
| 239 |
description: |
| 240 |
- The Amazon S3 directory that contains the database installation files. |
| 241 |
type: str |
| 242 |
db_engine_version_arn: |
| 243 |
description: |
| 244 |
- The ARN of the custom engine version. |
| 245 |
type: str |
| 246 |
kms_key_id: |
| 247 |
description: |
| 248 |
- The Amazon Web Services KMS key identifier for an encrypted CEV. |
| 249 |
type: str |
| 250 |
create_time: |
| 251 |
description: |
| 252 |
- The creation time of the DB engine version. |
| 253 |
type: str |
| 254 |
tags: |
| 255 |
description: A dictionary of key value pairs. |
| 256 |
type: dict |
| 257 |
sample: { |
| 258 |
"some": "tag" |
| 259 |
} |
| 260 |
supports_babelfish: |
| 261 |
description: |
| 262 |
- Indicates whether the engine version supports Babelfish for Aurora PostgreSQL. |
| 263 |
type: bool |
| 264 |
custom_db_engine_version_manifest: |
| 265 |
description: |
| 266 |
- JSON string that lists the installation files and parameters that RDS Custom uses to create a custom engine version (CEV). |
| 267 |
type: str |
| 268 |
supports_certificate_rotation_without_restart: |
| 269 |
description: |
| 270 |
- Indicates whether the engine version supports rotating the server certificate without rebooting the DB instance. |
| 271 |
type: bool |
| 272 |
supported_ca_certificate_identifiers: |
| 273 |
description: |
| 274 |
- A list of the supported CA certificate identifiers. |
| 275 |
type: list |
| 276 |
elements: str |
| 277 |
sample: [ |
| 278 |
"rds-ca-2019", |
| 279 |
"rds-ca-ecc384-g1", |
| 280 |
"rds-ca-rsa4096-g1", |
| 281 |
"rds-ca-rsa2048-g1" |
| 282 |
] |
| 283 |
supports_local_write_forwarding: |
| 284 |
description: |
| 285 |
- Indicates whether the DB engine version supports forwarding write operations from reader DB instances to the writer DB instance in the DB cluster. |
| 286 |
type: bool |
| 287 |
supports_integrations: |
| 288 |
description: |
| 289 |
- Indicates whether the DB engine version supports zero-ETL integrations with Amazon Redshift. |
| 290 |
type: bool |
| 291 |
""" |
| 292 |
|
| 293 |
from typing import Any |
| 294 |
from typing import Dict |
| 295 |
from typing import List |
| 296 |
|
| 297 |
try: |
| 298 |
import botocore |
| 299 |
except ImportError: |
| 300 |
pass # handled by AnsibleAWSModule |
| 301 |
|
| 302 |
from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict |
| 303 |
|
| 304 |
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule |
| 305 |
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry |
| 306 |
from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_list_to_ansible_dict |
| 307 |
|
| 308 |
|
| 309 |
@AWSRetry.jittered_backoff(retries=10) |
| 310 |
def _describe_db_engine_versions(connection: Any, **params: Dict[str, Any]) -> List[Dict[str, Any]]: |
| 311 |
paginator = connection.get_paginator("describe_db_engine_versions") |
| 312 |
return paginator.paginate(**params).build_full_result()["DBEngineVersions"] |
| 313 |
|
| 314 |
|
| 315 |
def describe_db_engine_versions(connection: Any, module: AnsibleAWSModule) -> Dict[str, Any]: |
| 316 |
engine = module.params.get("engine") |
| 317 |
engine_version = module.params.get("engine_version") |
| 318 |
db_parameter_group_family = module.params.get("db_parameter_group_family") |
| 319 |
default_only = module.params.get("default_only") |
| 320 |
filters = module.params.get("filters") |
| 321 |
|
| 322 |
params = {"DefaultOnly": default_only} |
| 323 |
if engine: |
| 324 |
params["Engine"] = engine |
| 325 |
if engine_version: |
| 326 |
params["EngineVersion"] = engine_version |
| 327 |
if db_parameter_group_family: |
| 328 |
params["DBParameterGroupFamily"] = db_parameter_group_family |
| 329 |
if filters: |
| 330 |
params["Filters"] = filters |
| 331 |
|
| 332 |
try: |
| 333 |
result = _describe_db_engine_versions(connection, **params) |
| 334 |
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: |
| 335 |
module.fail_json_aws(e, "Couldn't get RDS engine versions.") |
| 336 |
|
| 337 |
def _transform_item(v): |
| 338 |
tag_list = v.pop("TagList", []) |
| 339 |
v = camel_dict_to_snake_dict(v) |
| 340 |
v["tags"] = boto3_tag_list_to_ansible_dict(tag_list) |
| 341 |
return v |
| 342 |
|
| 343 |
return dict(changed=False, db_engine_versions=[_transform_item(v) for v in result]) |
| 344 |
|
| 345 |
|
| 346 |
def main() -> None: |
| 347 |
argument_spec = dict( |
| 348 |
engine=dict( |
| 349 |
choices=[ |
| 350 |
"aurora-mysql", |
| 351 |
"aurora-postgresql", |
| 352 |
"custom-oracle-ee", |
| 353 |
"db2-ae", |
| 354 |
"db2-se", |
| 355 |
"mariadb", |
| 356 |
"mysql", |
| 357 |
"oracle-ee", |
| 358 |
"oracle-ee-cdb", |
| 359 |
"oracle-se2", |
| 360 |
"oracle-se2-cdb", |
| 361 |
"postgres", |
| 362 |
"sqlserver-ee", |
| 363 |
"sqlserver-se", |
| 364 |
"sqlserver-ex", |
| 365 |
"sqlserver-web", |
| 366 |
] |
| 367 |
), |
| 368 |
engine_version=dict(), |
| 369 |
db_parameter_group_family=dict(), |
| 370 |
default_only=dict(type="bool", default=False), |
| 371 |
filters=dict(type="dict"), |
| 372 |
) |
| 373 |
|
| 374 |
module = AnsibleAWSModule( |
| 375 |
argument_spec=argument_spec, |
| 376 |
supports_check_mode=True, |
| 377 |
) |
| 378 |
|
| 379 |
try: |
| 380 |
client = module.client("rds", retry_decorator=AWSRetry.jittered_backoff(retries=10)) |
| 381 |
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: |
| 382 |
module.fail_json_aws(e, msg="Failed to connect to AWS.") |
| 383 |
|
| 384 |
module.exit_json(**describe_db_engine_versions(client, module)) |
| 385 |
|
| 386 |
|
| 387 |
if __name__ == "__main__": |
| 388 |
main() |