deleting resources during CDK deploy?

Viewed 34

How can I delete unused resources during a CDK deploy? I'm creating a VPC with:

vpc = ec2.Vpc(self, id = "myTestVPC", max_azs = 3, 
              cidr = "10.120.0.0/16", 
              subnet_configuration = [ presentation_nc, logic_nc, data_nc ])

So I wind up with 9 subnets - 3 public and 6 private. I want to use 1 routing table for the public subnets and 1 for the private. I'm doing that by iterating over vpc.private_subnets and vpc.public_subnets, and associating the routing tables with ec2.CfnSubnetRouteTableAssociation. That part works.

Now I have 7 unused routing tables that I want to get rid of. How can I do that?

1 Answers

Set the removal policy to DESTROY and remove the stack from cloudformation or remove the code from cdk application.

vpc.applyRemovalPolicy(RemovalPolicy.DESTROY)
Related