getSubnetIds

aws.ec2.getSubnetIds provides a set of ids for a vpc_id

This resource can be useful for getting back a set of subnet ids for a vpc.

Example Usage

using System.Collections.Generic;
using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
    public MyStack()
    {
        var @private = Output.Create(Aws.Ec2.GetSubnetIds.InvokeAsync(new Aws.Ec2.GetSubnetIdsArgs
        {
            VpcId = @var.Vpc_id,
            Tags = 
            {
                { "Tier", "Private" },
            },
        }));
        var app = new List<Aws.Ec2.Instance>();
        for (var rangeIndex = 0; rangeIndex < data.Aws_subnet_ids.Example.Ids; rangeIndex++)
        {
            var range = new { Value = rangeIndex };
            app.Add(new Aws.Ec2.Instance($"app-{range.Value}", new Aws.Ec2.InstanceArgs
            {
                Ami = @var.Ami,
                InstanceType = "t2.micro",
                SubnetId = range.Value,
            }));
        }
    }

}
package main

import (
	"github.com/pulumi/pulumi-aws/sdk/v4/go/aws/ec2"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := ec2.GetSubnetIds(ctx, &ec2.GetSubnetIdsArgs{
			VpcId: _var.Vpc_id,
			Tags: map[string]interface{}{
				"Tier": "Private",
			},
		}, nil)
		if err != nil {
			return err
		}
		var app []*ec2.Instance
		for key0, val0 := range data.Aws_subnet_ids.Example.Ids {
			__res, err := ec2.NewInstance(ctx, fmt.Sprintf("app-%v", key0), &ec2.InstanceArgs{
				Ami:          pulumi.Any(_var.Ami),
				InstanceType: pulumi.String("t2.micro"),
				SubnetId:     pulumi.Any(val0),
			})
			if err != nil {
				return err
			}
			app = append(app, __res)
		}
		return nil
	})
}
import pulumi
import pulumi_aws as aws

example_subnet_ids = aws.ec2.get_subnet_ids(vpc_id=var["vpc_id"])
example_subnet = [aws.ec2.get_subnet(id=__value) for __key, __value in example_subnet_ids.ids]
pulumi.export("subnetCidrBlocks", [s.cidr_block for s in example_subnet])
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const exampleSubnetIds = aws.ec2.getSubnetIds({
    vpcId: _var.vpc_id,
});
const exampleSubnet = exampleSubnetIds.then(exampleSubnetIds => exampleSubnetIds.ids.map((v, k) => [k, v]).map(([, ]) => aws.ec2.getSubnet({
    id: __value,
})));
export const subnetCidrBlocks = exampleSubnet.map(s => s.cidrBlock);

Using getSubnetIds

function getSubnetIds(args: GetSubnetIdsArgs, opts?: InvokeOptions): Promise<GetSubnetIdsResult>
def get_subnet_ids(filters: Optional[Sequence[GetSubnetIdsFilter]] = None,
                   tags: Optional[Mapping[str, str]] = None,
                   vpc_id: Optional[str] = None,
                   opts: Optional[InvokeOptions] = None) -> GetSubnetIdsResult
func GetSubnetIds(ctx *Context, args *GetSubnetIdsArgs, opts ...InvokeOption) (*GetSubnetIdsResult, error)

Note: This function is named GetSubnetIds in the Go SDK.

public static class GetSubnetIds {
    public static Task<GetSubnetIdsResult> InvokeAsync(GetSubnetIdsArgs args, InvokeOptions? opts = null)
}

The following arguments are supported:

VpcId string
The VPC ID that you want to filter from.
Filters List<GetSubnetIdsFilter>
Custom filter block as described below.
Tags Dictionary<string, string>
A map of tags, each pair of which must exactly match a pair on the desired subnets.
VpcId string
The VPC ID that you want to filter from.
Filters []GetSubnetIdsFilter
Custom filter block as described below.
Tags map[string]string
A map of tags, each pair of which must exactly match a pair on the desired subnets.
vpcId string
The VPC ID that you want to filter from.
filters GetSubnetIdsFilter[]
Custom filter block as described below.
tags {[key: string]: string}
A map of tags, each pair of which must exactly match a pair on the desired subnets.
vpc_id str
The VPC ID that you want to filter from.
filters Sequence[GetSubnetIdsFilter]
Custom filter block as described below.
tags Mapping[str, str]
A map of tags, each pair of which must exactly match a pair on the desired subnets.

getSubnetIds Result

The following output properties are available:

Id string
The provider-assigned unique ID for this managed resource.
Ids List<string>
A set of all the subnet ids found. This data source will fail if none are found.
Tags Dictionary<string, string>
VpcId string
Filters List<GetSubnetIdsFilter>
Id string
The provider-assigned unique ID for this managed resource.
Ids []string
A set of all the subnet ids found. This data source will fail if none are found.
Tags map[string]string
VpcId string
Filters []GetSubnetIdsFilter
id string
The provider-assigned unique ID for this managed resource.
ids string[]
A set of all the subnet ids found. This data source will fail if none are found.
tags {[key: string]: string}
vpcId string
filters GetSubnetIdsFilter[]
id str
The provider-assigned unique ID for this managed resource.
ids Sequence[str]
A set of all the subnet ids found. This data source will fail if none are found.
tags Mapping[str, str]
vpc_id str
filters Sequence[GetSubnetIdsFilter]

Supporting Types

GetSubnetIdsFilter

Name string
The name of the field to filter by, as defined by the underlying AWS API. For example, if matching against tag Name, use:
Values List<string>
Set of values that are accepted for the given field. Subnet IDs will be selected if any one of the given values match.
Name string
The name of the field to filter by, as defined by the underlying AWS API. For example, if matching against tag Name, use:
Values []string
Set of values that are accepted for the given field. Subnet IDs will be selected if any one of the given values match.
name string
The name of the field to filter by, as defined by the underlying AWS API. For example, if matching against tag Name, use:
values string[]
Set of values that are accepted for the given field. Subnet IDs will be selected if any one of the given values match.
name str
The name of the field to filter by, as defined by the underlying AWS API. For example, if matching against tag Name, use:
values Sequence[str]
Set of values that are accepted for the given field. Subnet IDs will be selected if any one of the given values match.

Package Details

Repository
https://github.com/pulumi/pulumi-aws
License
Apache-2.0
Notes
This Pulumi package is based on the aws Terraform Provider.