Skip to content

Add Performance Insights and Database Insights to rds_cluster.py #2543

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
3 changes: 3 additions & 0 deletions changelogs/fragments/2543-add_PI_rds_cluster.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
minor_changes:
- Add functionality to enable Performance Insights and Database Insights at cluster level (https://github.com/ansible-collections/amazon.aws/pull/2543).
64 changes: 64 additions & 0 deletions plugins/modules/rds_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@
description:
- The character set to associate with the DB cluster.
type: str
database_insights_mode
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's another one:

Suggested change
database_insights_mode
database_insights_mode:

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handled in next commit.

description:
- Indicates which mode of Database Insights to enable for the target DB cluster. Options are 'advanced' or 'standard'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to use choices: ['advanced', 'standard'] for this parameter

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are the values that are expected when modifying an rds cluster:

https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/rds/client/modify_db_cluster.html

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With choices it would look like this:

Suggested change
- Indicates which mode of Database Insights to enable for the target DB cluster. Options are 'advanced' or 'standard'
- Indicates which mode of Database Insights to enable for the target DB cluster.
choices:
- standard
- advanced

(You'll also have to add choices to the argument spec for that option.)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handled in next commit

type: str
versions_added: 9.4.0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new options have the field versions_added, which is causing the CI failure.

Suggested change
versions_added: 9.4.0
version_added: 9.4.0

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch-thanks!

database_name:
description:
- The name for your database. If a name is not provided Amazon RDS will not create a database.
Expand Down Expand Up @@ -177,6 +182,11 @@
- Enable mapping of AWS Identity and Access Management (IAM) accounts to database accounts.
If this option is omitted when creating the cluster, Amazon RDS sets this to C(false).
type: bool
enable_performance_insights:
description:
- Whether to enable Performance Insights for the DB cluster.
type: bool
versions_added: 9.4.0
allocated_storage:
description:
- The amount of storage in gibibytes (GiB) to allocate to each DB instance in the Multi-AZ DB cluster.
Expand Down Expand Up @@ -285,6 +295,16 @@
description:
- The option group to associate with the DB cluster.
type: str
performance_insights_kms_key_id:
description:
- The AWS KMS key identifier (ARN, name, or alias) for encryption of Performance Insights data.
type: str
versions_added: 9.4.0
performance_insights_retention_period:
description:
- The amount of time, in days, to retain Performance Insights data. Valid values are V(7) or V(731).
type: int
versions_added: 9.4.0
port:
description:
- The port number on which the instances in the DB cluster accept connections. If not specified, Amazon RDS
Expand Down Expand Up @@ -822,13 +842,17 @@ def get_create_options(params_dict):
"DBClusterIdentifier",
"DBClusterParameterGroupName",
"DBSubnetGroupName",
"DatabaseInsightsMode",
"DatabaseName",
"EnableCloudwatchLogsExports",
"EnableIAMDatabaseAuthentication",
"EnablePerformanceInsights",
"KmsKeyId",
"Engine",
"EngineMode",
"EngineVersion",
"PerformanceInsightsKMSKeyId",
"PerformanceInsightsRetentionPeriod",
"PreferredMaintenanceWindow",
"MasterUserPassword",
"MasterUsername",
Expand Down Expand Up @@ -865,15 +889,19 @@ def get_modify_options(params_dict, force_update_password):
"BacktrackWindow",
"BackupRetentionPeriod",
"PreferredBackupWindow",
"DatabaseInsightsMode",
"DBClusterIdentifier",
"DBClusterParameterGroupName",
"EnableIAMDatabaseAuthentication",
"EnablePerformanceInsights",
"EngineVersion",
"PreferredMaintenanceWindow",
"MasterUserPassword",
"NewDBClusterIdentifier",
"OptionGroupName",
"Port",
"PerformanceInsightsKMSKeyId",
"PerformanceInsightsRetentionPeriod",
"VpcSecurityGroupIds",
"EnableIAMDatabaseAuthentication",
"CloudwatchLogsExportConfiguration",
Expand Down Expand Up @@ -907,18 +935,22 @@ def get_restore_s3_options(params_dict):
"BacktrackWindow",
"BackupRetentionPeriod",
"CharacterSetName",
"DatabaseInsightsMode",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None of these options are supported by https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/rds/client/restore_db_cluster_from_s3.html#RDS.Client.restore_db_cluster_from_s3. These attributes could be modified after restoring the cluster.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that when I was doing research last night. I haven't changed it yet but currently debugging in difference branch. Thank you for looking into it! If I didn't see it last night, your comment would have!

"DBClusterIdentifier",
"DBClusterParameterGroupName",
"DBSubnetGroupName",
"DatabaseName",
"EnableCloudwatchLogsExports",
"EnableIAMDatabaseAuthentication",
"EnablePerformanceInsights",
"Engine",
"EngineVersion",
"KmsKeyId",
"MasterUserPassword",
"MasterUsername",
"OptionGroupName",
"PerformanceInsightsKMSKeyId",
"PerformanceInsightsRetentionPeriod",
"Port",
"PreferredBackupWindow",
"PreferredMaintenanceWindow",
Expand All @@ -935,6 +967,10 @@ def get_restore_s3_options(params_dict):
"CopyTagsToSnapshot",
"Domain",
"DomainIAMRoleName",
"DatabaseInsightsMode",
"EnablePerformanceInsights",
"PerformanceInsightsKMSKeyId",
"PerformanceInsightsRetentionPeriod",
]

return dict((k, v) for k, v in params_dict.items() if k in options and v is not None)
Expand All @@ -944,15 +980,19 @@ def get_restore_snapshot_options(params_dict):
options = [
"AvailabilityZones",
"BacktrackWindow",
"DatabaseInsightsMode",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment above-will fix in next commit!

"DBClusterIdentifier",
"DBSubnetGroupName",
"DatabaseName",
"EnableCloudwatchLogsExports",
"EnableIAMDatabaseAuthentication",
"EnablePerformanceInsights",
"Engine",
"EngineVersion",
"KmsKeyId",
"OptionGroupName",
"PerformanceInsightsKMSKeyId",
"PerformanceInsightsRetentionPeriod",
"Port",
"SnapshotIdentifier",
"Tags",
Expand All @@ -969,12 +1009,16 @@ def get_restore_snapshot_options(params_dict):
def get_restore_cluster_options(params_dict):
options = [
"BacktrackWindow",
"DatabaseInsightsMode",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment, will fix in next commit!

"DBClusterIdentifier",
"DBSubnetGroupName",
"EnableCloudwatchLogsExports",
"EnableIAMDatabaseAuthentication",
"EnablePerformanceInsights",
"KmsKeyId",
"OptionGroupName",
"PerformanceInsightsKMSKeyId",
"PerformanceInsightsRetentionPeriod",
"Port",
"RestoreToTime",
"RestoreType",
Expand Down Expand Up @@ -1092,6 +1136,22 @@ def changing_cluster_options(modify_params, current_cluster):
g["DBClusterOptionGroupName"] for g in current_cluster["DBClusterOptionGroupMemberships"]
]:
changing_params["OptionGroupName"] = option_group

enable_performance_insights = modify_params.pop("EnablePerformanceInsights", None)
if enable_performance_insights != current_cluster["EnablePerformanceInsights"]:
changing_params["EnablePerformanceInsights"] = enable_performance_insights

performance_insights_kms_key_id = modify_params.pop("PerformanceInsightsKMSKeyId", None)
if performance_insights_kms_key_id != current_cluster["PerformanceInsightsKMSKeyId"]:
changing_params["PerformanceInsightsKMSKeyId"] = performance_insights_kms_key_id

performance_insights_retention_period = modify_params("PerformanceInsightsRetentionPeriod", None)
if performance_insights_retention_period != current_cluster["PerformanceInsightsRetentionPeriod"]:
changing_params["PerformanceInsightsRetentionPeriod"] = performance_insights_retention_period

database_insights_mode = modify_params.pop("DatabaseInsightsMode", None)
if database_insights_mode != current_cluster["DatabaseInsightsMode"]:
changing_params["DatabaseInsightsMode"] = database_insights_mode

vpc_sgs = modify_params.pop("VpcSecurityGroupIds", None)
if vpc_sgs:
Expand Down Expand Up @@ -1259,10 +1319,12 @@ def main():
backup_retention_period=dict(type="int", default=1),
character_set_name=dict(),
database_name=dict(aliases=["db_name"]),
database_insights_mode=dict(choices=["standard","advanced"]),
db_cluster_identifier=dict(required=True, aliases=["cluster_id", "id", "cluster_name"]),
db_cluster_parameter_group_name=dict(),
db_subnet_group_name=dict(),
enable_cloudwatch_logs_exports=dict(type="list", elements="str"),
enable_performance_insights=dict(type="bool"),
deletion_protection=dict(type="bool"),
global_cluster_identifier=dict(),
enable_http_endpoint=dict(type="bool"),
Expand All @@ -1286,6 +1348,8 @@ def main():
new_db_cluster_identifier=dict(aliases=["new_cluster_id", "new_id", "new_cluster_name"]),
option_group_name=dict(),
port=dict(type="int"),
performance_insights_kms_key_id=dict(),
performance_insights_retention_period=dict(type="int"),
preferred_backup_window=dict(aliases=["backup_window"]),
preferred_maintenance_window=dict(aliases=["maintenance_window"]),
remove_from_global_db=dict(type="bool"),
Expand Down
Loading