1. Packages
  2. Tencentcloud Provider
  3. API Docs
  4. Subnet
tencentcloud 1.81.183 published on Wednesday, Apr 16, 2025 by tencentcloudstack

tencentcloud.Subnet

Explore with Pulumi AI

Provide a resource to create a VPC subnet.

Example Usage

Create a normal VPC subnet

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

const zones = tencentcloud.getAvailabilityZones({});
const vpc = new tencentcloud.Vpc("vpc", {cidrBlock: "10.0.0.0/16"});
const subnet = new tencentcloud.Subnet("subnet", {
    vpcId: vpc.vpcId,
    cidrBlock: "10.0.0.0/16",
    availabilityZone: zones.then(zones => zones.zones?.[0]?.name),
    isMulticast: false,
});
Copy
import pulumi
import pulumi_tencentcloud as tencentcloud

zones = tencentcloud.get_availability_zones()
vpc = tencentcloud.Vpc("vpc", cidr_block="10.0.0.0/16")
subnet = tencentcloud.Subnet("subnet",
    vpc_id=vpc.vpc_id,
    cidr_block="10.0.0.0/16",
    availability_zone=zones.zones[0].name,
    is_multicast=False)
Copy
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 {
		zones, err := tencentcloud.GetAvailabilityZones(ctx, &tencentcloud.GetAvailabilityZonesArgs{}, nil)
		if err != nil {
			return err
		}
		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{
			VpcId:            vpc.VpcId,
			CidrBlock:        pulumi.String("10.0.0.0/16"),
			AvailabilityZone: pulumi.String(zones.Zones[0].Name),
			IsMulticast:      pulumi.Bool(false),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
Copy
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Tencentcloud = Pulumi.Tencentcloud;

return await Deployment.RunAsync(() => 
{
    var zones = Tencentcloud.GetAvailabilityZones.Invoke();

    var vpc = new Tencentcloud.Vpc("vpc", new()
    {
        CidrBlock = "10.0.0.0/16",
    });

    var subnet = new Tencentcloud.Subnet("subnet", new()
    {
        VpcId = vpc.VpcId,
        CidrBlock = "10.0.0.0/16",
        AvailabilityZone = zones.Apply(getAvailabilityZonesResult => getAvailabilityZonesResult.Zones[0]?.Name),
        IsMulticast = false,
    });

});
Copy
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.GetAvailabilityZonesArgs;
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 zones = TencentcloudFunctions.getAvailabilityZones();

        var vpc = new Vpc("vpc", VpcArgs.builder()
            .cidrBlock("10.0.0.0/16")
            .build());

        var subnet = new Subnet("subnet", SubnetArgs.builder()
            .vpcId(vpc.vpcId())
            .cidrBlock("10.0.0.0/16")
            .availabilityZone(zones.applyValue(getAvailabilityZonesResult -> getAvailabilityZonesResult.zones()[0].name()))
            .isMulticast(false)
            .build());

    }
}
Copy
resources:
  vpc:
    type: tencentcloud:Vpc
    properties:
      cidrBlock: 10.0.0.0/16
  subnet:
    type: tencentcloud:Subnet
    properties:
      vpcId: ${vpc.vpcId}
      cidrBlock: 10.0.0.0/16
      availabilityZone: ${zones.zones[0].name}
      isMulticast: false
variables:
  zones:
    fn::invoke:
      function: tencentcloud:getAvailabilityZones
      arguments: {}
Copy

Create a CDC instance VPC subnet

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

const zones = tencentcloud.getAvailabilityZones({});
const vpc = new tencentcloud.Vpc("vpc", {cidrBlock: "10.0.0.0/16"});
const subnet = new tencentcloud.Subnet("subnet", {
    vpcId: vpc.vpcId,
    cidrBlock: "10.0.0.0/16",
    cdcId: "cluster-lchwgxhs",
    availabilityZone: zones.then(zones => zones.zones?.[0]?.name),
    isMulticast: false,
});
Copy
import pulumi
import pulumi_tencentcloud as tencentcloud

zones = tencentcloud.get_availability_zones()
vpc = tencentcloud.Vpc("vpc", cidr_block="10.0.0.0/16")
subnet = tencentcloud.Subnet("subnet",
    vpc_id=vpc.vpc_id,
    cidr_block="10.0.0.0/16",
    cdc_id="cluster-lchwgxhs",
    availability_zone=zones.zones[0].name,
    is_multicast=False)
