Skip to content

rds: DatabaseCluster auto-created Parameter Group doesn't inherit RemovalPolicy #35273

@pahud

Description

@pahud

Describe the bug

When a DatabaseCluster is configured with removalPolicy: RemovalPolicy.RETAIN, the auto-created Parameter Group does not inherit this removal policy, causing CloudFormation stack deletion to fail with the error "Parameter Group is still in use by database instances."

Regression Issue

  • Select this option if this issue appears to be a regression.

Last Known Working CDK Library Version

No response

Expected Behavior

Auto-created Parameter Groups should inherit the parent cluster's RemovalPolicy to ensure consistent lifecycle management.

Current Behavior

Current Behavior:

const cluster = new DatabaseCluster(this, 'MyCluster', {
  engine: DatabaseClusterEngine.auroraPostgres({ version: AuroraPostgresEngineVersion.VER_15_4 }),
  writer: ClusterInstance.provisioned('writer'),
  vpc,
  removalPolicy: RemovalPolicy.RETAIN, // Applied to cluster
  parameters: {
    'shared_preload_libraries': 'pg_stat_statements'
  }
});

Reproduction Steps

  1. Create a DatabaseCluster with removalPolicy: RemovalPolicy.RETAIN
  2. Include parameters property to trigger auto-creation of Parameter Group
  3. Deploy the stack
  4. Attempt to delete the stack
  5. Observe CloudFormation error about Parameter Group still being in use

Possible Solution

Modify the Parameter Group creation in cluster.ts to inherit the cluster's removal policy:

const parameterGroup = props.parameterGroup ?? (
  props.parameters
    ? new ParameterGroup(this, 'ParameterGroup', {
      engine: props.engine,
      parameters: props.parameters,
      removalPolicy: props.removalPolicy, // Add this line
    })
    : undefined
);

Additional Information/Context

Workaround

Users can work around this issue by manually creating the Parameter Group with the desired removal policy:

const parameterGroup = new ParameterGroup(this, 'MyParameterGroup', {
  engine: DatabaseClusterEngine.auroraPostgres({ version: AuroraPostgresEngineVersion.VER_15_4 }),
  parameters: {
    'shared_preload_libraries': 'pg_stat_statements'
  },
  removalPolicy: RemovalPolicy.RETAIN,
});

const cluster = new DatabaseCluster(this, 'MyCluster', {
  engine: DatabaseClusterEngine.auroraPostgres({ version: AuroraPostgresEngineVersion.VER_15_4 }),
  writer: ClusterInstance.provisioned('writer'),
  vpc,
  parameterGroup, // Use explicit parameter group
  removalPolicy: RemovalPolicy.RETAIN,
});

AWS CDK Library version (aws-cdk-lib)

aws-cdk-lib@2.196.1

AWS CDK CLI version

2.1021.0 (build 059c862)

Node.js Version

v22.11.0

OS

mac os x

Language

TypeScript

Language Version

No response

Other information

No response

Metadata

Metadata

Assignees

Labels

@aws-cdk/aws-rdsRelated to Amazon Relational DatabasebugThis issue is a bug.effort/mediumMedium work item – several days of effortp2

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions