Open slunk opened 3 months ago
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.
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...
Hi @slunk
applyRemovalPolicy() is a method available in some L2 constructs, such as:
BucketPolicy
Redshift Table
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
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.
Fair enough, thanks for the explanation! I'll try to fix that request and resubmit when I get some time.
Describe the bug
This snippet fails to compile:
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:
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