Copy
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 {
		zones, err := tencentcloud.GetAvailabilityZones(ctx, &tencentcloud.GetAvailabilityZonesArgs{}, nil)
		if err != nil {
			return err
		}
		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{
			VpcId:            vpc.VpcId,
			CidrBlock:        pulumi.String("10.0.0.0/16"),
			CdcId:            pulumi.String("cluster-lchwgxhs"),
			AvailabilityZone: pulumi.String(zones.Zones[0].Name),
			IsMulticast:      pulumi.Bool(false),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
Copy
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Tencentcloud = Pulumi.Tencentcloud;

return await Deployment.RunAsync(() => 
{
    var zones = Tencentcloud.GetAvailabilityZones.Invoke();

    var vpc = new Tencentcloud.Vpc("vpc", new()
    {
        CidrBlock = "10.0.0.0/16",
    });

    var subnet = new Tencentcloud.Subnet("subnet", new()
    {
        VpcId = vpc.VpcId,
        CidrBlock = "10.0.0.0/16",
        CdcId = "cluster-lchwgxhs",
        AvailabilityZone = zones.Apply(getAvailabilityZonesResult => getAvailabilityZonesResult.Zones[0]?.Name),
        IsMulticast = false,
    });

});
Copy
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.GetAvailabilityZonesArgs;
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 zones = TencentcloudFunctions.getAvailabilityZones();

        var vpc = new Vpc("vpc", VpcArgs.builder()
            .cidrBlock("10.0.0.0/16")
            .build());

        var subnet = new Subnet("subnet", SubnetArgs.builder()
            .vpcId(vpc.vpcId())
            .cidrBlock("10.0.0.0/16")
            .cdcId("cluster-lchwgxhs")
            .availabilityZone(zones.applyValue(getAvailabilityZonesResult -> getAvailabilityZonesResult.zones()[0].name()))
            .isMulticast(false)
            .build());

    }
}
Copy
resources:
  vpc:
    type: tencentcloud:Vpc
    properties:
      cidrBlock: 10.0.0.0/16
  subnet:
    type: tencentcloud:Subnet
    properties:
      vpcId: ${vpc.vpcId}
      cidrBlock: 10.0.0.0/16
      cdcId: cluster-lchwgxhs
      availabilityZone: ${zones.zones[0].name}
      isMulticast: false
variables:
  zones:
    fn::invoke:
      function: tencentcloud:getAvailabilityZones
      arguments: {}
Copy

Create Subnet Resource

Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.

Constructor syntax

new Subnet(name: string, args: SubnetArgs, opts?: CustomResourceOptions);
@overload
def Subnet(resource_name: str,
           args: SubnetArgs,
           opts: Optional[ResourceOptions] = None)

@overload
def Subnet(resource_name: str,
           opts: Optional[ResourceOptions] = None,
           availability_zone: Optional[str] = None,
           cidr_block: Optional[str] = None,
           vpc_id: Optional[str] = None,
           cdc_id: Optional[str] = None,
           is_multicast: Optional[bool] = None,
           name: Optional[str] = None,
           route_table_id: Optional[str] = None,
           subnet_id: Optional[str] = None,
           tags: Optional[Mapping[str, str]] = None)
func NewSubnet(ctx *Context, name string, args SubnetArgs, opts ...ResourceOption) (*Subnet, error)
public Subnet(string name, SubnetArgs args, CustomResourceOptions? opts = null)
public Subnet(String name, SubnetArgs args)
public Subnet(String name, SubnetArgs args, CustomResourceOptions options)
type: tencentcloud:Subnet
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.

Parameters

name This property is required. string
The unique name of the resource.
args This property is required. SubnetArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name This property is required. str
The unique name of the resource.
args This property is required. SubnetArgs
The arguments to resource properties.
opts ResourceOptions
Bag of options to control resource's behavior.
ctx Context
Context object for the current deployment.
name This property is required. string
The unique name of the resource.
args This property is required. SubnetArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name This property is required. string
The unique name of the resource.
args This property is required. SubnetArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
name This property is required. String
The unique name of the resource.
args This property is required. SubnetArgs
The arguments to resource properties.
options CustomResourceOptions
Bag of options to control resource's behavior.

Subnet Resource Properties

To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

Inputs

In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.

The Subnet resource accepts the following input properties:

