How to use the @pulumi/aws.getAvailabilityZones function in @pulumi/aws

To help you get started, we’ve selected a few @pulumi/aws examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pulumi / tf2pulumi / gen / nodejs / testdata / test_comments / index.17.ts View on Github external
//
// Note that the VPC has been tagged appropriately.
const defaultVpc = new aws.ec2.Vpc("default", {
    cidrBlock: "10.0.0.0/16", // Just one CIDR block
    enableDnsHostnames: true, // Definitely want DNS hostnames.
    // The tag collection for this VPC.
    tags: {
        // Ensure that we tag this VPC with a Name.
        Name: "test",
    },
});
// Use some data sources.
const defaultSubnetIds = defaultVpc.id.apply(id => aws.ec2.getSubnetIds({
    vpcId: id,
}, { async: true }));
const defaultAvailabilityZones = pulumi.output(aws.getAvailabilityZones({ async: true }));
const defaultAvailabilityZone: pulumi.Output[] = [];
for (let i = 0; i < defaultAvailabilityZones.apply(defaultAvailabilityZones => defaultAvailabilityZones.ids.length); i++) {
    defaultAvailabilityZone.push(defaultAvailabilityZones.apply(defaultAvailabilityZones => aws.getAvailabilityZone({
        zoneId: defaultAvailabilityZones.zoneIds[i],
    }, { async: true })));
}
// The VPC details
const vpc = [{
    // The ID
    id: defaultVpc.id,
}];
// The region, again
const region = awsRegion; // why not
// Create a security group.
//
// This group should allow SSH and HTTP access.
github jen20 / pulumi-aws-vpc / src / index.ts View on Github external
}, inputs.baseTags);
        const internetGateway = new aws.ec2.InternetGateway(`${baseName}-igw`, {
            vpcId: vpc.id,
            tags: internetGatewayTags,
        }, vpcParent);

        // Subnet Distributor
        let distributor: SubnetDistributor;
        if (typeof inputs.azCount === "number") {
            distributor = SubnetDistributor.fixedCount(inputs.baseCidr, inputs.azCount);
        } else {
            distributor = await SubnetDistributor.perAz(inputs.baseCidr);
        }

        // Find AZ names
        let azNames = (await aws.getAvailabilityZones({
            state: "available",
        })).names;

        // Public Subnets
        const publicSubnets = (await distributor.publicSubnets()).map((cidr, index) => {
            const subnetTags = Object.assign({
                Name: `${inputs.description} Public ${index + 1}`,
            }, inputs.baseTags);
            return new aws.ec2.Subnet(`${baseName}-public-${index + 1}`, {
                vpcId: vpc.id,
                cidrBlock: cidr,
                mapPublicIpOnLaunch: false,
                availabilityZone: azNames[index],
                tags: subnetTags,
            }, vpcParent);
        });
github jen20 / pulumi-aws-vpc / dist / index.js View on Github external
Name: `${inputs.description} VPC IG`,
            }, inputs.baseTags);
            const internetGateway = new aws.ec2.InternetGateway(`${baseName}-igw`, {
                vpcId: vpc.id,
                tags: internetGatewayTags,
            }, vpcParent);
            // Subnet Distributor
            let distributor;
            if (typeof inputs.azCount === "number") {
                distributor = subnetDistributor_1.SubnetDistributor.fixedCount(inputs.baseCidr, inputs.azCount);
            }
            else {
                distributor = yield subnetDistributor_1.SubnetDistributor.perAz(inputs.baseCidr);
            }
            // Find AZ names
            let azNames = (yield aws.getAvailabilityZones({
                state: "available",
            })).names;
            // Public Subnets
            const publicSubnets = (yield distributor.publicSubnets()).map((cidr, index) => {
                const subnetTags = Object.assign({
                    Name: `${inputs.description} Public ${index + 1}`,
                }, inputs.baseTags);
                return new aws.ec2.Subnet(`${baseName}-public-${index + 1}`, {
                    vpcId: vpc.id,
                    cidrBlock: cidr,
                    mapPublicIpOnLaunch: false,
                    availabilityZone: azNames[index],
                    tags: subnetTags,
                }, vpcParent);
            });
            instance.publicSubnetIds = publicSubnets.map(subnet => subnet.id);
