UNPKG

@pulumi/aws

Version:

A Pulumi package for creating and managing Amazon Web Services (AWS) cloud resources.

144 lines 4.85 kB
"use strict"; // *** WARNING: this file was generated by pulumi-language-nodejs. *** // *** Do not edit by hand unless you're certain you know what you are doing! *** Object.defineProperty(exports, "__esModule", { value: true }); exports.getSubnetsOutput = exports.getSubnets = void 0; const pulumi = require("@pulumi/pulumi"); const utilities = require("../utilities"); /** * This resource can be useful for getting back a set of subnet IDs. * * ## Example Usage * * The following shows outputting all CIDR blocks for every subnet ID in a VPC. * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as aws from "@pulumi/aws"; * import * as std from "@pulumi/std"; * * const example = aws.ec2.getSubnets({ * filters: [{ * name: "vpc-id", * values: [vpcId], * }], * }); * const exampleGetSubnet = example.then(example => std.toset({ * input: example.ids, * })).then(invoke => .reduce((__obj, [__key, __value]) => ({ ...__obj, [__key]: aws.ec2.getSubnet({ * id: __value, * }) }))); * export const subnetCidrBlocks = exampleGetSubnet.apply(exampleGetSubnet => Object.values(exampleGetSubnet).map(s => (s.cidrBlock))); * ``` * * The following example retrieves a set of all subnets in a VPC with a custom * tag of `Tier` set to a value of "Private" so that the `aws.ec2.Instance` resource * can loop through the subnets, putting instances across availability zones. * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as aws from "@pulumi/aws"; * import * as std from "@pulumi/std"; * * export = async () => { * const _private = await aws.ec2.getSubnets({ * filters: [{ * name: "vpc-id", * values: [vpcId], * }], * tags: { * Tier: "Private", * }, * }); * const app: aws.ec2.Instance[] = []; * for (const range of std.toset({ * input: _private.ids, * }).result.map((v, k) => ({key: k, value: v}))) { * app.push(new aws.ec2.Instance(`app-${range.key}`, { * ami: ami, * instanceType: aws.ec2.InstanceType.T2_Micro, * subnetId: range.value, * })); * } * } * ``` */ function getSubnets(args, opts) { args = args || {}; opts = pulumi.mergeOptions(utilities.resourceOptsDefaults(), opts || {}); return pulumi.runtime.invoke("aws:ec2/getSubnets:getSubnets", { "filters": args.filters, "region": args.region, "tags": args.tags, }, opts); } exports.getSubnets = getSubnets; /** * This resource can be useful for getting back a set of subnet IDs. * * ## Example Usage * * The following shows outputting all CIDR blocks for every subnet ID in a VPC. * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as aws from "@pulumi/aws"; * import * as std from "@pulumi/std"; * * const example = aws.ec2.getSubnets({ * filters: [{ * name: "vpc-id", * values: [vpcId], * }], * }); * const exampleGetSubnet = example.then(example => std.toset({ * input: example.ids, * })).then(invoke => .reduce((__obj, [__key, __value]) => ({ ...__obj, [__key]: aws.ec2.getSubnet({ * id: __value, * }) }))); * export const subnetCidrBlocks = exampleGetSubnet.apply(exampleGetSubnet => Object.values(exampleGetSubnet).map(s => (s.cidrBlock))); * ``` * * The following example retrieves a set of all subnets in a VPC with a custom * tag of `Tier` set to a value of "Private" so that the `aws.ec2.Instance` resource * can loop through the subnets, putting instances across availability zones. * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as aws from "@pulumi/aws"; * import * as std from "@pulumi/std"; * * export = async () => { * const _private = await aws.ec2.getSubnets({ * filters: [{ * name: "vpc-id", * values: [vpcId], * }], * tags: { * Tier: "Private", * }, * }); * const app: aws.ec2.Instance[] = []; * for (const range of std.toset({ * input: _private.ids, * }).result.map((v, k) => ({key: k, value: v}))) { * app.push(new aws.ec2.Instance(`app-${range.key}`, { * ami: ami, * instanceType: aws.ec2.InstanceType.T2_Micro, * subnetId: range.value, * })); * } * } * ``` */ function getSubnetsOutput(args, opts) { args = args || {}; opts = pulumi.mergeOptions(utilities.resourceOptsDefaults(), opts || {}); return pulumi.runtime.invokeOutput("aws:ec2/getSubnets:getSubnets", { "filters": args.filters, "region": args.region, "tags": args.tags, }, opts); } exports.getSubnetsOutput = getSubnetsOutput; //# sourceMappingURL=getSubnets.js.map