AvailabilityZone This property is required. string
The availability zone within which the subnet should be created.
CidrBlock This property is required. string
A network address block of the subnet.
VpcId This property is required. string
ID of the VPC to be associated.
CdcId string
ID of CDC instance.
IsMulticast bool
Indicates whether multicast is enabled. The default value is 'true'.
Name string
The name of subnet to be created.
RouteTableId string
ID of a routing table to which the subnet should be associated.
SubnetId string
ID of the resource.
Tags Dictionary<string, string>
Tags of the subnet.
AvailabilityZone This property is required. string
The availability zone within which the subnet should be created.
CidrBlock This property is required. string
A network address block of the subnet.
VpcId This property is required. string
ID of the VPC to be associated.
CdcId string
ID of CDC instance.
IsMulticast bool
Indicates whether multicast is enabled. The default value is 'true'.
Name string
The name of subnet to be created.
RouteTableId string
ID of a routing table to which the subnet should be associated.
SubnetId string
ID of the resource.
Tags map[string]string
Tags of the subnet.
availabilityZone This property is required. String
The availability zone within which the subnet should be created.
cidrBlock This property is required. String
A network address block of the subnet.
vpcId This property is required. String
ID of the VPC to be associated.
cdcId String
ID of CDC instance.
isMulticast Boolean
Indicates whether multicast is enabled. The default value is 'true'.
name String
The name of subnet to be created.
routeTableId String
ID of a routing table to which the subnet should be associated.
subnetId String
ID of the resource.
tags Map<String,String>
Tags of the subnet.
availabilityZone This property is required. string
The availability zone within which the subnet should be created.
cidrBlock This property is required. string
A network address block of the subnet.
vpcId This property is required. string
ID of the VPC to be associated.
cdcId string
ID of CDC instance.
isMulticast boolean
Indicates whether multicast is enabled. The default value is 'true'.
name string
The name of subnet to be created.
routeTableId string
ID of a routing table to which the subnet should be associated.
subnetId string
ID of the resource.
tags {[key: string]: string}
Tags of the subnet.
availability_zone This property is required. str
The availability zone within which the subnet should be created.
cidr_block This property is required. str
A network address block of the subnet.
vpc_id This property is required. str
ID of the VPC to be associated.
cdc_id str
ID of CDC instance.
is_multicast bool
Indicates whether multicast is enabled. The default value is 'true'.
name str
The name of subnet to be created.
route_table_id str
ID of a routing table to which the subnet should be associated.
subnet_id str
ID of the resource.
tags Mapping[str, str]
Tags of the subnet.
availabilityZone This property is required. String
The availability zone within which the subnet should be created.
cidrBlock This property is required. String
A network address block of the subnet.
vpcId This property is required. String
ID of the VPC to be associated.
cdcId String
ID of CDC instance.
isMulticast Boolean
Indicates whether multicast is enabled. The default value is 'true'.
name String
The name of subnet to be created.
routeTableId String
ID of a routing table to which the subnet should be associated.
subnetId String
ID of the resource.
tags Map<String>
Tags of the subnet.

Outputs

All input properties are implicitly available as output properties. Additionally, the Subnet resource produces the following output properties:

AvailableIpCount double
The number of available IPs.
CreateTime string
Creation time of subnet resource.
Id string
The provider-assigned unique ID for this managed resource.
IsDefault bool
Indicates whether it is the default VPC for this region.
AvailableIpCount float64
The number of available IPs.
CreateTime string
Creation time of subnet resource.
Id string
The provider-assigned unique ID for this managed resource.
IsDefault bool
Indicates whether it is the default VPC for this region.
availableIpCount Double
The number of available IPs.
createTime String
Creation time of subnet resource.
id String
The provider-assigned unique ID for this managed resource.
isDefault Boolean
Indicates whether it is the default VPC for this region.
availableIpCount number
The number of available IPs.
createTime string
Creation time of subnet resource.
id string
The provider-assigned unique ID for this managed resource.
isDefault boolean
Indicates whether it is the default VPC for this region.
available_ip_count float
The number of available IPs.
create_time str
Creation time of subnet resource.
id str
The provider-assigned unique ID for this managed resource.
is_default bool
Indicates whether it is the default VPC for this region.
availableIpCount Number
The number of available IPs.
createTime String
Creation time of subnet resource.
id String
The provider-assigned unique ID for this managed resource.
isDefault Boolean
Indicates whether it is the default VPC for this region.

Look up Existing Subnet Resource

Get an existing Subnet resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

public static get(name: string, id: Input<ID>, state?: SubnetState, opts?: CustomResourceOptions): Subnet
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        availability_zone: Optional[str] = None,
        available_ip_count: Optional[float] = None,
        cdc_id: Optional[str] = None,
        cidr_block: Optional[str] = None,
        create_time: Optional[str] = None,
        is_default: Optional[bool] = None,
        is_multicast: Optional[bool] = None,
        name: Optional[str] = None,
        route_table_id: Optional[str] = None,
        subnet_id: Optional[str] = None,
        tags: Optional[Mapping[str, str]] = None,
        vpc_id: Optional[str] = None) -> Subnet
