1. Packages
  2. Tencentcloud Provider
  3. API Docs
  4. getVpcSubnets
tencentcloud 1.81.189 published on Wednesday, Apr 30, 2025 by tencentcloudstack

tencentcloud.getVpcSubnets

Explore with Pulumi AI

tencentcloud logo
tencentcloud 1.81.189 published on Wednesday, Apr 30, 2025 by tencentcloudstack

    Use this data source to query vpc subnets information.

    Example Usage

    Create subnet resource

    import * as pulumi from "@pulumi/pulumi";
    import * as tencentcloud from "@pulumi/tencentcloud";
    
    const config = new pulumi.Config();
    const availabilityZone = config.get("availabilityZone") || "ap-guangzhou-3";
    const vpc = new tencentcloud.Vpc("vpc", {cidrBlock: "10.0.0.0/16"});
    const subnet = new tencentcloud.Subnet("subnet", {
        availabilityZone: availabilityZone,
        vpcId: vpc.vpcId,
        cidrBlock: "10.0.20.0/28",
        isMulticast: false,
        tags: {
            test: "test",
        },
    });
    const subnetCDC = new tencentcloud.Subnet("subnetCDC", {
        vpcId: vpc.vpcId,
        cidrBlock: "10.0.0.0/16",
        cdcId: "cluster-lchwgxhs",
        availabilityZone: data.tencentcloud_availability_zones.zones.zones[0].name,
        isMulticast: false,
    });
    
    import pulumi
    import pulumi_tencentcloud as tencentcloud
    
    config = pulumi.Config()
    availability_zone = config.get("availabilityZone")
    if availability_zone is None:
        availability_zone = "ap-guangzhou-3"
    vpc = tencentcloud.Vpc("vpc", cidr_block="10.0.0.0/16")
    subnet = tencentcloud.Subnet("subnet",
        availability_zone=availability_zone,
        vpc_id=vpc.vpc_id,
        cidr_block="10.0.20.0/28",
        is_multicast=False,
        tags={
            "test": "test",
        })
    subnet_cdc = tencentcloud.Subnet("subnetCDC",
        vpc_id=vpc.vpc_id,
        cidr_block="10.0.0.0/16",
        cdc_id="cluster-lchwgxhs",
        availability_zone=data["tencentcloud_availability_zones"]["zones"]["zones"][0]["name"],
        is_multicast=False)
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-terraform-provider/sdks/go/tencentcloud/tencentcloud"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi/config"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		cfg := config.New(ctx, "")
    		availabilityZone := "ap-guangzhou-3"
    		if param := cfg.Get("availabilityZone"); param != "" {
    			availabilityZone = param
    		}
    		vpc, err := tencentcloud.NewVpc(ctx, "vpc", &tencentcloud.VpcArgs{
    			CidrBlock: pulumi.String("10.0.0.0/16"),
    		})
    		if err != nil {
    			return err
    		}
    		_, err = tencentcloud.NewSubnet(ctx, "subnet", &tencentcloud.SubnetArgs{
    			AvailabilityZone: pulumi.String(availabilityZone),
    			VpcId:            vpc.VpcId,
    			CidrBlock:        pulumi.String("10.0.20.0/28"),
    			IsMulticast:      pulumi.Bool(false),
    			Tags: pulumi.StringMap{
    				"test": pulumi.String("test"),
    			},
    		})
    		if err != nil {
    			return err
    		}
    		_, err = tencentcloud.NewSubnet(ctx, "subnetCDC", &tencentcloud.SubnetArgs{
    			VpcId:            vpc.VpcId,
    			CidrBlock:        pulumi.String("10.0.0.0/16"),
    			CdcId:            pulumi.String("cluster-lchwgxhs"),
    			AvailabilityZone: pulumi.Any(data.Tencentcloud_availability_zones.Zones.Zones[0].Name),
    			IsMulticast:      pulumi.Bool(false),
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Tencentcloud = Pulumi.Tencentcloud;
    
    return await Deployment.RunAsync(() => 
    {
        var config = new Config();
        var availabilityZone = config.Get("availabilityZone") ?? "ap-guangzhou-3";
        var vpc = new Tencentcloud.Vpc("vpc", new()
        {
            CidrBlock = "10.0.0.0/16",
        });
    
        var subnet = new Tencentcloud.Subnet("subnet", new()
        {
            AvailabilityZone = availabilityZone,
            VpcId = vpc.VpcId,
            CidrBlock = "10.0.20.0/28",
            IsMulticast = false,
            Tags = 
            {
                { "test", "test" },
            },
        });
    
        var subnetCDC = new Tencentcloud.Subnet("subnetCDC", new()
        {
            VpcId = vpc.VpcId,
            CidrBlock = "10.0.0.0/16",
            CdcId = "cluster-lchwgxhs",
            AvailabilityZone = data.Tencentcloud_availability_zones.Zones.Zones[0].Name,
            IsMulticast = false,
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.tencentcloud.Vpc;
    import com.pulumi.tencentcloud.VpcArgs;
    import com.pulumi.tencentcloud.Subnet;
    import com.pulumi.tencentcloud.SubnetArgs;
    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 config = ctx.config();
            final var availabilityZone = config.get("availabilityZone").orElse("ap-guangzhou-3");
            var vpc = new Vpc("vpc", VpcArgs.builder()
                .cidrBlock("10.0.0.0/16")
                .build());
    
            var subnet = new Subnet("subnet", SubnetArgs.builder()
                .availabilityZone(availabilityZone)
                .vpcId(vpc.vpcId())
                .cidrBlock("10.0.20.0/28")
                .isMulticast(false)
                .tags(Map.of("test", "test"))
                .build());
    
            var subnetCDC = new Subnet("subnetCDC", SubnetArgs.builder()
                .vpcId(vpc.vpcId())
                .cidrBlock("10.0.0.0/16")
                .cdcId("cluster-lchwgxhs")
                .availabilityZone(data.tencentcloud_availability_zones().zones().zones()[0].name())
                .isMulticast(false)
                .build());
    
        }
    }
    
    configuration:
      availabilityZone:
        type: string
        default: ap-guangzhou-3
    resources:
      vpc:
        type: tencentcloud:Vpc
        properties:
          cidrBlock: 10.0.0.0/16
      subnet:
        type: tencentcloud:Subnet
        properties:
          availabilityZone: ${availabilityZone}
          vpcId: ${vpc.vpcId}
          cidrBlock: 10.0.20.0/28
          isMulticast: false
          tags:
            test: test
      subnetCDC:
        type: tencentcloud:Subnet
        properties:
          vpcId: ${vpc.vpcId}
          cidrBlock: 10.0.0.0/16
          cdcId: cluster-lchwgxhs
          availabilityZone: ${data.tencentcloud_availability_zones.zones.zones[0].name}
          isMulticast: false
    

    Query all subnets

    import * as pulumi from "@pulumi/pulumi";
    import * as tencentcloud from "@pulumi/tencentcloud";
    
    const subnets = tencentcloud.getVpcSubnets({});
    
    import pulumi
    import pulumi_tencentcloud as tencentcloud
    
    subnets = tencentcloud.get_vpc_subnets()
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-terraform-provider/sdks/go/tencentcloud/tencentcloud"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		_, err := tencentcloud.GetVpcSubnets(ctx, &tencentcloud.GetVpcSubnetsArgs{}, nil)
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Tencentcloud = Pulumi.Tencentcloud;
    
    return await Deployment.RunAsync(() => 
    {
        var subnets = Tencentcloud.GetVpcSubnets.Invoke();
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.tencentcloud.TencentcloudFunctions;
    import com.pulumi.tencentcloud.inputs.GetVpcSubnetsArgs;
    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 subnets = TencentcloudFunctions.getVpcSubnets();
    
        }
    }
    
    variables:
      subnets:
        fn::invoke:
          function: tencentcloud:getVpcSubnets
          arguments: {}
    

    Using getVpcSubnets

    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 getVpcSubnets(args: GetVpcSubnetsArgs, opts?: InvokeOptions): Promise<GetVpcSubnetsResult>
    function getVpcSubnetsOutput(args: GetVpcSubnetsOutputArgs, opts?: InvokeOptions): Output<GetVpcSubnetsResult>
    def get_vpc_subnets(availability_zone: Optional[str] = None,
                        cdc_id: Optional[str] = None,
                        cidr_block: Optional[str] = None,
                        id: Optional[str] = None,
                        is_default: Optional[bool] = None,
                        is_remote_vpc_snat: Optional[bool] = None,
                        name: Optional[str] = None,
                        result_output_file: Optional[str] = None,
                        subnet_id: Optional[str] = None,
                        tag_key: Optional[str] = None,
                        tags: Optional[Mapping[str, str]] = None,
                        vpc_id: Optional[str] = None,
                        opts: Optional[InvokeOptions] = None) -> GetVpcSubnetsResult
    def get_vpc_subnets_output(availability_zone: Optional[pulumi.Input[str]] = None,
                        cdc_id: Optional[pulumi.Input[str]] = None,
                        cidr_block: Optional[pulumi.Input[str]] = None,
                        id: Optional[pulumi.Input[str]] = None,
                        is_default: Optional[pulumi.Input[bool]] = None,
                        is_remote_vpc_snat: Optional[pulumi.Input[bool]] = None,
                        name: Optional[pulumi.Input[str]] = None,
                        result_output_file: Optional[pulumi.Input[str]] = None,
                        subnet_id: Optional[pulumi.Input[str]] = None,
                        tag_key: Optional[pulumi.Input[str]] = None,
                        tags: Optional[pulumi.Input[Mapping[str, pulumi.Input[str]]]] = None,
                        vpc_id: Optional[pulumi.Input[str]] = None,
                        opts: Optional[InvokeOptions] = None) -> Output[GetVpcSubnetsResult]
    func GetVpcSubnets(ctx *Context, args *GetVpcSubnetsArgs, opts ...InvokeOption) (*GetVpcSubnetsResult, error)
    func GetVpcSubnetsOutput(ctx *Context, args *GetVpcSubnetsOutputArgs, opts ...InvokeOption) GetVpcSubnetsResultOutput

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

    public static class GetVpcSubnets 
    {
        public static Task<GetVpcSubnetsResult> InvokeAsync(GetVpcSubnetsArgs args, InvokeOptions? opts = null)
        public static Output<GetVpcSubnetsResult> Invoke(GetVpcSubnetsInvokeArgs args, InvokeOptions? opts = null)
    }
    public static CompletableFuture<GetVpcSubnetsResult> getVpcSubnets(GetVpcSubnetsArgs args, InvokeOptions options)
    public static Output<GetVpcSubnetsResult> getVpcSubnets(GetVpcSubnetsArgs args, InvokeOptions options)
    
    fn::invoke:
      function: tencentcloud:index/getVpcSubnets:getVpcSubnets
      arguments:
        # arguments dictionary

    The following arguments are supported:

    AvailabilityZone string
    Zone of the subnet to be queried.
    CdcId string
    ID of CDC instance.
    CidrBlock string
    Filter subnet with this CIDR.
    Id string
    IsDefault bool
    Filter default or no default subnets.
    IsRemoteVpcSnat bool
    Filter the VPC SNAT address pool subnet.
    Name string
    Name of the subnet to be queried.
    ResultOutputFile string
    Used to save results.
    SubnetId string
    ID of the subnet to be queried.
    TagKey string
    Filter if subnet has this tag.
    Tags Dictionary<string, string>
    Tags of the subnet to be queried.
    VpcId string
    ID of the VPC to be queried.
    AvailabilityZone string
    Zone of the subnet to be queried.
    CdcId string
    ID of CDC instance.
    CidrBlock string
    Filter subnet with this CIDR.
    Id string
    IsDefault bool
    Filter default or no default subnets.
    IsRemoteVpcSnat bool
    Filter the VPC SNAT address pool subnet.
    Name string
    Name of the subnet to be queried.
    ResultOutputFile string
    Used to save results.
    SubnetId string
    ID of the subnet to be queried.
    TagKey string
    Filter if subnet has this tag.
    Tags map[string]string
    Tags of the subnet to be queried.
    VpcId string
    ID of the VPC to be queried.
    availabilityZone String
    Zone of the subnet to be queried.
    cdcId String
    ID of CDC instance.
    cidrBlock String
    Filter subnet with this CIDR.
    id String
    isDefault Boolean
    Filter default or no default subnets.
    isRemoteVpcSnat Boolean
    Filter the VPC SNAT address pool subnet.
    name String
    Name of the subnet to be queried.
    resultOutputFile String
    Used to save results.
    subnetId String
    ID of the subnet to be queried.
    tagKey String
    Filter if subnet has this tag.
    tags Map<String,String>
    Tags of the subnet to be queried.
    vpcId String
    ID of the VPC to be queried.
    availabilityZone string
    Zone of the subnet to be queried.
    cdcId string
    ID of CDC instance.
    cidrBlock string
    Filter subnet with this CIDR.
    id string
    isDefault boolean
    Filter default or no default subnets.
    isRemoteVpcSnat boolean
    Filter the VPC SNAT address pool subnet.
    name string
    Name of the subnet to be queried.
    resultOutputFile string
    Used to save results.
    subnetId string
    ID of the subnet to be queried.
    tagKey string
    Filter if subnet has this tag.
    tags {[key: string]: string}
    Tags of the subnet to be queried.
    vpcId string
    ID of the VPC to be queried.
    availability_zone str
    Zone of the subnet to be queried.
    cdc_id str
    ID of CDC instance.
    cidr_block str
    Filter subnet with this CIDR.
    id str
    is_default bool
    Filter default or no default subnets.
    is_remote_vpc_snat bool
    Filter the VPC SNAT address pool subnet.
    name str
    Name of the subnet to be queried.
    result_output_file str
    Used to save results.
    subnet_id str
    ID of the subnet to be queried.
    tag_key str
    Filter if subnet has this tag.
    tags Mapping[str, str]
    Tags of the subnet to be queried.
    vpc_id str
    ID of the VPC to be queried.
    availabilityZone String
    Zone of the subnet to be queried.
    cdcId String
    ID of CDC instance.
    cidrBlock String
    Filter subnet with this CIDR.
    id String
    isDefault Boolean
    Filter default or no default subnets.
    isRemoteVpcSnat Boolean
    Filter the VPC SNAT address pool subnet.
    name String
    Name of the subnet to be queried.
    resultOutputFile String
    Used to save results.
    subnetId String
    ID of the subnet to be queried.
    tagKey String
    Filter if subnet has this tag.
    tags Map<String>
    Tags of the subnet to be queried.
    vpcId String
    ID of the VPC to be queried.

    getVpcSubnets Result

    The following output properties are available:

    Id string
    InstanceLists List<GetVpcSubnetsInstanceList>
    List of subnets.
    AvailabilityZone string
    The availability zone of the subnet.
    CdcId string
    ID of CDC instance.
    CidrBlock string
    A network address block of the subnet.
    IsDefault bool
    Indicates whether it is the default subnet of the VPC for this region.
    IsRemoteVpcSnat bool
    Name string
    Name of the subnet.
    ResultOutputFile string
    SubnetId string
    ID of the subnet.
    TagKey string
    Tags Dictionary<string, string>
    Tags of the subnet resource.
    VpcId string
    ID of the VPC.
    Id string
    InstanceLists []GetVpcSubnetsInstanceList
    List of subnets.
    AvailabilityZone string
    The availability zone of the subnet.
    CdcId string
    ID of CDC instance.
    CidrBlock string
    A network address block of the subnet.
    IsDefault bool
    Indicates whether it is the default subnet of the VPC for this region.
    IsRemoteVpcSnat bool
    Name string
    Name of the subnet.
    ResultOutputFile string
    SubnetId string
    ID of the subnet.
    TagKey string
    Tags map[string]string
    Tags of the subnet resource.
    VpcId string
    ID of the VPC.
    id String
    instanceLists List<GetVpcSubnetsInstanceList>
    List of subnets.
    availabilityZone String
    The availability zone of the subnet.
    cdcId String
    ID of CDC instance.
    cidrBlock String
    A network address block of the subnet.
    isDefault Boolean
    Indicates whether it is the default subnet of the VPC for this region.
    isRemoteVpcSnat Boolean
    name String
    Name of the subnet.
    resultOutputFile String
    subnetId String
    ID of the subnet.
    tagKey String
    tags Map<String,String>
    Tags of the subnet resource.
    vpcId String
    ID of the VPC.
    id string
    instanceLists GetVpcSubnetsInstanceList[]
    List of subnets.
    availabilityZone string
    The availability zone of the subnet.
    cdcId string
    ID of CDC instance.
    cidrBlock string
    A network address block of the subnet.
    isDefault boolean
    Indicates whether it is the default subnet of the VPC for this region.
    isRemoteVpcSnat boolean
    name string
    Name of the subnet.
    resultOutputFile string
    subnetId string
    ID of the subnet.
    tagKey string
    tags {[key: string]: string}
    Tags of the subnet resource.
    vpcId string
    ID of the VPC.
    id str
    instance_lists Sequence[GetVpcSubnetsInstanceList]
    List of subnets.
    availability_zone str
    The availability zone of the subnet.
    cdc_id str
    ID of CDC instance.
    cidr_block str
    A network address block of the subnet.
    is_default bool
    Indicates whether it is the default subnet of the VPC for this region.
    is_remote_vpc_snat bool
    name str
    Name of the subnet.
    result_output_file str
    subnet_id str
    ID of the subnet.
    tag_key str
    tags Mapping[str, str]
    Tags of the subnet resource.
    vpc_id str
    ID of the VPC.
    id String
    instanceLists List<Property Map>
    List of subnets.
    availabilityZone String
    The availability zone of the subnet.
    cdcId String
    ID of CDC instance.
    cidrBlock String
    A network address block of the subnet.
    isDefault Boolean
    Indicates whether it is the default subnet of the VPC for this region.
    isRemoteVpcSnat Boolean
    name String
    Name of the subnet.
    resultOutputFile String
    subnetId String
    ID of the subnet.
    tagKey String
    tags Map<String>
    Tags of the subnet resource.
    vpcId String
    ID of the VPC.

    Supporting Types

    GetVpcSubnetsInstanceList

    AvailabilityZone string
    Zone of the subnet to be queried.
    AvailableIpCount double
    The number of available IPs.
    CdcId string
    ID of CDC instance.
    CidrBlock string
    Filter subnet with this CIDR.
    CreateTime string
    Creation time of the subnet resource.
    IsDefault bool
    Filter default or no default subnets.
    IsMulticast bool
    Indicates whether multicast is enabled.
    Name string
    Name of the subnet to be queried.
    RouteTableId string
    ID of the routing table.
    SubnetId string
    ID of the subnet to be queried.
    Tags Dictionary<string, string>
    Tags of the subnet to be queried.
    VpcId string
    ID of the VPC to be queried.
    AvailabilityZone string
    Zone of the subnet to be queried.
    AvailableIpCount float64
    The number of available IPs.
    CdcId string
    ID of CDC instance.
    CidrBlock string
    Filter subnet with this CIDR.
    CreateTime string
    Creation time of the subnet resource.
    IsDefault bool
    Filter default or no default subnets.
    IsMulticast bool
    Indicates whether multicast is enabled.
    Name string
    Name of the subnet to be queried.
    RouteTableId string
    ID of the routing table.
    SubnetId string
    ID of the subnet to be queried.
    Tags map[string]string
    Tags of the subnet to be queried.
    VpcId string
    ID of the VPC to be queried.
    availabilityZone String
    Zone of the subnet to be queried.
    availableIpCount Double
    The number of available IPs.
    cdcId String
    ID of CDC instance.
    cidrBlock String
    Filter subnet with this CIDR.
    createTime String
    Creation time of the subnet resource.
    isDefault Boolean
    Filter default or no default subnets.
    isMulticast Boolean
    Indicates whether multicast is enabled.
    name String
    Name of the subnet to be queried.
    routeTableId String
    ID of the routing table.
    subnetId String
    ID of the subnet to be queried.
    tags Map<String,String>
    Tags of the subnet to be queried.
    vpcId String
    ID of the VPC to be queried.
    availabilityZone string
    Zone of the subnet to be queried.
    availableIpCount number
    The number of available IPs.
    cdcId string
    ID of CDC instance.
    cidrBlock string
    Filter subnet with this CIDR.
    createTime string
    Creation time of the subnet resource.
    isDefault boolean
    Filter default or no default subnets.
    isMulticast boolean
    Indicates whether multicast is enabled.
    name string
    Name of the subnet to be queried.
    routeTableId string
    ID of the routing table.
    subnetId string
    ID of the subnet to be queried.
    tags {[key: string]: string}
    Tags of the subnet to be queried.
    vpcId string
    ID of the VPC to be queried.
    availability_zone str
    Zone of the subnet to be queried.
    available_ip_count float
    The number of available IPs.
    cdc_id str
    ID of CDC instance.
    cidr_block str
    Filter subnet with this CIDR.
    create_time str
    Creation time of the subnet resource.
    is_default bool
    Filter default or no default subnets.
    is_multicast bool
    Indicates whether multicast is enabled.
    name str
    Name of the subnet to be queried.
    route_table_id str
    ID of the routing table.
    subnet_id str
    ID of the subnet to be queried.
    tags Mapping[str, str]
    Tags of the subnet to be queried.
    vpc_id str
    ID of the VPC to be queried.
    availabilityZone String
    Zone of the subnet to be queried.
    availableIpCount Number
    The number of available IPs.
    cdcId String
    ID of CDC instance.
    cidrBlock String
    Filter subnet with this CIDR.
    createTime String
    Creation time of the subnet resource.
    isDefault Boolean
    Filter default or no default subnets.
    isMulticast Boolean
    Indicates whether multicast is enabled.
    name String
    Name of the subnet to be queried.
    routeTableId String
    ID of the routing table.
    subnetId String
    ID of the subnet to be queried.
    tags Map<String>
    Tags of the subnet to be queried.
    vpcId String
    ID of the VPC to be queried.

    Package Details

    Repository
    tencentcloud tencentcloudstack/terraform-provider-tencentcloud
    License
    Notes
    This Pulumi package is based on the tencentcloud Terraform Provider.
    tencentcloud logo
    tencentcloud 1.81.189 published on Wednesday, Apr 30, 2025 by tencentcloudstack