1. Packages
  2. AWS Classic
  3. API Docs
  4. ec2
  5. getSubnets

Try AWS Native preview for resources not in the classic version.

AWS Classic v6.22.2 published on Friday, Feb 16, 2024 by Pulumi

aws.ec2.getSubnets

Explore with Pulumi AI

aws logo

Try AWS Native preview for resources not in the classic version.

AWS Classic v6.22.2 published on Friday, Feb 16, 2024 by Pulumi

    This resource can be useful for getting back a set of subnet IDs.

    Using getSubnets

    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 getSubnets(args: GetSubnetsArgs, opts?: InvokeOptions): Promise<GetSubnetsResult>
    function getSubnetsOutput(args: GetSubnetsOutputArgs, opts?: InvokeOptions): Output<GetSubnetsResult>
    def get_subnets(filters: Optional[Sequence[GetSubnetsFilter]] = None,
                    tags: Optional[Mapping[str, str]] = None,
                    opts: Optional[InvokeOptions] = None) -> GetSubnetsResult
    def get_subnets_output(filters: Optional[pulumi.Input[Sequence[pulumi.Input[GetSubnetsFilterArgs]]]] = None,
                    tags: Optional[pulumi.Input[Mapping[str, pulumi.Input[str]]]] = None,
                    opts: Optional[InvokeOptions] = None) -> Output[GetSubnetsResult]
    func GetSubnets(ctx *Context, args *GetSubnetsArgs, opts ...InvokeOption) (*GetSubnetsResult, error)
    func GetSubnetsOutput(ctx *Context, args *GetSubnetsOutputArgs, opts ...InvokeOption) GetSubnetsResultOutput

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

    public static class GetSubnets 
    {
        public static Task<GetSubnetsResult> InvokeAsync(GetSubnetsArgs args, InvokeOptions? opts = null)
        public static Output<GetSubnetsResult> Invoke(GetSubnetsInvokeArgs args, InvokeOptions? opts = null)
    }
    public static CompletableFuture<GetSubnetsResult> getSubnets(GetSubnetsArgs args, InvokeOptions options)
    // Output-based functions aren't available in Java yet
    
    fn::invoke:
      function: aws:ec2/getSubnets:getSubnets
      arguments:
        # arguments dictionary

    The following arguments are supported:

    Filters List<GetSubnetsFilter>
    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:

    Filters []GetSubnetsFilter
    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:

    filters List<GetSubnetsFilter>
    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:

    filters GetSubnetsFilter[]
    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:

    filters Sequence[GetSubnetsFilter]
    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:

    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:

    getSubnets 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 subnet ids found.
    Tags Dictionary<string, string>
    Filters List<GetSubnetsFilter>
    Id string
    The provider-assigned unique ID for this managed resource.
    Ids []string
    List of all the subnet ids found.
    Tags map[string]string
    Filters []GetSubnetsFilter
    id String
    The provider-assigned unique ID for this managed resource.
    ids List<String>
    List of all the subnet ids found.
    tags Map<String,String>
    filters List<GetSubnetsFilter>
    id string
    The provider-assigned unique ID for this managed resource.
    ids string[]
    List of all the subnet ids found.
    tags {[key: string]: string}
    filters GetSubnetsFilter[]
    id str
    The provider-assigned unique ID for this managed resource.
    ids Sequence[str]
    List of all the subnet ids found.
    tags Mapping[str, str]
    filters Sequence[GetSubnetsFilter]
    id String
    The provider-assigned unique ID for this managed resource.
    ids List<String>
    List of all the subnet ids found.
    tags Map<String>
    filters List<Property Map>

    Supporting Types

    GetSubnetsFilter

    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.getSubnets({ filters: [{ name: "tag:Name", values: [""], }], });

    import pulumi
    import pulumi_aws as aws
    
    selected = aws.ec2.get_subnets(filters=[aws.ec2.GetSubnetsFilterArgs(
        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.GetSubnets.Invoke(new()
        {
            Filters = new[]
            {
                new Aws.Ec2.Inputs.GetSubnetsFilterInputArgs
                {
                    Name = "tag:Name",
                    Values = new[]
                    {
                        "",
                    },
                },
            },
        });
    
    });
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/ec2"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		_, err := ec2.GetSubnets(ctx, &ec2.GetSubnetsArgs{
    			Filters: []ec2.GetSubnetsFilter{
    				{
    					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.GetSubnetsArgs;
    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.getSubnets(GetSubnetsArgs.builder()
                .filters(GetSubnetsFilterArgs.builder()
                    .name("tag:Name")
                    .values("")
                    .build())
                .build());
    
        }
    }
    
    variables:
      selected:
        fn::invoke:
          Function: aws:ec2:getSubnets
          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.getSubnets({ filters: [{ name: "tag:Name", values: [""], }], });

    import pulumi
    import pulumi_aws as aws
    
    selected = aws.ec2.get_subnets(filters=[aws.ec2.GetSubnetsFilterArgs(
        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.GetSubnets.Invoke(new()
        {
            Filters = new[]
            {
                new Aws.Ec2.Inputs.GetSubnetsFilterInputArgs
                {
                    Name = "tag:Name",
                    Values = new[]
                    {
                        "",
                    },
                },
            },
        });
    
    });
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/ec2"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		_, err := ec2.GetSubnets(ctx, &ec2.GetSubnetsArgs{
    			Filters: []ec2.GetSubnetsFilter{
    				{
    					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.GetSubnetsArgs;
    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.getSubnets(GetSubnetsArgs.builder()
                .filters(GetSubnetsFilterArgs.builder()
                    .name("tag:Name")
                    .values("")
                    .build())
                .build());
    
        }
    }
    
    variables:
      selected:
        fn::invoke:
          Function: aws:ec2:getSubnets
          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.getSubnets({ filters: [{ name: "tag:Name", values: [""], }], });

    import pulumi
    import pulumi_aws as aws
    
    selected = aws.ec2.get_subnets(filters=[aws.ec2.GetSubnetsFilterArgs(
        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.GetSubnets.Invoke(new()
        {
            Filters = new[]
            {
                new Aws.Ec2.Inputs.GetSubnetsFilterInputArgs
                {
                    Name = "tag:Name",
                    Values = new[]
                    {
                        "",
                    },
                },
            },
        });
    
    });
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/ec2"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		_, err := ec2.GetSubnets(ctx, &ec2.GetSubnetsArgs{
    			Filters: []ec2.GetSubnetsFilter{
    				{
    					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.GetSubnetsArgs;
    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.getSubnets(GetSubnetsArgs.builder()
                .filters(GetSubnetsFilterArgs.builder()
                    .name("tag:Name")
                    .values("")
                    .build())
                .build());
    
        }
    }
    
    variables:
      selected:
        fn::invoke:
          Function: aws:ec2:getSubnets
          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.getSubnets({ filters: [{ name: "tag:Name", values: [""], }], });

    import pulumi
    import pulumi_aws as aws
    
    selected = aws.ec2.get_subnets(filters=[aws.ec2.GetSubnetsFilterArgs(
        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.GetSubnets.Invoke(new()
        {
            Filters = new[]
            {
                new Aws.Ec2.Inputs.GetSubnetsFilterInputArgs
                {
                    Name = "tag:Name",
                    Values = new[]
                    {
                        "",
                    },
                },
            },
        });
    
    });
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/ec2"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		_, err := ec2.GetSubnets(ctx, &ec2.GetSubnetsArgs{
    			Filters: []ec2.GetSubnetsFilter{
    				{
    					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.GetSubnetsArgs;
    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.getSubnets(GetSubnetsArgs.builder()
                .filters(GetSubnetsFilterArgs.builder()
                    .name("tag:Name")
                    .values("")
                    .build())
                .build());
    
        }
    }
    
    variables:
      selected:
        fn::invoke:
          Function: aws:ec2:getSubnets
          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.getSubnets({ filters: [{ name: "tag:Name", values: [""], }], });

    import pulumi
    import pulumi_aws as aws
    
    selected = aws.ec2.get_subnets(filters=[aws.ec2.GetSubnetsFilterArgs(
        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.GetSubnets.Invoke(new()
        {
            Filters = new[]
            {
                new Aws.Ec2.Inputs.GetSubnetsFilterInputArgs
                {
                    Name = "tag:Name",
                    Values = new[]
                    {
                        "",
                    },
                },
            },
        });
    
    });
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/ec2"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		_, err := ec2.GetSubnets(ctx, &ec2.GetSubnetsArgs{
    			Filters: []ec2.GetSubnetsFilter{
    				{
    					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.GetSubnetsArgs;
    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.getSubnets(GetSubnetsArgs.builder()
                .filters(GetSubnetsFilterArgs.builder()
                    .name("tag:Name")
                    .values("")
                    .build())
                .build());
    
        }
    }
    
    variables:
      selected:
        fn::invoke:
          Function: aws:ec2:getSubnets
          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.getSubnets({ filters: [{ name: "tag:Name", values: [""], }], });

    import pulumi
    import pulumi_aws as aws
    
    selected = aws.ec2.get_subnets(filters=[aws.ec2.GetSubnetsFilterArgs(
        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.GetSubnets.Invoke(new()
        {
            Filters = new[]
            {
                new Aws.Ec2.Inputs.GetSubnetsFilterInputArgs
                {
                    Name = "tag:Name",
                    Values = new[]
                    {
                        "",
                    },
                },
            },
        });
    
    });
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/ec2"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		_, err := ec2.GetSubnets(ctx, &ec2.GetSubnetsArgs{
    			Filters: []ec2.GetSubnetsFilter{
    				{
    					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.GetSubnetsArgs;
    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.getSubnets(GetSubnetsArgs.builder()
                .filters(GetSubnetsFilterArgs.builder()
                    .name("tag:Name")
                    .values("")
                    .build())
                .build());
    
        }
    }
    
    variables:
      selected:
        fn::invoke:
          Function: aws:ec2:getSubnets
          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

    Try AWS Native preview for resources not in the classic version.

    AWS Classic v6.22.2 published on Friday, Feb 16, 2024 by Pulumi