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

(aws-docdb): setting up cluster with retention policy == snapshot breaks internal security group #28773

Closed
kornicameister opened this issue Jan 19, 2024 · 5 comments · Fixed by #28798
Labels
@aws-cdk/aws-docdb Related to Amazon DocumentDB bug This issue is a bug. effort/medium Medium work item – several days of effort p2

Comments

@kornicameister
Copy link
Contributor

Describe the bug

Setting up a cluster with removalPolicy: cdk.RemovalPolicy.SNAPSHOT fails to synth because ec2.SecurityGroup does not supoort said RemovalPolicy

Expected Behavior

cdk synth executed correctly.

Current Behavior

cdk synth fails with Error: AWS::EC2::SecurityGroup does not support snapshot removal policy

Reproduction Steps

#!/usr/bin/env node
import * as cdk from 'aws-cdk-lib';
import * as docDb from 'aws-cdk-lib/aws-docdb';
import * as ec2 from 'aws-cdk-lib/aws-ec2';
import 'source-map-support/register';

const app = new cdk.App();
const env = {
  account: 'your account',
  region: 'your region',
};
const stack = new cdk.Stack(app, 'DocDB', {
  env,
});

new docDb.DatabaseCluster(stack, 'Cluster', {
  removalPolicy: cdk.RemovalPolicy.SNAPSHOT,
  masterUser: {
    username: 'test',
    password: cdk.SecretValue.unsafePlainText('test'),
  },
  instanceType: ec2.InstanceType.of(
    ec2.InstanceClass.T4G,
    ec2.InstanceSize.MEDIUM,
  ),
  vpc: ec2.Vpc.fromLookup(stack, 'VPC', { isDefault: true }),
});

Possible Solution

  1. Fallback to retaining security group if document db has snapshot policy set
  2. Do not set retention policy inside construct

Personally I prefer the 2nd idea, because setting a retention policy inside Construct does seem to be a bit of an odd idea.
I think setting up one with CDK defaults make more sense and if user wants to change the default it can always create a security group before hand and pass it as prop

Additional Information/Context

No response

CDK CLI Version

2.121.1

Framework Version

No response

Node.js Version

20.8

OS

MacOS sierra

Language

TypeScript

Language Version

5.3

Other information

No response

@kornicameister kornicameister added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jan 19, 2024
@github-actions github-actions bot added the @aws-cdk/aws-docdb Related to Amazon DocumentDB label Jan 19, 2024
@kornicameister
Copy link
Contributor Author

Huh...funny enough the problem is around DocDB.
Apparently it does not support delete with snapshot.

I guess it's my bad on that part.

However, I would still bring up to discussion a part where removal policy of group is set via escape hatch

@pahud
Copy link
Contributor

pahud commented Jan 20, 2024

Yes I think we should fix here to avoid this error.

// HACK: Use an escape-hatch to apply a consistent removal policy to the
// security group so we don't get errors when trying to delete the stack
(securityGroup.node.defaultChild as CfnResource).applyRemovalPolicy(props.removalPolicy, {
applyToUpdateReplacePolicy: true,
});

@pahud pahud added p2 effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Jan 20, 2024
@kornicameister
Copy link
Contributor Author

Would it work to jest get rid of escape hatch?

@kornicameister
Copy link
Contributor Author

@pahud would you mind checking on the linked PR from @lpizzinidev.
There's a discussion that tackles the problem of using an escape and in general downgrading removal policies if L2 component's children do not support particular removal policy i.e.

  1. we spin up DocumentDBCluster with snapshot removal policy
  2. we downgrade removal policy for security group to destroy because it does not support snapshot

In short, there's a bit of a pickle between @lpizzinidev and myself :-) questioning the design of downgrading policies without explicit intention of a user/caller that creates given L2 construct.

lpizzinidev added a commit to lpizzinidev/aws-cdk that referenced this issue Jan 29, 2024
GavinZZ added a commit to lpizzinidev/aws-cdk that referenced this issue Feb 29, 2024
GavinZZ added a commit that referenced this issue Feb 29, 2024
Adds support for `removalPolicy: RemovalPolicy.SNAPSHOT` for DocumentDB
clusters as specified in the
[documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-deletionpolicy.html).

To allow users to specify custom policies for the cluster's instances
and security group the following properties have been added:
* `instanceRemovalPolicy`
* `securityGroupRemovalPolicy`

Closes #28773.
Closes #28861

----

*By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache-2.0 license*
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-docdb Related to Amazon DocumentDB bug This issue is a bug. effort/medium Medium work item – several days of effort p2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants