https://pulumi.com logo
Title
h

hundreds-receptionist-31352

09/08/2020, 12:35 PM
Hi , I'm trying to create a vpc and subnets in specific AZ, I'm using de awsx.ec2.vpc library, I would like to know if there is some way to choose the AZ, I have tried it but it didn't work: const vpc = new awsx.ec2.Vpc("cloud-pulumi", { cidrBlock: vpcCidr, subnets: [ { type: "public" , name: "public" , location: { availabilityZone: "us-east-1a,us-east-1b", } }, { type: "private" , name: "application" ,location: { availabilityZone: "us-east-1a,us-east-1b", } } ], });
c

cool-fireman-90027

09/08/2020, 4:05 PM
Hi @hundreds-receptionist-31352, The following will work:
const vpc = new awsx.ec2.Vpc(`${vpc_name}`, {
    cidrBlock: vpc_cidr,
    numberOfNatGateways: number_of_nat_gateways,
    subnets: [
        { type: "public", name: "pulumi-public-web-1", location: {cidrBlock: "10.0.0.0/24",availabilityZone: "us-east-1e" }},
        { type: "public", name: "pulumi-public-web-2", location: {cidrBlock:"10.0.1.0/24", availabilityZone:  "us-east-1e"}},
        { type: "private", name: "pulumi-private-apps-1", location: {cidrBlock:"10.0.2.0/24", availabilityZone:  "us-east-1d"}},
        { type: "private", name: "pulumi-private-apps-2", location: {cidrBlock:"10.0.3.0/25", availabilityZone:  "us-east-1e"}},
        { type: "private", name: "pulumi-private-databases", location: {cidrBlock:"10.0.3.128/25", availabilityZone:  "us-east-1f"}},   
    ]
});
h

hundreds-receptionist-31352

09/08/2020, 5:09 PM
thanks! in that case the cidr block for every subnet can be calculated automatically or I need to calculate it by myself?
c

cool-fireman-90027

09/08/2020, 5:56 PM
You would have to calculate the cidr block for every subnet. If you don't want to calculate the cidr block, then you could use
all
of the az's to have it spread them all. https://www.pulumi.com/docs/reference/pkg/nodejs/pulumi/awsx/ec2/#VpcArgs-numberOfAvailabilityZones You could add/set the subnets as a variable in the config file: pulumi config set subnet_1_cidr 10.0.0.0/.. pulumi config set subnet_1_cidr 10.0.0.1/.. and then you could read it into you index.ts like this:
const number_of_nat_gateways = config.requireNumber("number_of_nat_gateways");
and then later in the vpc construct you have:
numberOfNatGateways: number_of_nat_gateways,
b

billowy-army-68599

09/08/2020, 6:01 PM
there's a third party module that creates a VPC that includes a subnet calculator: https://github.com/jen20/pulumi-aws-vpc/blob/master/nodejs/src/subnetDistributor.ts
h

hundreds-receptionist-31352

09/08/2020, 6:58 PM
thanks!!!