func GetSubnet(ctx *Context, name string, id IDInput, state *SubnetState, opts ...ResourceOption) (*Subnet, error)
public static Subnet Get(string name, Input<string> id, SubnetState? state, CustomResourceOptions? opts = null)
public static Subnet get(String name, Output<String> id, SubnetState state, CustomResourceOptions options)
resources:  _:    type: tencentcloud:Subnet    get:      id: ${id}
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
resource_name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
The following state arguments are supported:
AvailabilityZone string
The availability zone within which the subnet should be created.
AvailableIpCount double
The number of available IPs.
CdcId string
ID of CDC instance.
CidrBlock string
A network address block of the subnet.
CreateTime string
Creation time of subnet resource.
IsDefault bool
Indicates whether it is the default VPC for this region.
IsMulticast bool
Indicates whether multicast is enabled. The default value is 'true'.
Name string
The name of subnet to be created.
RouteTableId string
ID of a routing table to which the subnet should be associated.
SubnetId string
ID of the resource.
Tags Dictionary<string, string>
Tags of the subnet.
VpcId string
ID of the VPC to be associated.
AvailabilityZone string
The availability zone within which the subnet should be created.
AvailableIpCount float64
The number of available IPs.
CdcId string
ID of CDC instance.
CidrBlock string
A network address block of the subnet.
CreateTime string
Creation time of subnet resource.
IsDefault bool
Indicates whether it is the default VPC for this region.
IsMulticast bool
Indicates whether multicast is enabled. The default value is 'true'.
Name string
The name of subnet to be created.
RouteTableId string
ID of a routing table to which the subnet should be associated.
SubnetId string
ID of the resource.
Tags map[string]string
Tags of the subnet.
VpcId string
ID of the VPC to be associated.
availabilityZone String
The availability zone within which the subnet should be created.
availableIpCount Double
The number of available IPs.
cdcId String
ID of CDC instance.
cidrBlock String
A network address block of the subnet.
createTime String
Creation time of subnet resource.
isDefault Boolean
Indicates whether it is the default VPC for this region.
isMulticast Boolean
Indicates whether multicast is enabled. The default value is 'true'.
name String
The name of subnet to be created.
routeTableId String
ID of a routing table to which the subnet should be associated.
subnetId String
ID of the resource.
tags Map<String,String>
Tags of the subnet.
vpcId String
ID of the VPC to be associated.
availabilityZone string
The availability zone within which the subnet should be created.
availableIpCount number
The number of available IPs.
cdcId string
ID of CDC instance.
cidrBlock string
A network address block of the subnet.
createTime string
Creation time of subnet resource.
isDefault boolean
Indicates whether it is the default VPC for this region.
isMulticast boolean
Indicates whether multicast is enabled. The default value is 'true'.
name string
The name of subnet to be created.
routeTableId string
ID of a routing table to which the subnet should be associated.
subnetId string
ID of the resource.
tags {[key: string]: string}
Tags of the subnet.
vpcId string
ID of the VPC to be associated.
availability_zone str
The availability zone within which the subnet should be created.
available_ip_count float
The number of available IPs.
cdc_id str
ID of CDC instance.
cidr_block str
A network address block of the subnet.
create_time str
Creation time of subnet resource.
is_default bool
Indicates whether it is the default VPC for this region.
is_multicast bool
Indicates whether multicast is enabled. The default value is 'true'.
name str
The name of subnet to be created.
route_table_id str
ID of a routing table to which the subnet should be associated.
subnet_id str
ID of the resource.
tags Mapping[str, str]
Tags of the subnet.
vpc_id str
ID of the VPC to be associated.
availabilityZone String
The availability zone within which the subnet should be created.
availableIpCount Number
The number of available IPs.
cdcId String
ID of CDC instance.
cidrBlock String
A network address block of the subnet.
createTime String
Creation time of subnet resource.
isDefault Boolean
Indicates whether it is the default VPC for this region.
isMulticast Boolean
Indicates whether multicast is enabled. The default value is 'true'.
name String
The name of subnet to be created.
routeTableId String
ID of a routing table to which the subnet should be associated.
subnetId String
ID of the resource.
tags Map<String>
Tags of the subnet.
vpcId String
ID of the VPC to be associated.

Import

Vpc subnet instance can be imported, e.g.

$ pulumi import tencentcloud:index/subnet:Subnet subnet subnet-b8j03v0c
Copy

To learn more about importing existing cloud resources, see Importing resources.

Package Details

Repository
tencentcloud tencentcloudstack/terraform-provider-tencentcloud
License
Notes
This Pulumi package is based on the tencentcloud Terraform Provider.