Show / Hide Table of Contents

Class GetSubnet

Inheritance
System.Object
GetSubnet
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 GetSubnet

Methods

View Source

InvokeAsync(GetSubnetArgs, InvokeOptions)

aws.ec2.Subnet provides details about a specific VPC subnet.

This resource can prove useful when a module accepts a subnet id as an input variable and needs to, for example, determine the id of the VPC that the subnet belongs to.

{{% examples %}}

Example Usage

{{% example %}}

The following example shows how one might accept a subnet id as a variable and use this data source to obtain the data necessary to create a security group that allows connections from hosts in that subnet.

using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
public MyStack()
{
    var config = new Config();
    var subnetId = config.RequireObject<dynamic>("subnetId");
    var selected = Output.Create(Aws.Ec2.GetSubnet.InvokeAsync(new Aws.Ec2.GetSubnetArgs
    {
        Id = subnetId,
    }));
    var subnet = new Aws.Ec2.SecurityGroup("subnet", new Aws.Ec2.SecurityGroupArgs
    {
        Ingress = 
        {
            new Aws.Ec2.Inputs.SecurityGroupIngressArgs
            {
                CidrBlocks = 
                {
                    selected.Apply(selected => selected.CidrBlock),
                },
                FromPort = 80,
                Protocol = "tcp",
                ToPort = 80,
            },
        },
        VpcId = selected.Apply(selected => selected.VpcId),
    });
}

}

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

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