Hi , I'm trying to create a vpc and subnets in spe...
# aws
h
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
Hi @hundreds-receptionist-31352, The following will work:
Copy code
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
thanks! in that case the cidr block for every subnet can be calculated automatically or I need to calculate it by myself?
c
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:
Copy code
const number_of_nat_gateways = config.requireNumber("number_of_nat_gateways");
and then later in the vpc construct you have:
Copy code
numberOfNatGateways: number_of_nat_gateways,
b
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
thanks!!!