I have a CFN stack for my VPC where I first create only public and private subnets, which get assigned default CIDR blocks. Now after a while I need to add isolated subnets to the VPC as well. When I try to update the CFN stack, I get an exception – "The CIDR '10.0.0.0/25' conflicts with another subnet
Is it possible to reassign the CIDR blocks to the subnets after adding more subnets in CFN stack update?
Here’s sample code:
if (<some condition>){
this.createVpcWithIsolatedSubnets();
} else {
this.createVpc()
}
createVpc() {
const vpc = new ec2.Vpc(this, `VPC`, {
maxAzs: MAX_AZ,
subnetConfiguration: [
{
name: 'Public',
subnetType: ec2.SubnetType.PUBLIC
},
{
name: 'Private',
subnetType: ec2.SubnetType.PRIVATE_WITH_EGRESS
}
]
});
}
createVpcWithIsolatedSubnets() {
const vpc = new ec2.Vpc(this, `VPC`, {
maxAzs: MAX_AZ,
subnetConfiguration: [
{
name: 'Public',
subnetType: ec2.SubnetType.PUBLIC
},
{
name: 'Private',
subnetType: ec2.SubnetType.PRIVATE_WITH_EGRESS
},
{
name: 'Isolated',
subnetType: ec2.SubnetType.PRIVATE_ISOLATED
}
]
});
}