-
-
Save jen20/2d8451034c0a15858af8561f69a79ac4 to your computer and use it in GitHub Desktop.
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
import * as aws from "@pulumi/aws"; | |
import {SubnetDistributor} from "./subnetDistributor"; | |
import {Output} from "@pulumi/pulumi"; | |
interface StackOutputs { | |
privateSubnetIds: Output<string>[] | |
publicSubnetIds: Output<string>[] | |
} | |
async function main(): Promise<StackOutputs> { | |
const baseCidr = "10.0.0.0/16"; | |
const baseTags = { | |
Project: "Distributor" | |
}; | |
const azCount = (await aws.getAvailabilityZones()).names.length; | |
const subnetDistributor = new SubnetDistributor(baseCidr, azCount); | |
const vpc = new aws.ec2.Vpc("vpc", { | |
cidrBlock: baseCidr, | |
enableDnsSupport: true, | |
enableDnsHostnames: true, | |
tags: baseTags | |
}); | |
const privateSubnets = subnetDistributor.privateSubnets().map((cidr, index) => { | |
return new aws.ec2.Subnet(`private-subnet-${index + 1}`, { | |
vpcId: vpc.id, | |
cidrBlock: cidr, | |
mapPublicIpOnLaunch: false, | |
tags: baseTags | |
}); | |
}); | |
const publicSubnets = subnetDistributor.publicSubnets().map((cidr, index) => { | |
return new aws.ec2.Subnet(`public-subnet-${index + 1}`, { | |
vpcId: vpc.id, | |
cidrBlock: cidr, | |
mapPublicIpOnLaunch: false, | |
tags: baseTags | |
}); | |
}); | |
return { | |
privateSubnetIds: privateSubnets.map(subnet => subnet.id), | |
publicSubnetIds: publicSubnets.map(subnet => subnet.id) | |
} | |
} | |
const outputs = main(); | |
export const privateSubnetIds = outputs.then(o => o.privateSubnetIds); | |
export const publicSubnetIds = outputs.then(o => o.publicSubnetIds); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment