Skip to content

Commit

Permalink
feat(rds): implement setting parameter group name (#29965)
Browse files Browse the repository at this point in the history
### 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*
  • Loading branch information
LaurenceWarne committed May 6, 2024
1 parent a38707b commit 50331a1
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 9 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -394,8 +394,9 @@
"ParameterGroup5E32DECB": {
"Type": "AWS::RDS::DBParameterGroup",
"Properties": {
"DBParameterGroupName": "name",
"Description": "desc",
"Family": "postgres15",
"Family": "postgres16",
"Parameters": {}
},
"UpdateReplacePolicy": "Delete",
Expand Down Expand Up @@ -481,7 +482,7 @@
},
"EnableIAMDatabaseAuthentication": true,
"Engine": "postgres",
"EngineVersion": "15.2",
"EngineVersion": "16.2",
"MasterUserPassword": {
"Fn::Join": [
"",
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions packages/aws-cdk-lib/aws-rds/README.md
Expand Up @@ -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',
},
Expand Down
11 changes: 11 additions & 0 deletions packages/aws-cdk-lib/aws-rds/lib/parameter-group.ts
Expand Up @@ -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
*
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -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 }),
});
}
Expand All @@ -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 }),
});
}
Expand Down
4 changes: 4 additions & 0 deletions packages/aws-cdk-lib/aws-rds/test/parameter-group.test.ts
Expand Up @@ -29,6 +29,7 @@ describe('parameter group', () => {
const parameterGroup = new ParameterGroup(stack, 'Params', {
engine: DatabaseClusterEngine.AURORA,
description: 'desc',
name: 'name',
parameters: {
key: 'value',
},
Expand All @@ -37,6 +38,7 @@ describe('parameter group', () => {

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::RDS::DBParameterGroup', {
DBParameterGroupName: 'name',
Description: 'desc',
Family: 'aurora5.6',
Parameters: {
Expand All @@ -53,6 +55,7 @@ describe('parameter group', () => {
const parameterGroup = new ParameterGroup(stack, 'Params', {
engine: DatabaseClusterEngine.AURORA,
description: 'desc',
name: 'name',
parameters: {
key: 'value',
},
Expand All @@ -61,6 +64,7 @@ describe('parameter group', () => {

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::RDS::DBClusterParameterGroup', {
DBClusterParameterGroupName: 'name',
Description: 'desc',
Family: 'aurora5.6',
Parameters: {
Expand Down

0 comments on commit 50331a1

Please sign in to comment.