From 50331a19cfbe30e3d46f8eed15d74d5975fb1527 Mon Sep 17 00:00:00 2001 From: LaurenceWarne <17688577+LaurenceWarne@users.noreply.github.com> Date: Mon, 6 May 2024 19:53:24 +0100 Subject: [PATCH] feat(rds): implement setting parameter group name (#29965) ### Reason for this change I'd like to be able to set RDS parameter group names using CDK. ### Description of changes I've added a new field `name` to `ParameterGroupProps` used to populate `dbClusterParameterGroupName` and `dbParameterGroupName` where appropriate - AFAICS this couldn't be done at this level previously? ### Description of how you validated changes I've altered a couple of unit tests and an integration test. However I'm unable to run the integration test as the postgres version in the existing snapshot is deprecated (I believe this needs to be deployed before the new snapshot?) which blocks me from deploying. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- ...-rds-instance-with-rds-parameter-group.assets.json | 4 ++-- ...ds-instance-with-rds-parameter-group.template.json | 5 +++-- .../manifest.json | 2 +- .../tree.json | 5 +++-- .../test/integ.instance-with-parameter-group.ts | 5 +++-- packages/aws-cdk-lib/aws-rds/README.md | 1 + packages/aws-cdk-lib/aws-rds/lib/parameter-group.ts | 11 +++++++++++ .../aws-cdk-lib/aws-rds/test/parameter-group.test.ts | 4 ++++ 8 files changed, 28 insertions(+), 9 deletions(-) diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-rds/test/integ.instance-with-parameter-group.js.snapshot/aws-cdk-rds-instance-with-rds-parameter-group.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-rds/test/integ.instance-with-parameter-group.js.snapshot/aws-cdk-rds-instance-with-rds-parameter-group.assets.json index cf9ecfa597261..b2db8913fb2a3 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-rds/test/integ.instance-with-parameter-group.js.snapshot/aws-cdk-rds-instance-with-rds-parameter-group.assets.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-rds/test/integ.instance-with-parameter-group.js.snapshot/aws-cdk-rds-instance-with-rds-parameter-group.assets.json @@ -1,7 +1,7 @@ { "version": "36.0.0", "files": { - "27d09999310ee1193509c78be177319a1946d9d28632d2362b5f6168fd2078f1": { + "239d9f5d8cff7634197e9978eaf8133a6904b71cd0f07fbb239f839c7ce32886": { "source": { "path": "aws-cdk-rds-instance-with-rds-parameter-group.template.json", "packaging": "file" @@ -9,7 +9,7 @@ "destinations": { "current_account-current_region": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "27d09999310ee1193509c78be177319a1946d9d28632d2362b5f6168fd2078f1.json", + "objectKey": "239d9f5d8cff7634197e9978eaf8133a6904b71cd0f07fbb239f839c7ce32886.json", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-rds/test/integ.instance-with-parameter-group.js.snapshot/aws-cdk-rds-instance-with-rds-parameter-group.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-rds/test/integ.instance-with-parameter-group.js.snapshot/aws-cdk-rds-instance-with-rds-parameter-group.template.json index 08798fdefb756..4fb3b3c5d1aa0 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-rds/test/integ.instance-with-parameter-group.js.snapshot/aws-cdk-rds-instance-with-rds-parameter-group.template.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-rds/test/integ.instance-with-parameter-group.js.snapshot/aws-cdk-rds-instance-with-rds-parameter-group.template.json @@ -394,8 +394,9 @@ "ParameterGroup5E32DECB": { "Type": "AWS::RDS::DBParameterGroup", "Properties": { + "DBParameterGroupName": "name", "Description": "desc", - "Family": "postgres15", + "Family": "postgres16", "Parameters": {} }, "UpdateReplacePolicy": "Delete", @@ -481,7 +482,7 @@ }, "EnableIAMDatabaseAuthentication": true, "Engine": "postgres", - "EngineVersion": "15.2", + "EngineVersion": "16.2", "MasterUserPassword": { "Fn::Join": [ "", diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-rds/test/integ.instance-with-parameter-group.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-rds/test/integ.instance-with-parameter-group.js.snapshot/manifest.json index bbaf8c75314a2..5ab6b54ad58d9 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-rds/test/integ.instance-with-parameter-group.js.snapshot/manifest.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-rds/test/integ.instance-with-parameter-group.js.snapshot/manifest.json @@ -18,7 +18,7 @@ "validateOnSynth": false, "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/27d09999310ee1193509c78be177319a1946d9d28632d2362b5f6168fd2078f1.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/239d9f5d8cff7634197e9978eaf8133a6904b71cd0f07fbb239f839c7ce32886.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-rds/test/integ.instance-with-parameter-group.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-rds/test/integ.instance-with-parameter-group.js.snapshot/tree.json index e2c109b5469fc..9ab09e1f659fd 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-rds/test/integ.instance-with-parameter-group.js.snapshot/tree.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-rds/test/integ.instance-with-parameter-group.js.snapshot/tree.json @@ -661,8 +661,9 @@ "attributes": { "aws:cdk:cloudformation:type": "AWS::RDS::DBParameterGroup", "aws:cdk:cloudformation:props": { + "dbParameterGroupName": "name", "description": "desc", - "family": "postgres15", + "family": "postgres16", "parameters": {} } }, @@ -834,7 +835,7 @@ }, "enableIamDatabaseAuthentication": true, "engine": "postgres", - "engineVersion": "15.2", + "engineVersion": "16.2", "masterUsername": { "Fn::Join": [ "", diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-rds/test/integ.instance-with-parameter-group.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-rds/test/integ.instance-with-parameter-group.ts index 141fefb491cc1..83a9caefd940b 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-rds/test/integ.instance-with-parameter-group.ts +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-rds/test/integ.instance-with-parameter-group.ts @@ -11,13 +11,14 @@ const stack = new cdk.Stack(app, 'aws-cdk-rds-instance-with-rds-parameter-group' const vpc = new ec2.Vpc(stack, 'VPC', { maxAzs: 2, restrictDefaultSecurityGroup: false }); const parameterGroup = new rds.ParameterGroup(stack, 'ParameterGroup', { - engine: rds.DatabaseInstanceEngine.postgres({ version: rds.PostgresEngineVersion.VER_15_2 }), + engine: rds.DatabaseInstanceEngine.postgres({ version: rds.PostgresEngineVersion.VER_16_2 }), description: 'desc', removalPolicy: cdk.RemovalPolicy.DESTROY, + name: 'name', }); new rds.DatabaseInstance(stack, 'Instance', { - engine: rds.DatabaseInstanceEngine.postgres({ version: rds.PostgresEngineVersion.VER_15_2 }), + engine: rds.DatabaseInstanceEngine.postgres({ version: rds.PostgresEngineVersion.VER_16_2 }), vpc, multiAz: false, publiclyAccessible: true, diff --git a/packages/aws-cdk-lib/aws-rds/README.md b/packages/aws-cdk-lib/aws-rds/README.md index f44921d277e47..6fad15b4734b5 100644 --- a/packages/aws-cdk-lib/aws-rds/README.md +++ b/packages/aws-cdk-lib/aws-rds/README.md @@ -1078,6 +1078,7 @@ const parameterGroup = new rds.ParameterGroup(this, 'ParameterGroup', { engine: rds.DatabaseInstanceEngine.sqlServerEe({ version: rds.SqlServerEngineVersion.VER_11, }), + name: 'my-parameter-group', parameters: { locks: '100', }, diff --git a/packages/aws-cdk-lib/aws-rds/lib/parameter-group.ts b/packages/aws-cdk-lib/aws-rds/lib/parameter-group.ts index c529bc859d401..ef1f43aac56b1 100644 --- a/packages/aws-cdk-lib/aws-rds/lib/parameter-group.ts +++ b/packages/aws-cdk-lib/aws-rds/lib/parameter-group.ts @@ -70,6 +70,13 @@ export interface ParameterGroupProps { */ readonly engine: IEngine; + /** + * The name of this parameter group. + * + * @default - CloudFormation-generated name + */ + readonly name?: string; + /** * Description for this parameter group * @@ -126,6 +133,7 @@ export class ParameterGroup extends Resource implements IParameterGroup { private readonly family: string; private readonly removalPolicy?: RemovalPolicy; private readonly description?: string; + private readonly name?: string; private clusterCfnGroup?: CfnDBClusterParameterGroup; private instanceCfnGroup?: CfnDBParameterGroup; @@ -139,6 +147,7 @@ export class ParameterGroup extends Resource implements IParameterGroup { } this.family = family; this.description = props.description; + this.name = props.name; this.parameters = props.parameters ?? {}; this.removalPolicy = props.removalPolicy; } @@ -149,6 +158,7 @@ export class ParameterGroup extends Resource implements IParameterGroup { this.clusterCfnGroup = new CfnDBClusterParameterGroup(this, id, { description: this.description || `Cluster parameter group for ${this.family}`, family: this.family, + dbClusterParameterGroupName: this.name, parameters: Lazy.any({ produce: () => this.parameters }), }); } @@ -166,6 +176,7 @@ export class ParameterGroup extends Resource implements IParameterGroup { this.instanceCfnGroup = new CfnDBParameterGroup(this, id, { description: this.description || `Parameter group for ${this.family}`, family: this.family, + dbParameterGroupName: this.name, parameters: Lazy.any({ produce: () => this.parameters }), }); } diff --git a/packages/aws-cdk-lib/aws-rds/test/parameter-group.test.ts b/packages/aws-cdk-lib/aws-rds/test/parameter-group.test.ts index cb8ee7adefc4c..a47d76953bd11 100644 --- a/packages/aws-cdk-lib/aws-rds/test/parameter-group.test.ts +++ b/packages/aws-cdk-lib/aws-rds/test/parameter-group.test.ts @@ -29,6 +29,7 @@ describe('parameter group', () => { const parameterGroup = new ParameterGroup(stack, 'Params', { engine: DatabaseClusterEngine.AURORA, description: 'desc', + name: 'name', parameters: { key: 'value', }, @@ -37,6 +38,7 @@ describe('parameter group', () => { // THEN Template.fromStack(stack).hasResourceProperties('AWS::RDS::DBParameterGroup', { + DBParameterGroupName: 'name', Description: 'desc', Family: 'aurora5.6', Parameters: { @@ -53,6 +55,7 @@ describe('parameter group', () => { const parameterGroup = new ParameterGroup(stack, 'Params', { engine: DatabaseClusterEngine.AURORA, description: 'desc', + name: 'name', parameters: { key: 'value', }, @@ -61,6 +64,7 @@ describe('parameter group', () => { // THEN Template.fromStack(stack).hasResourceProperties('AWS::RDS::DBClusterParameterGroup', { + DBClusterParameterGroupName: 'name', Description: 'desc', Family: 'aurora5.6', Parameters: {