1. Packages
  2. AWS
  3. API Docs
  4. ec2
  5. getSubnetIds
Viewing docs for AWS v5.43.0 (Older version)
published on Tuesday, Mar 10, 2026 by Pulumi
aws logo
Viewing docs for AWS v5.43.0 (Older version)
published on Tuesday, Mar 10, 2026 by Pulumi

    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.

    NOTE: The aws.ec2.getSubnetIds data source has been deprecated and will be removed in a future version. Use the aws.ec2.getSubnets data source instead.

    Example Usage

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

    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Aws = Pulumi.Aws;
    
    return await Deployment.RunAsync(() => 
    {
        var exampleSubnetIds = Aws.Ec2.GetSubnetIds.Invoke(new()
        {
            VpcId = @var.Vpc_id,
        });
    
        var exampleSubnet = .Select(__value => 
        {
            return  Aws.Ec2.GetSubnet.Invoke(new()
            {
                Id = __value,
            });
        });
    
        return new Dictionary<string, object?>
        {
            ["subnetCidrBlocks"] = exampleSubnet.Select(s => 
            {
                return  s.CidrBlock;
            }),
        };
    });
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-aws/sdk/v5/go/aws/ec2"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		exampleSubnetIds, err := ec2.GetSubnetIds(ctx, &ec2.GetSubnetIdsArgs{
    			VpcId: _var.Vpc_id,
    		}, nil)
    		if err != nil {
    			return err
    		}
    		exampleSubnet := "TODO: For expression"
    		ctx.Export("subnetCidrBlocks", "TODO: For expression")
    		return nil
    	})
    }
    

    Example coming soon!

    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 => .map(([, ]) => (aws.ec2.getSubnet({
        id: __value,
    }))));
    export const subnetCidrBlocks = exampleSubnet.map(s => (s.cidrBlock));
    
    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])
    

    Example coming soon!

    can loop through the subnets, putting instances across availability zones.

    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using Pulumi;
    using Aws = Pulumi.Aws;
    
    return await Deployment.RunAsync(async() => 
    {
        var @private = await Aws.Ec2.GetSubnetIds.InvokeAsync(new()
        {
            VpcId = @var.Vpc_id,
            Tags = 
            {
                { "Tier", "Private" },
            },
        });
    
        var app = new List<Aws.Ec2.Instance>();
        foreach (var range in )
        {
            app.Add(new Aws.Ec2.Instance($"app-{range.Key}", new()
            {
                Ami = @var.Ami,
                InstanceType = "t2.micro",
                SubnetId = range.Value,
            }));
        }
    });
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-aws/sdk/v5/go/aws/ec2"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		private, 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 private.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.String(val0),
    			})
    			if err != nil {
    				return err
    			}
    			app = append(app, __res)
    		}
    		return nil
    	})
    }
    
    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.GetSubnetIdsArgs;
    import com.pulumi.aws.ec2.Instance;
    import com.pulumi.aws.ec2.InstanceArgs;
    import com.pulumi.codegen.internal.KeyedValue;
    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 private = Ec2Functions.getSubnetIds(GetSubnetIdsArgs.builder()
                .vpcId(var_.vpc_id())
                .tags(Map.of("Tier", "Private"))
                .build());
    
            final var app = private.applyValue(getSubnetIdsResult -> {
                final var resources = new ArrayList<Instance>();
                for (var range : KeyedValue.of(getSubnetIdsResult.ids()) {
                    var resource = new Instance("app-" + range.key(), InstanceArgs.builder()                
                        .ami(var_.ami())
                        .instanceType("t2.micro")
                        .subnetId(range.value())
                        .build());
    
                    resources.add(resource);
                }
    
                return resources;
            });
    
        }
    }
    
    import * as pulumi from "@pulumi/pulumi";
    import * as aws from "@pulumi/aws";
    
    export = async () => {
        const private = await aws.ec2.getSubnetIds({
            vpcId: _var.vpc_id,
            tags: {
                Tier: "Private",
            },
        });
        const app: aws.ec2.Instance[] = [];
        for (const range of _private.ids.map((v, k) => ({key: k, value: v}))) {
            app.push(new aws.ec2.Instance(`app-${range.key}`, {
                ami: _var.ami,
                instanceType: "t2.micro",
                subnetId: range.value,
            }));
        }
    }
    
    import pulumi
    import pulumi_aws as aws
    
    private = aws.ec2.get_subnet_ids(vpc_id=var["vpc_id"],
        tags={
            "Tier": "Private",
        })
    app = []
    for range in [{"key": k, "value": v} for [k, v] in enumerate(private.ids)]:
        app.append(aws.ec2.Instance(f"app-{range['key']}",
            ami=var["ami"],
            instance_type="t2.micro",
            subnet_id=range["value"]))
    
    resources:
      app:
        type: aws:ec2:Instance
        properties:
          ami: ${var.ami}
          instanceType: t2.micro
          subnetId: ${range.value}
        options: {}
    variables:
      private:
        fn::invoke:
          Function: aws:ec2:getSubnetIds
          Arguments:
            vpcId: ${var.vpc_id}
            tags:
              Tier: Private
    

    Using getSubnetIds

    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 getSubnetIds(args: GetSubnetIdsArgs, opts?: InvokeOptions): Promise<GetSubnetIdsResult>
    function getSubnetIdsOutput(args: GetSubnetIdsOutputArgs, opts?: InvokeOptions): Output<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
    def get_subnet_ids_output(filters: Optional[pulumi.Input[Sequence[pulumi.Input[GetSubnetIdsFilterArgs]]]] = None,
                       tags: Optional[pulumi.Input[Mapping[str, pulumi.Input[str]]]] = None,
                       vpc_id: Optional[pulumi.Input[str]] = None,
                       opts: Optional[InvokeOptions] = None) -> Output[GetSubnetIdsResult]
    func GetSubnetIds(ctx *Context, args *GetSubnetIdsArgs, opts ...InvokeOption) (*GetSubnetIdsResult, error)
    func GetSubnetIdsOutput(ctx *Context, args *GetSubnetIdsOutputArgs, opts ...InvokeOption) GetSubnetIdsResultOutput

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

    public static class GetSubnetIds 
    {
        public static Task<GetSubnetIdsResult> InvokeAsync(GetSubnetIdsArgs args, InvokeOptions? opts = null)
        public static Output<GetSubnetIdsResult> Invoke(GetSubnetIdsInvokeArgs args, InvokeOptions? opts = null)
    }
    public static CompletableFuture<GetSubnetIdsResult> getSubnetIds(GetSubnetIdsArgs args, InvokeOptions options)
    public static Output<GetSubnetIdsResult> getSubnetIds(GetSubnetIdsArgs args, InvokeOptions options)
    
    fn::invoke:
      function: aws:ec2/getSubnetIds:getSubnetIds
      arguments:
        # arguments dictionary

    The following arguments are supported:

    VpcId string
    VPC ID that you want to filter from.
    Filters List<GetSubnetIdsFilter>
    Custom filter block as described below.
    Tags Dictionary<string, string>

    Map of tags, each pair of which must exactly match a pair on the desired subnets.

    More complex filters can be expressed using one or more filter sub-blocks, which take the following arguments:

    VpcId string
    VPC ID that you want to filter from.
    Filters []GetSubnetIdsFilter
    Custom filter block as described below.
    Tags map[string]string

    Map of tags, each pair of which must exactly match a pair on the desired subnets.

    More complex filters can be expressed using one or more filter sub-blocks, which take the following arguments:

    vpcId String
    VPC ID that you want to filter from.
    filters List<GetSubnetIdsFilter>
    Custom filter block as described below.
    tags Map<String,String>

    Map of tags, each pair of which must exactly match a pair on the desired subnets.

    More complex filters can be expressed using one or more filter sub-blocks, which take the following arguments:

    vpcId string
    VPC ID that you want to filter from.
    filters GetSubnetIdsFilter[]
    Custom filter block as described below.
    tags {[key: string]: string}

    Map of tags, each pair of which must exactly match a pair on the desired subnets.

    More complex filters can be expressed using one or more filter sub-blocks, which take the following arguments:

    vpc_id str
    VPC ID that you want to filter from.
    filters Sequence[GetSubnetIdsFilter]
    Custom filter block as described below.
    tags Mapping[str, str]

    Map of tags, each pair of which must exactly match a pair on the desired subnets.

    More complex filters can be expressed using one or more filter sub-blocks, which take the following arguments:

    vpcId String
    VPC ID that you want to filter from.
    filters List<Property Map>
    Custom filter block as described below.
    tags Map<String>

    Map of tags, each pair of which must exactly match a pair on the desired subnets.

    More complex filters can be expressed using one or more filter sub-blocks, which take the following arguments:

    getSubnetIds Result

    The following output properties are available:

    Id string
    The provider-assigned unique ID for this managed resource.
    Ids List<string>
    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
    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 List<String>
    Set of all the subnet ids found. This data source will fail if none are found.
    tags Map<String,String>
    vpcId String
    filters List<GetSubnetIdsFilter>
    id string
    The provider-assigned unique ID for this managed resource.
    ids string[]
    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]
    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]
    id String
    The provider-assigned unique ID for this managed resource.
    ids List<String>
    Set of all the subnet ids found. This data source will fail if none are found.
    tags Map<String>
    vpcId String
    filters List<Property Map>

    Supporting Types

    GetSubnetIdsFilter

    Name string
    Name of the field to filter by, as defined by the underlying AWS API. For example, if matching against tag Name, use:

    import * as pulumi from "@pulumi/pulumi";
    import * as aws from "@pulumi/aws";
    

    const selected = aws.ec2.getSubnetIds({ filters: [{ name: "tag:Name", values: [""], }], });

    import pulumi
    import pulumi_aws as aws
    
    selected = aws.ec2.get_subnet_ids(filters=[aws.ec2.GetSubnetIdsFilterArgs(
        name="tag:Name",
        values=[""],
    )])
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Aws = Pulumi.Aws;
    
    return await Deployment.RunAsync(() => 
    {
        var selected = Aws.Ec2.GetSubnetIds.Invoke(new()
        {
            Filters = new[]
            {
                new Aws.Ec2.Inputs.GetSubnetIdsFilterInputArgs
                {
                    Name = "tag:Name",
                    Values = new[]
                    {
                        "",
                    },
                },
            },
        });
    
    });
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-aws/sdk/v5/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{
    			Filters: []ec2.GetSubnetIdsFilter{
    				{
    					Name: "tag:Name",
    					Values: []string{
    						"",
    					},
    				},
    			},
    		}, nil)
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    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.GetSubnetIdsArgs;
    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 selected = Ec2Functions.getSubnetIds(GetSubnetIdsArgs.builder()
                .filters(GetSubnetIdsFilterArgs.builder()
                    .name("tag:Name")
                    .values("")
                    .build())
                .build());
    
        }
    }
    
    variables:
      selected:
        fn::invoke:
          Function: aws:ec2:getSubnetIds
          Arguments:
            filters:
              - name: tag:Name
                values:
                  -
    
    title="Required"> <span id="values_csharp">

    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
    Name of the field to filter by, as defined by the underlying AWS API. For example, if matching against tag Name, use:

    import * as pulumi from "@pulumi/pulumi";
    import * as aws from "@pulumi/aws";
    

    const selected = aws.ec2.getSubnetIds({ filters: [{ name: "tag:Name", values: [""], }], });

    import pulumi
    import pulumi_aws as aws
    
    selected = aws.ec2.get_subnet_ids(filters=[aws.ec2.GetSubnetIdsFilterArgs(
        name="tag:Name",
        values=[""],
    )])
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Aws = Pulumi.Aws;
    
    return await Deployment.RunAsync(() => 
    {
        var selected = Aws.Ec2.GetSubnetIds.Invoke(new()
        {
            Filters = new[]
            {
                new Aws.Ec2.Inputs.GetSubnetIdsFilterInputArgs
                {
                    Name = "tag:Name",
                    Values = new[]
                    {
                        "",
                    },
                },
            },
        });
    
    });
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-aws/sdk/v5/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{
    			Filters: []ec2.GetSubnetIdsFilter{
    				{
    					Name: "tag:Name",
    					Values: []string{
    						"",
    					},
    				},
    			},
    		}, nil)
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    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.GetSubnetIdsArgs;
    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 selected = Ec2Functions.getSubnetIds(GetSubnetIdsArgs.builder()
                .filters(GetSubnetIdsFilterArgs.builder()
                    .name("tag:Name")
                    .values("")
                    .build())
                .build());
    
        }
    }
    
    variables:
      selected:
        fn::invoke:
          Function: aws:ec2:getSubnetIds
          Arguments:
            filters:
              - name: tag:Name
                values:
                  -
    
    title="Required"> <span id="values_go">

    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
    Name of the field to filter by, as defined by the underlying AWS API. For example, if matching against tag Name, use:

    import * as pulumi from "@pulumi/pulumi";
    import * as aws from "@pulumi/aws";
    

    const selected = aws.ec2.getSubnetIds({ filters: [{ name: "tag:Name", values: [""], }], });

    import pulumi
    import pulumi_aws as aws
    
    selected = aws.ec2.get_subnet_ids(filters=[aws.ec2.GetSubnetIdsFilterArgs(
        name="tag:Name",
        values=[""],
    )])
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Aws = Pulumi.Aws;
    
    return await Deployment.RunAsync(() => 
    {
        var selected = Aws.Ec2.GetSubnetIds.Invoke(new()
        {
            Filters = new[]
            {
                new Aws.Ec2.Inputs.GetSubnetIdsFilterInputArgs
                {
                    Name = "tag:Name",
                    Values = new[]
                    {
                        "",
                    },
                },
            },
        });
    
    });
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-aws/sdk/v5/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{
    			Filters: []ec2.GetSubnetIdsFilter{
    				{
    					Name: "tag:Name",
    					Values: []string{
    						"",
    					},
    				},
    			},
    		}, nil)
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    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.GetSubnetIdsArgs;
    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 selected = Ec2Functions.getSubnetIds(GetSubnetIdsArgs.builder()
                .filters(GetSubnetIdsFilterArgs.builder()
                    .name("tag:Name")
                    .values("")
                    .build())
                .build());
    
        }
    }
    
    variables:
      selected:
        fn::invoke:
          Function: aws:ec2:getSubnetIds
          Arguments:
            filters:
              - name: tag:Name
                values:
                  -
    
    title="Required"> <span id="values_java">

    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
    Name of the field to filter by, as defined by the underlying AWS API. For example, if matching against tag Name, use:

    import * as pulumi from "@pulumi/pulumi";
    import * as aws from "@pulumi/aws";
    

    const selected = aws.ec2.getSubnetIds({ filters: [{ name: "tag:Name", values: [""], }], });

    import pulumi
    import pulumi_aws as aws
    
    selected = aws.ec2.get_subnet_ids(filters=[aws.ec2.GetSubnetIdsFilterArgs(
        name="tag:Name",
        values=[""],
    )])
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Aws = Pulumi.Aws;
    
    return await Deployment.RunAsync(() => 
    {
        var selected = Aws.Ec2.GetSubnetIds.Invoke(new()
        {
            Filters = new[]
            {
                new Aws.Ec2.Inputs.GetSubnetIdsFilterInputArgs
                {
                    Name = "tag:Name",
                    Values = new[]
                    {
                        "",
                    },
                },
            },
        });
    
    });
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-aws/sdk/v5/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{
    			Filters: []ec2.GetSubnetIdsFilter{
    				{
    					Name: "tag:Name",
    					Values: []string{
    						"",
    					},
    				},
    			},
    		}, nil)
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    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.GetSubnetIdsArgs;
    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 selected = Ec2Functions.getSubnetIds(GetSubnetIdsArgs.builder()
                .filters(GetSubnetIdsFilterArgs.builder()
                    .name("tag:Name")
                    .values("")
                    .build())
                .build());
    
        }
    }
    
    variables:
      selected:
        fn::invoke:
          Function: aws:ec2:getSubnetIds
          Arguments:
            filters:
              - name: tag:Name
                values:
                  -
    
    title="Required"> <span id="values_nodejs">

    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
    Name of the field to filter by, as defined by the underlying AWS API. For example, if matching against tag Name, use:

    import * as pulumi from "@pulumi/pulumi";
    import * as aws from "@pulumi/aws";
    

    const selected = aws.ec2.getSubnetIds({ filters: [{ name: "tag:Name", values: [""], }], });

    import pulumi
    import pulumi_aws as aws
    
    selected = aws.ec2.get_subnet_ids(filters=[aws.ec2.GetSubnetIdsFilterArgs(
        name="tag:Name",
        values=[""],
    )])
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Aws = Pulumi.Aws;
    
    return await Deployment.RunAsync(() => 
    {
        var selected = Aws.Ec2.GetSubnetIds.Invoke(new()
        {
            Filters = new[]
            {
                new Aws.Ec2.Inputs.GetSubnetIdsFilterInputArgs
                {
                    Name = "tag:Name",
                    Values = new[]
                    {
                        "",
                    },
                },
            },
        });
    
    });
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-aws/sdk/v5/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{
    			Filters: []ec2.GetSubnetIdsFilter{
    				{
    					Name: "tag:Name",
    					Values: []string{
    						"",
    					},
    				},
    			},
    		}, nil)
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    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.GetSubnetIdsArgs;
    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 selected = Ec2Functions.getSubnetIds(GetSubnetIdsArgs.builder()
                .filters(GetSubnetIdsFilterArgs.builder()
                    .name("tag:Name")
                    .values("")
                    .build())
                .build());
    
        }
    }
    
    variables:
      selected:
        fn::invoke:
          Function: aws:ec2:getSubnetIds
          Arguments:
            filters:
              - name: tag:Name
                values:
                  -
    
    title="Required"> <span id="values_python">

    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.

    name String
    Name of the field to filter by, as defined by the underlying AWS API. For example, if matching against tag Name, use:

    import * as pulumi from "@pulumi/pulumi";
    import * as aws from "@pulumi/aws";
    

    const selected = aws.ec2.getSubnetIds({ filters: [{ name: "tag:Name", values: [""], }], });

    import pulumi
    import pulumi_aws as aws
    
    selected = aws.ec2.get_subnet_ids(filters=[aws.ec2.GetSubnetIdsFilterArgs(
        name="tag:Name",
        values=[""],
    )])
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Aws = Pulumi.Aws;
    
    return await Deployment.RunAsync(() => 
    {
        var selected = Aws.Ec2.GetSubnetIds.Invoke(new()
        {
            Filters = new[]
            {
                new Aws.Ec2.Inputs.GetSubnetIdsFilterInputArgs
                {
                    Name = "tag:Name",
                    Values = new[]
                    {
                        "",
                    },
                },
            },
        });
    
    });
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-aws/sdk/v5/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{
    			Filters: []ec2.GetSubnetIdsFilter{
    				{
    					Name: "tag:Name",
    					Values: []string{
    						"",
    					},
    				},
    			},
    		}, nil)
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    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.GetSubnetIdsArgs;
    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 selected = Ec2Functions.getSubnetIds(GetSubnetIdsArgs.builder()
                .filters(GetSubnetIdsFilterArgs.builder()
                    .name("tag:Name")
                    .values("")
                    .build())
                .build());
    
        }
    }
    
    variables:
      selected:
        fn::invoke:
          Function: aws:ec2:getSubnetIds
          Arguments:
            filters:
              - name: tag:Name
                values:
                  -
    
    title="Required"> <span id="values_yaml">

    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.

    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
    Viewing docs for AWS v5.43.0 (Older version)
    published on Tuesday, Mar 10, 2026 by Pulumi
      Try Pulumi Cloud free. Your team will thank you.