Show / Hide Table of Contents

Class GetSubnetIds

Inheritance
System.Object
GetSubnetIds
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: Pulumi.Aws.Ec2
Assembly: Pulumi.Aws.dll
Syntax
public static class GetSubnetIds

Methods

View Source

InvokeAsync(GetSubnetIdsArgs, InvokeOptions)

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.

{{% examples %}}

Example Usage

{{% example %}}

The following shows outputing all cidr blocks for every subnet id in a vpc.

using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
public MyStack()
{
    var exampleSubnetIds = Output.Create(Aws.Ec2.GetSubnetIds.InvokeAsync(new Aws.Ec2.GetSubnetIdsArgs
    {
        VpcId = @var.Vpc_id,
    }));
    var exampleSubnet = exampleSubnetIds.Apply(exampleSubnetIds => "TODO: ForExpression");
    this.SubnetCidrBlocks = "TODO: ForExpression";
}

[Output("subnetCidrBlocks")]
public Output<string> SubnetCidrBlocks { get; set; }
}

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.

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,
        }));
    }
}

}

{{% /example %}} {{% /examples %}}

Declaration
public static Task<GetSubnetIdsResult> InvokeAsync(GetSubnetIdsArgs args, InvokeOptions options = null)
Parameters
Type Name Description
GetSubnetIdsArgs args
InvokeOptions options
Returns
Type Description
System.Threading.Tasks.Task<GetSubnetIdsResult>
  • View Source
Back to top Copyright 2016-2020, Pulumi Corporation.