rds: DatabaseCluster auto-created Parameter Group doesn't inherit RemovalPolicy
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### 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:**
```typescript
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:
```typescript
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:
```typescript
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_
Contributor guide
Assessment
This issue has not been assessed yet.