(aws-docdb): cannot delete a stack with DatabaseCluster removal_policy set to 'Retain' #29054
Labels
@aws-cdk/aws-docdb
Related to Amazon DocumentDB
bug
This issue is a bug.
effort/medium
Medium work item – several days of effort
p3
Describe the bug
After creating a DocumentDB DatabaseCluster with a removal_policy set to Retain, the CloudFormation stack can not be deleted. The stack can not be deleted because the associated subnet group can not be removed if it points to an existing cluster.
Sample error from CloudFormation:
Got InvalidDBInstanceStateException with error: Cannot delete the subnet group '{subnet_group_name}' because at least one database instance: {instance_name} is still using it.
Expected Behavior
The CloudFormation stack should be able to successfully delete.
Current Behavior
After creating a DocumentDB DatabaseCluster with a removal_policy set to Retain, the CloudFormation stack can not be deleted. The stack can not be deleted because the associated subnet group can not be removed if it points to an existing cluster.
Sample error from CloudFormation:
Got InvalidDBInstanceStateException with error: Cannot delete the subnet group '{subnet_group_name}' because at least one database instance: {instance_name} is still using it.
Reproduction Steps
Possible Solution
This same bug was happening for the aws-rds DatabaseCluster (issue attached here), until this fix came around. I suggest to make the same fix for the aws-docdb DatabaseCluster, where it sets the retention policy of DbSubnetGroup to 'Retain' if it is 'Retain' on the DatabaseCluster.
I plan on creating a PR using this solution to resolve this issue.
Additional Information/Context
No response
CDK CLI Version
2.126.0
Framework Version
No response
Node.js Version
v20.11.0
OS
macOS Sonoma 14.3
Language
Python
Language Version
No response
Other information
No response
The text was updated successfully, but these errors were encountered: