-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In #1791 we \"fixed\" the cidr function so that it would generate subnets correctly. We did not fix it correctly though. This cidr function needs to match the logic that the CloudFormation Fn::Cidr function has. Critically the `cidrBits` logic was incorrect. It should be the inverse of the subnet mask that you want to have for the subnets. For example a `cidrBits` of 5 means that I want subnets with a mask of `/27` (32-5=27). ```ts cidr({ ipBlock: '192.168.0.0/24', count: 6, cidrBits: 5, }); ```
- Loading branch information
Showing
7 changed files
with
152 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
name: aws-cidr-ts | ||
runtime: nodejs | ||
description: A TypeScript Pulumi program with AWS Cloud Control provider |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright 2016-2024, Pulumi Corporation. | ||
|
||
import * as pulumi from '@pulumi/pulumi'; | ||
import * as aws from "@pulumi/aws-native"; | ||
|
||
const cidrBlock = '192.168.0.0/24'; | ||
const vpc = new aws.ec2.Vpc('vpc', { | ||
cidrBlock, | ||
}); | ||
|
||
const ipv6Cidr = new aws.ec2.VpcCidrBlock('ipv6Cidr', { | ||
vpcId: vpc.vpcId, | ||
amazonProvidedIpv6CidrBlock: true, | ||
}); | ||
|
||
|
||
const cidrs = aws.cidrOutput({ | ||
count: 4, | ||
ipBlock: cidrBlock, | ||
cidrBits: 5 | ||
}); | ||
const ipvcCidrs = aws.cidrOutput({ | ||
ipBlock: ipv6Cidr.ipv6CidrBlock.apply(cidr => cidr!), | ||
cidrBits: 64, | ||
count: 4, | ||
}); | ||
|
||
ipvcCidrs.apply(cidr => { | ||
if (cidr.subnets.length !== 4) { | ||
throw new Error('Expected 4 ipv6 CIDRs'); | ||
} | ||
}) | ||
|
||
cidrs.apply(cidr => { | ||
if (cidr.subnets.length !== 4) { | ||
throw new Error('Expected 4 ipv4 CIDRs'); | ||
} | ||
}) | ||
|
||
pulumi.all([cidrs.subnets, ipvcCidrs.subnets]).apply(([ipv4, ipv6]) => { | ||
for (let i = 0; i < 4; i++) { | ||
new aws.ec2.Subnet(`subnet-${i}`, { | ||
vpcId: vpc.id, | ||
cidrBlock: ipv4[i], | ||
ipv6CidrBlock: ipv6[i] | ||
}, { dependsOn: [ipv6Cidr]}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "aws-cidr-ts", | ||
"devDependencies": { | ||
"@types/node": "^8.0.0" | ||
}, | ||
"dependencies": { | ||
"@pulumi/pulumi": "^3.136.0" | ||
}, | ||
"peerDependencies": { | ||
"@pulumi/aws-native": "dev" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"compilerOptions": { | ||
"strict": true, | ||
"outDir": "bin", | ||
"target": "es2016", | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"sourceMap": true, | ||
"experimentalDecorators": true, | ||
"pretty": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"noImplicitReturns": true, | ||
"forceConsistentCasingInFileNames": true | ||
}, | ||
"files": [ | ||
"index.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters