Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cloudformation cannot delete AWS::RDS::DBSubnetGroup when DBInstance ist set to retain #5282

Closed
konstantinj opened this issue Dec 3, 2019 · 3 comments · Fixed by #8110
Closed
Assignees
Labels
@aws-cdk/aws-rds Related to Amazon Relational Database bug This issue is a bug. needs-discussion This issue/PR requires more discussion with community. p1

Comments

@konstantinj
Copy link

konstantinj commented Dec 3, 2019

When creating either a dbcluster or dbinstance with all options to default it is not possible to delete the cloudformation stack afterwards since the dbinstance is per default set to retain but cfn still tries to delete the AWS::RDS::DBSubnetGroup which is not possible because the instance depends on it.

Reproduction Steps

create a dbcuster or a dbinstance

        const database = new rds.DatabaseCluster(this, 'DatabaseCluster', {
            defaultDatabaseName: 'test',
            masterUser: {
                username: 'test',
            },
            instances: 1,
            engine: rds.DatabaseClusterEngine.AURORA,
            instanceProps: {
                instanceType: ec2.InstanceType.of(ec2.InstanceClass.T3, ec2.InstanceSize.SMALL),
                vpc: vpc,
                vpcSubnets: {
                    subnetType: ec2.SubnetType.PRIVATE,
                }
            }
        });

Error Log

cloudformation will not finish the deletion and time out after 4 hours of trying.

Environment

  • CLI Version :1.18.0
  • Framework Version:1.18.0
  • OS :osx
  • Language :typescript

This is 🐛 Bug Report

@konstantinj konstantinj added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Dec 3, 2019
@SomayaB SomayaB added @aws-cdk/aws-rds Related to Amazon Relational Database @aws-cdk/aws-cloudformation Related to AWS CloudFormation labels Dec 3, 2019
@skinny85 skinny85 removed the @aws-cdk/aws-cloudformation Related to AWS CloudFormation label Jan 8, 2020
@skinny85
Copy link
Contributor

skinny85 commented Jan 8, 2020

Hey @konstantinj ,

thanks for opening the issue. This is a tradeoff between the defaults, which we want to be safe (we don't want to people accidentally deleting their database), and the desire the experiment.

Could perhaps changing AWS::RDS::DBSubnetGroup to also retain if the DB is retain be a satisfactory compromise here?

Thanks,
Adam

@skinny85 skinny85 added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. p1 labels Jan 8, 2020
@SomayaB SomayaB added closing-soon This issue will automatically close in 4 days unless further comments are made. and removed response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. needs-triage This issue or PR still needs to be triaged. labels Jan 15, 2020
@SomayaB SomayaB added needs-discussion This issue/PR requires more discussion with community. and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Jan 22, 2020
@skinny85 skinny85 assigned nija-at and unassigned skinny85 Mar 19, 2020
@mjsilva
Copy link

mjsilva commented Apr 2, 2020

@skinny85 thanks for the clarification I just bumped on this today while testing CDK. I think it makes sense to leave removalPolicy retain by default. Maybe we just need to document or find a way to let the user know this is the expected behaviours before hand? If you have any suggestion where to document this I'm happy to open a PR.

I'm retesting with removalPolicy: RemovalPolicy.DESTROY and will report back how it goes.

@mjsilva
Copy link

mjsilva commented Apr 17, 2020

RemovalPolicy.DESTROY works perfectly. So for now I added a ...: isProduction ? RemovalPolicy.RETAIN : RemovalPolicy.DESTROY on stateful resources like DB, Logs etc...

skinny85 added a commit to skinny85/aws-cdk that referenced this issue May 20, 2020
When the DatabaseCluster has its deletion policy set to 'Retain',
an attempt to delete the stack containing it fails,
as the DbSubnetGroup cannot be removed if it still points to an existing Cluster.
To fix that, set the retention policy of DbSubnetGroup to 'Retain'
if it is 'Retain' on the DatabaseCluster.

Fixes aws#5282
skinny85 added a commit to skinny85/aws-cdk that referenced this issue Jun 1, 2020
When the DatabaseCluster has its deletion policy set to 'Retain',
an attempt to delete the stack containing it fails,
as the DbSubnetGroup cannot be removed if it still points to an existing Cluster.
To fix that, set the retention policy of DbSubnetGroup to 'Retain'
if it is 'Retain' on the DatabaseCluster.

Fixes aws#5282
@mergify mergify bot closed this as completed in #8110 Jun 1, 2020
mergify bot pushed a commit that referenced this issue Jun 1, 2020
When the DatabaseCluster has its deletion policy set to 'Retain',
an attempt to delete the stack containing it fails,
as the DbSubnetGroup cannot be removed if it still points to an existing Cluster.
To fix that, set the retention policy of DbSubnetGroup to 'Retain'
if it is 'Retain' on the DatabaseCluster.

Fixes #5282

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-rds Related to Amazon Relational Database bug This issue is a bug. needs-discussion This issue/PR requires more discussion with community. p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants