0

I'm currently migrating an AWS stack defined in Cloudformation (CFT) to CDK. The goal is not to trigger a replacement of viral resources, but I'm stuck with my Application Load Balancer.

In the old CFT stack the ALB is defined as:

Type: AWS::ElasticLoadBalancingV2::LoadBalancer

without the "Type" Property set which allows the following values: application | gateway | network Anyways the resulting Resource in AWS Console has the Type set to "application".

In CDK I create the ALB like:

new ApplicationLoadBalancer(this, 'alb', {
  vpc,
  internetFacing: true,
  vpcSubnets: {
    subnets: vpc.publicSubnets,
  },
  securityGroup: this.securityGroup,
});

unfortunately this triggers a replacement because "Type": "application" is now set explicitly.

Is there any way around this? My next guess would be to try an Cfn Construct...

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62

1 Answers1

0

The most convenient solution I found was to just delete the property that is set implicitly in the L2 Construct.

const alb = new ApplicationLoadBalancer(this, 'alb', {
  vpc,
  internetFacing: true,
  vpcSubnets: {
    subnets: vpc.publicSubnets,
  },
  securityGroup: mySg
});

// First cast Construct to its underlying Cfn Construct
// Then delete property
(alb.node.defaultChild as CfnLoadBalancer).addDeletionOverride('Properties.Type');

More information can be found here: AWS Documentation: Escape hatches