github pulumi / pulumi-cloud / aws-infra / aws.ts View on Github external
export async function getAwsAz(index: number) {
    if (!azs) {
        azs = aws.getAvailabilityZones();
    }
    return (await azs).names[index];
}
github pulumi / infrastructure-as-code-workshop / labs / aws / typescript / lab-02 / code / step4.ts View on Github external
const sg = new aws.ec2.SecurityGroup("web-secgrp", {
    ingress: [
        { protocol: "icmp", fromPort: 8, toPort: 0, cidrBlocks: ["0.0.0.0/0"] },
    ],
});

const alb = new awsx.lb.ApplicationLoadBalancer("web-traffic", {
    external: true,
    securityGroups: [ sg.id ],
});
const listener = alb.createListener("web-listener", { port: 80 });

export const ips: any[] = [];
export const hostnames: any[] = [];
for (const az of aws.getAvailabilityZones().names) {
    const server = new aws.ec2.Instance(`web-server-${az}`, {
        instanceType: "t2.micro",
        securityGroups: alb.securityGroups.map(sg => sg.securityGroup.name),
        ami: ami,
        availabilityZone: az,
        userData: "#!/bin/bash\n"+
            `echo 'Hello, World -- from ${az}!' > index.html\n` +
            "nohup python -m SimpleHTTPServer 80 &",
        tags: { "Name": "web-server" },
    });
    ips.push(server.publicIp);
    hostnames.push(server.publicDns);

    alb.attachTarget(`web-target-${az}`, server);
}
github pulumi / pulumi-awsx / nodejs / awsx / aws.ts View on Github external
export function getAvailabilityZones(): Promise {
    if (!zones) {
        zones = aws.getAvailabilityZones().then(r => r.names);
    }

    return zones;
}
github pulumi / infrastructure-as-code-workshop / labs / aws / typescript / lab-02 / code / step3.ts View on Github external
const ami = aws.getAmi({
    filters: [{ name: "name", values: ["amzn-ami-hvm-*-x86_64-ebs"] }],
    owners: [ "137112412989" ],
    mostRecent: true,
}).then(ami => ami.id);

const sg = new aws.ec2.SecurityGroup("web-secgrp", {
    ingress: [
        { protocol: "icmp", fromPort: 8, toPort: 0, cidrBlocks: ["0.0.0.0/0"] },
        { protocol: "tcp", fromPort: 80, toPort: 80, cidrBlocks: ["0.0.0.0/0"] },
    ],
});

export const ips: any[] = [];
export const hostnames: any[] = [];
for (const az of aws.getAvailabilityZones().names) {
    const server = new aws.ec2.Instance(`web-server-${az}`, {
        instanceType: "t2.micro",
        securityGroups: [ sg.name ],
        ami: ami,
        availabilityZone: az,
        userData: "#!/bin/bash\n"+
            `echo 'Hello, World -- from ${az}!' > index.html\n` +
            "nohup python -m SimpleHTTPServer 80 &",
        tags: { "Name": "web-server" },
    });
    ips.push(server.publicIp);
    hostnames.push(server.publicDns);
}
github pulumi / examples / aws-stackreference-architecture / networking / src / index.ts View on Github external
async function main() {
    const config = new Config();

    const azCount = config.getNumber("azCount") || 2;

    const baseTags = {
        ManagedBy: "Pulumi",
        PulumiStack: getStack(),
    };
    const availabilityZones = aws.getAvailabilityZones({
        state: "available",
    }, { async: true });

    const appVpc = new Vpc("app-vpc", {
        description: `${baseTags.ManagedBy} App VPC`,
        baseTags: baseTags,

        baseCidr: "172.28.0.0/16",
        availabilityZoneNames: availabilityZones.names.slice(0, azCount),
        enableFlowLogs: true,

        endpoints: {
            s3: true,
            dynamodb: true,
        },
    });
github pulumi / pulumi-awsx / nodejs / aws-infra / aws.ts View on Github external
export async function getAwsAz(index: number) {
    if (!azs) {
        azs = aws.getAvailabilityZones();
    }
    return (await azs).names[index];
}