Skip to content

Commit

Permalink
fix: ipv6AssignAddressOnCreation(true) on isolated subnet causes depl…
Browse files Browse the repository at this point in the history
…oy error
  • Loading branch information
badmintoncryer committed Jan 29, 2024
1 parent 6a7a24a commit 89e41cf
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/aws-cdk-lib/aws-ec2/lib/vpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1801,6 +1801,11 @@ export class Vpc extends VpcBase {
privateSubnet.node.addDependency(this.ipv6CidrBlock);
}
});
(this.isolatedSubnets as PrivateSubnet[]).forEach((isolatedSubnet) => {
if (this.ipv6CidrBlock !== undefined) {
isolatedSubnet.node.addDependency(this.ipv6CidrBlock);
}
});
}
}

Expand Down
32 changes: 32 additions & 0 deletions packages/aws-cdk-lib/aws-ec2/test/vpc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1330,6 +1330,38 @@ describe('vpc', () => {

Template.fromStack(stack).resourceCountIs('Custom::VpcRestrictDefaultSG', 0);
});

test.each(
[
{
subnetType: SubnetType.PRIVATE_ISOLATED,
},
{
subnetType: SubnetType.PRIVATE_WITH_EGRESS,
additionalSubnetConfig: [{ subnetType: SubnetType.PUBLIC, name: 'public' }],
},
{
subnetType: SubnetType.PUBLIC,
},
],
)('subnet has dependent on the CIDR block when ipv6AssignAddressOnCreation is set to true, ', (testData) => {
const stack = getTestStack();
new Vpc(stack, 'TheVPC', {
ipProtocol: IpProtocol.DUAL_STACK,
maxAzs: 1,
subnetConfiguration: [
{
subnetType: testData.subnetType,
name: 'subnetName',
ipv6AssignAddressOnCreation: true,
},
...testData.additionalSubnetConfig ?? [],
],
});
Template.fromStack(stack).hasResource('AWS::EC2::Subnet', {
DependsOn: ['TheVPCipv6cidrF3E84E30'],
});
});
});

describe('fromVpcAttributes', () => {
Expand Down

0 comments on commit 89e41cf

Please sign in to comment.