1. Packages
  2. AWS
  3. API Docs
  4. ec2
  5. getVpcs
AWS v7.11.0 published on Wednesday, Nov 5, 2025 by Pulumi

aws.ec2.getVpcs

Start a Neo task
Explain and create an aws.ec2.getVpcs resource
aws logo
AWS v7.11.0 published on Wednesday, Nov 5, 2025 by Pulumi

    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”.

    Example Usage

    The following shows outputting all VPC Ids.

    import * as pulumi from "@pulumi/pulumi";
    import * as aws from "@pulumi/aws";
    
    export = async () => {
        const foo = await aws.ec2.getVpcs({
            tags: {
                service: "production",
            },
        });
        return {
            foo: foo.ids,
        };
    }
    
    import pulumi
    import pulumi_aws as aws
    
    foo = aws.ec2.get_vpcs(tags={
        "service": "production",
    })
    pulumi.export("foo", foo.ids)
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/ec2"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		foo, err := ec2.GetVpcs(ctx, &ec2.GetVpcsArgs{
    			Tags: map[string]interface{}{
    				"service": "production",
    			},
    		}, nil)
    		if err != nil {
    			return err
    		}
    		ctx.Export("foo", foo.Ids)
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Aws = Pulumi.Aws;
    
    return await Deployment.RunAsync(() => 
    {
        var foo = Aws.Ec2.GetVpcs.Invoke(new()
        {
            Tags = 
            {
                { "service", "production" },
            },
        });
    
        return new Dictionary<string, object?>
        {
            ["foo"] = foo.Apply(getVpcsResult => getVpcsResult.Ids),
        };
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.aws.ec2.Ec2Functions;
    import com.pulumi.aws.ec2.inputs.GetVpcsArgs;
    import java.util.List;
    import java.util.ArrayList;
    import java.util.Map;
    import java.io.File;
    import java.nio.file.Files;
    import java.nio.file.Paths;
    
    public class App {
        public static void main(String[] args) {
            Pulumi.run(App::stack);
        }
    
        public static void stack(Context ctx) {
            final var foo = Ec2Functions.getVpcs(GetVpcsArgs.builder()
                .tags(Map.of("service", "production"))
                .build());
    
            ctx.export("foo", foo.ids());
        }
    }
    
    variables:
      foo:
        fn::invoke:
          function: aws:ec2:getVpcs
          arguments:
            tags:
              service: production
    outputs:
      foo: ${foo.ids}
    

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

    import * as pulumi from "@pulumi/pulumi";
    import * as aws from "@pulumi/aws";
    
    export = async () => {
        const foo = await aws.ec2.getVpcs({});
        const fooGetVpc = .map(__index => (await aws.ec2.getVpc({
            id: foo.ids[__index],
        })));
        const testFlowLog: aws.ec2.FlowLog[] = [];
    foo.ids.length.apply(rangeBody => {
            for (const range = {value: 0}; range.value < rangeBody; range.value++) {
                testFlowLog.push(new aws.ec2.FlowLog(`test_flow_log-${range.value}`, {vpcId: fooGetVpc.apply(fooGetVpc => fooGetVpc[range.value].id)}));
            }
        });
        return {
            foo: foo.ids,
        };
    }
    
    import pulumi
    import pulumi_aws as aws
    
    foo = aws.ec2.get_vpcs()
    foo_get_vpc = [aws.ec2.get_vpc(id=foo.ids[__index]) for __index in len(foo.ids).apply(lambda length: range(length))]
    test_flow_log = []
    def create_test_flow_log(range_body):
        for range in [{"value": i} for i in range(0, range_body)]:
            test_flow_log.append(aws.ec2.FlowLog(f"test_flow_log-{range['value']}", vpc_id=foo_get_vpc.apply(lambda foo_get_vpc: foo_get_vpc[range["value"]].id)))
    
    (len(foo.ids)).apply(create_test_flow_log)
    pulumi.export("foo", foo.ids)
    
    Example coming soon!
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Aws = Pulumi.Aws;
    
    return await Deployment.RunAsync(() => 
    {
        var foo = Aws.Ec2.GetVpcs.Invoke();
    
        var fooGetVpc = ;
    
        var testFlowLog = new List<Aws.Ec2.FlowLog>();
        for (var rangeIndex = 0; rangeIndex < foo.Apply(getVpcsResult => getVpcsResult.Ids).Length; rangeIndex++)
        {
            var range = new { Value = rangeIndex };
            testFlowLog.Add(new Aws.Ec2.FlowLog($"test_flow_log-{range.Value}", new()
            {
                VpcId = fooGetVpc.Apply(fooGetVpc => fooGetVpc[range.Value].Id),
            }));
        }
        return new Dictionary<string, object?>
        {
            ["foo"] = foo.Apply(getVpcsResult => getVpcsResult.Ids),
        };
    });
    
    Example coming soon!
    
    Example coming soon!
    

    Using getVpcs

    Two invocation forms are available. The direct form accepts plain arguments and either blocks until the result value is available, or returns a Promise-wrapped result. The output form accepts Input-wrapped arguments and returns an Output-wrapped result.

    function getVpcs(args: GetVpcsArgs, opts?: InvokeOptions): Promise<GetVpcsResult>
    function getVpcsOutput(args: GetVpcsOutputArgs, opts?: InvokeOptions): Output<GetVpcsResult>
    def get_vpcs(filters: Optional[Sequence[GetVpcsFilter]] = None,
                 region: Optional[str] = None,
                 tags: Optional[Mapping[str, str]] = None,
                 opts: Optional[InvokeOptions] = None) -> GetVpcsResult
    def get_vpcs_output(filters: Optional[pulumi.Input[Sequence[pulumi.Input[GetVpcsFilterArgs]]]] = None,
                 region: Optional[pulumi.Input[str]] = None,
                 tags: Optional[pulumi.Input[Mapping[str, pulumi.Input[str]]]] = None,
                 opts: Optional[InvokeOptions] = None) -> Output[GetVpcsResult]
    func GetVpcs(ctx *Context, args *GetVpcsArgs, opts ...InvokeOption) (*GetVpcsResult, error)
    func GetVpcsOutput(ctx *Context, args *GetVpcsOutputArgs, opts ...InvokeOption) GetVpcsResultOutput

    > Note: This function is named GetVpcs in the Go SDK.

    public static class GetVpcs 
    {
        public static Task<GetVpcsResult> InvokeAsync(GetVpcsArgs args, InvokeOptions? opts = null)
        public static Output<GetVpcsResult> Invoke(GetVpcsInvokeArgs args, InvokeOptions? opts = null)
    }
    public static CompletableFuture<GetVpcsResult> getVpcs(GetVpcsArgs args, InvokeOptions options)
    public static Output<GetVpcsResult> getVpcs(GetVpcsArgs args, InvokeOptions options)
    
    fn::invoke:
      function: aws:ec2/getVpcs:getVpcs
      arguments:
        # arguments dictionary

    The following arguments are supported:

    Filters List<GetVpcsFilter>
    Custom filter block as described below.
    Region string
    Region where this resource will be managed. Defaults to the Region set in the provider configuration.
    Tags Dictionary<string, string>
    Map of tags, each pair of which must exactly match a pair on the desired vpcs.
    Filters []GetVpcsFilter
    Custom filter block as described below.
    Region string
    Region where this resource will be managed. Defaults to the Region set in the provider configuration.
    Tags map[string]string
    Map of tags, each pair of which must exactly match a pair on the desired vpcs.
    filters List<GetVpcsFilter>
    Custom filter block as described below.
    region String
    Region where this resource will be managed. Defaults to the Region set in the provider configuration.
    tags Map<String,String>
    Map of tags, each pair of which must exactly match a pair on the desired vpcs.
    filters GetVpcsFilter[]
    Custom filter block as described below.
    region string
    Region where this resource will be managed. Defaults to the Region set in the provider configuration.
    tags {[key: string]: string}
    Map of tags, each pair of which must exactly match a pair on the desired vpcs.
    filters Sequence[GetVpcsFilter]
    Custom filter block as described below.
    region str
    Region where this resource will be managed. Defaults to the Region set in the provider configuration.
    tags Mapping[str, str]
    Map of tags, each pair of which must exactly match a pair on the desired vpcs.
    filters List<Property Map>
    Custom filter block as described below.
    region String
    Region where this resource will be managed. Defaults to the Region set in the provider configuration.
    tags Map<String>
    Map of tags, each pair of which must exactly match a pair on the desired vpcs.

    getVpcs Result

    The following output properties are available:

    Id string
    The provider-assigned unique ID for this managed resource.
    Ids List<string>
    List of all the VPC Ids found.
    Region string
    Tags Dictionary<string, string>
    Filters List<GetVpcsFilter>
    Id string
    The provider-assigned unique ID for this managed resource.
    Ids []string
    List of all the VPC Ids found.
    Region string
    Tags map[string]string
    Filters []GetVpcsFilter
    id String
    The provider-assigned unique ID for this managed resource.
    ids List<String>
    List of all the VPC Ids found.
    region String
    tags Map<String,String>
    filters List<GetVpcsFilter>
    id string
    The provider-assigned unique ID for this managed resource.
    ids string[]
    List of all the VPC Ids found.
    region string
    tags {[key: string]: string}
    filters GetVpcsFilter[]
    id str
    The provider-assigned unique ID for this managed resource.
    ids Sequence[str]
    List of all the VPC Ids found.
    region str
    tags Mapping[str, str]
    filters Sequence[GetVpcsFilter]
    id String
    The provider-assigned unique ID for this managed resource.
    ids List<String>
    List of all the VPC Ids found.
    region String
    tags Map<String>
    filters List<Property Map>

    Supporting Types

    GetVpcsFilter

    Name string
    Name of the field to filter by, as defined by the underlying AWS API.
    Values List<string>
    Set of values that are accepted for the given field. A VPC will be selected if any one of the given values matches.
    Name string
    Name of the field to filter by, as defined by the underlying AWS API.
    Values []string
    Set of values that are accepted for the given field. A VPC will be selected if any one of the given values matches.
    name String
    Name of the field to filter by, as defined by the underlying AWS API.
    values List<String>
    Set of values that are accepted for the given field. A VPC will be selected if any one of the given values matches.
    name string
    Name of the field to filter by, as defined by the underlying AWS API.
    values string[]
    Set of values that are accepted for the given field. A VPC will be selected if any one of the given values matches.
    name str
    Name of the field to filter by, as defined by the underlying AWS API.
    values Sequence[str]
    Set of values that are accepted for the given field. A VPC will be selected if any one of the given values matches.
    name String
    Name of the field to filter by, as defined by the underlying AWS API.
    values List<String>
    Set of values that are accepted for the given field. A VPC will be selected if any one of the given values matches.

    Package Details

    Repository
    AWS Classic pulumi/pulumi-aws
    License
    Apache-2.0
    Notes
    This Pulumi package is based on the aws Terraform Provider.
    aws logo
    AWS v7.11.0 published on Wednesday, Nov 5, 2025 by Pulumi
      Meet Neo: Your AI Platform Teammate