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

vpc-endpoint-service: impossible to change removal policy #30639

Open
slunk opened this issue Jun 24, 2024 · 4 comments
Open

vpc-endpoint-service: impossible to change removal policy #30639

slunk opened this issue Jun 24, 2024 · 4 comments
Labels
@aws-cdk/aws-iam Related to AWS Identity and Access Management effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p3

Comments

@slunk
Copy link

slunk commented Jun 24, 2024

Describe the bug

This snippet fails to compile:

const vpces = new VpcEndpointService(this, 'Id', {
  vpcEndpointServiceLoadBalancers: [nlb],
});
vpces.applyRemovalPolicy(RemovalPolicy.RETAIN);

Expected Behavior

Build succeeds, and the Cloudformation stack managing this vpc endpoint service has a resource whose removal policy is set to RETAIN.

Current Behavior

This error is emitted:

Error: Cannot apply RemovalPolicy: no child or not a CfnResource. Apply the removal policy on the CfnResource directly.

Reproduction Steps

Create a stack with a VpcEndpointService and set its removal policy.

Possible Solution

Set the defaultChild for this construct.

Additional Information/Context

No response

CDK CLI Version

2.144.0

Framework Version

No response

Node.js Version

v20.3.0

OS

linux

Language

TypeScript

Language Version

No response

Other information

No response

@slunk slunk added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jun 24, 2024
@github-actions github-actions bot added the @aws-cdk/aws-iam Related to AWS Identity and Access Management label Jun 24, 2024
slunk added a commit to slunk/aws-cdk that referenced this issue Jun 24, 2024
        ### Issue # (if applicable)

        Closes aws#30639.

        ### Reason for this change

        Cannot set removal policy on VpcEndpointService. defaultChild is not set.

        ### Description of changes

        Sets defaultChild of VpcEndpointService objects.
@khushail khushail added investigating This issue is being investigated and/or work is in progress to resolve the issue. and removed needs-triage This issue or PR still needs to be triaged. labels Jun 24, 2024
@pahud
Copy link
Contributor

pahud commented Jun 24, 2024

applyRemovalPolicy only works with CfnResource

try this instead:

    const vpces = new ec2.VpcEndpointService(this, 'Id', {
      vpcEndpointServiceLoadBalancers: [nlb],
    });
    (vpces.node.tryFindChild('Id') as CfnVPCEndpointService).applyRemovalPolicy(RemovalPolicy.RETAIN);

Let me know if it works for you.

@pahud pahud added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. p3 and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. labels Jun 24, 2024
@slunk
Copy link
Author

slunk commented Jun 25, 2024

Hi Pahud. I'm not especially interested in a workaround because I've already found one.

vpces["endpointService"].applyRemovalPolicy(RemovalPolicy.RETAIN);

If you don't consider this a bug, feel free to resolve. Your suggestion seems a bit obtuse, though. How am I, a CDK user, meant to figure that out from the documentation? It also seems inconsistent with other established constructs. I can call applyRemovalPolicy on S3 buckets, network load balancers, etc...

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Jun 25, 2024
@pahud
Copy link
Contributor

pahud commented Jun 25, 2024

Hi @slunk

applyRemovalPolicy() is a method available in some L2 constructs, such as:

BucketPolicy

/**
* Sets the removal policy for the BucketPolicy.
* @param removalPolicy the RemovalPolicy to set.
*/
public applyRemovalPolicy(removalPolicy: RemovalPolicy) {
this.resource.applyRemovalPolicy(removalPolicy);
}
}

Redshift Table

public applyRemovalPolicy(policy: cdk.RemovalPolicy): void {
this.resource.applyRemovalPolicy(policy);
}

If you look at its implementation, it essentially runs the applyRemovalPolicy() on this.resource which is the L1 resource behind the L2 construct.

The reason I am not considering it a bug is

  1. It's not a required method for a L2 construct, but could be nice to have as a feature request.
  2. Without that L2 construct method, we still can do that with a very simple workaround from ALL L2 constructs. The tip is first find out the L1 resource using tryFindChild to access the L1 Node and then just applyRemovalPolicy() from that L1 node.

We appreciate your PR to expose that method to the L2 surface. Unfortunately it was closed by the bot. This is a nice feature request though. Feel free to submit a new one for that and let me know if you need any help. You can find me on cdk.dev if you need any help.

@pahud pahud added feature-request A feature should be added or improved. effort/small Small work item – less than a day of effort response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed bug This issue is a bug. labels Jun 25, 2024
@slunk
Copy link
Author

slunk commented Jun 26, 2024

Fair enough, thanks for the explanation! I'll try to fix that request and resubmit when I get some time.

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Jun 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-iam Related to AWS Identity and Access Management effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p3
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants