Show / Hide Table of Contents

Class GetVpcs

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

Methods

View Source

InvokeAsync(GetVpcsArgs, InvokeOptions)

This resource can be useful for getting back a list of VPC Ids for a region.

The following example retrieves a list of VPC Ids with a custom tag of service set to a value of "production".

{{% examples %}}

Example Usage

{{% example %}}

The following shows outputing all VPC Ids.

using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
public MyStack()
{
    var fooVpcs = Output.Create(Aws.Ec2.GetVpcs.InvokeAsync(new Aws.Ec2.GetVpcsArgs
    {
        Tags = 
        {
            { "service", "production" },
        },
    }));
    this.Foo = fooVpcs.Apply(fooVpcs => fooVpcs.Ids);
}

[Output("foo")]
public Output<string> Foo { get; set; }
}

An example use case would be interpolate the aws.ec2.getVpcs output into count of an aws.ec2.FlowLog resource.

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

class MyStack : Stack
{
public MyStack()
{
    var dict = Output.Create(Initialize());
    this.Foo = dict.Apply(dict => dict["foo"]);
}

private async Task<IDictionary<string, Output<string>>> Initialize()
{
    var fooVpcs = await Aws.Ec2.GetVpcs.InvokeAsync();
    var testFlowLog = new List<Aws.Ec2.FlowLog>();
    for (var rangeIndex = 0; rangeIndex < fooVpcs.Ids.Length; rangeIndex++)
    {
        var range = new { Value = rangeIndex };
        testFlowLog.Add(new Aws.Ec2.FlowLog($"testFlowLog-{range.Value}", new Aws.Ec2.FlowLogArgs
        {
            VpcId = fooVpcs.Ids[range.Value],
        }));
    }
    var foo = fooVpcs.Ids;

    return new Dictionary<string, Output<string>>
    {
        { "foo", foo },
    };
}

[Output("foo")]
public Output<string> Foo { get; set; }
}

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

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