title: "getSubnet" title_tag: "huaweicloud.Vpc.getSubnet" meta_desc: "Documentation for the huaweicloud.Vpc.getSubnet function with examples, input properties, output properties, and supporting types." layout: api no_edit_this_page: true


Provides details about a specific VPC subnet.

This resource can prove useful when a module accepts a subnet id as an input variable and needs to, for example, determine the id of the VPC that the subnet belongs to.

Attributes Reference

In addition to all arguments above, the following attributes are exported:

  • dns_list - The IP address list of DNS servers on the subnet.

  • dhcp_enable - Whether the DHCP is enabled.

  • description - The description of the subnet.

  • ipv4_subnet_id - The ID of the IPv4 subnet (Native OpenStack API).

  • ipv6_enable - Whether the IPv6 is enabled.

  • ipv6_subnet_id - The ID of the IPv6 subnet (Native OpenStack API).

  • ipv6_cidr - The IPv6 subnet CIDR block.

  • ipv6_gateway - The IPv6 subnet gateway.

## Example Usage
using System.Collections.Generic;
using Pulumi;
using Huaweicloud = Pulumi.Huaweicloud;

return await Deployment.RunAsync(() => 
{
    var subnet = Huaweicloud.Vpc.GetSubnet.Invoke(new()
    {
        Id = @var.Subnet_id,
    });

    return new Dictionary<string, object?>
    {
        ["subnetVpcId"] = subnet.Apply(getSubnetResult => getSubnetResult.VpcId),
    };
});
package main

import (
    "github.com/huaweicloud/pulumi-huaweicloud/sdk/go/huaweicloud/Vpc"
    "github.com/pulumi/pulumi-huaweicloud/sdk/go/huaweicloud/Vpc"
    "github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
    pulumi.Run(func(ctx *pulumi.Context) error {
        subnet, err := Vpc.GetSubnet(ctx, &vpc.GetSubnetArgs{
            Id: pulumi.StringRef(_var.Subnet_id),
        }, nil)
        if err != nil {
            return err
        }
        ctx.Export("subnetVpcId", subnet.VpcId)
        return nil
    })
}
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.huaweicloud.Vpc.VpcFunctions;
import com.pulumi.huaweicloud.Vpc.inputs.GetSubnetArgs;
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 subnet = VpcFunctions.getSubnet(GetSubnetArgs.builder()
            .id(var_.subnet_id())
            .build());

        ctx.export("subnetVpcId", subnet.applyValue(getSubnetResult -> getSubnetResult.vpcId()));
    }
}
import pulumi
import pulumi_huaweicloud as huaweicloud

subnet = huaweicloud.Vpc.get_subnet(id=var["subnet_id"])
pulumi.export("subnetVpcId", subnet.vpc_id)
import * as pulumi from "@pulumi/pulumi";
import * as huaweicloud from "@pulumi/huaweicloud";

const subnet = huaweicloud.Vpc.getSubnet({
    id: _var.subnet_id,
});
export const subnetVpcId = subnet.then(subnet => subnet.vpcId);
variables:
  subnet:
    Fn::Invoke:
      Function: huaweicloud:Vpc:getSubnet
      Arguments:
        id: ${var.subnet_id}
outputs:
  subnetVpcId: ${subnet.vpcId}

Using getSubnet {#using}

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 getSubnet(args: GetSubnetArgs, opts?: InvokeOptions): Promise<GetSubnetResult>
function getSubnetOutput(args: GetSubnetOutputArgs, opts?: InvokeOptions): Output<GetSubnetResult>
def get_subnet(availability_zone: Optional[str] = None,
               cidr: Optional[str] = None,
               gateway_ip: Optional[str] = None,
               id: Optional[str] = None,
               name: Optional[str] = None,
               primary_dns: Optional[str] = None,
               region: Optional[str] = None,
               secondary_dns: Optional[str] = None,
               status: Optional[str] = None,
               vpc_id: Optional[str] = None,
               opts: Optional[InvokeOptions] = None) -> GetSubnetResult
def get_subnet_output(availability_zone: Optional[pulumi.Input[str]] = None,
               cidr: Optional[pulumi.Input[str]] = None,
               gateway_ip: Optional[pulumi.Input[str]] = None,
               id: Optional[pulumi.Input[str]] = None,
               name: Optional[pulumi.Input[str]] = None,
               primary_dns: Optional[pulumi.Input[str]] = None,
               region: Optional[pulumi.Input[str]] = None,
               secondary_dns: Optional[pulumi.Input[str]] = None,
               status: Optional[pulumi.Input[str]] = None,
               vpc_id: Optional[pulumi.Input[str]] = None,
               opts: Optional[InvokeOptions] = None) -> Output[GetSubnetResult]
func GetSubnet(ctx *Context, args *GetSubnetArgs, opts ...InvokeOption) (*GetSubnetResult, error)
func GetSubnetOutput(ctx *Context, args *GetSubnetOutputArgs, opts ...InvokeOption) GetSubnetResultOutput

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

public static class GetSubnet 
{
    public static Task<GetSubnetResult> InvokeAsync(GetSubnetArgs args, InvokeOptions? opts = null)
    public static Output<GetSubnetResult> Invoke(GetSubnetInvokeArgs args, InvokeOptions? opts = null)
}
public static CompletableFuture<GetSubnetResult> getSubnet(GetSubnetArgs args, InvokeOptions options)
// Output-based functions aren't available in Java yet
Fn::Invoke:
  Function: huaweicloud:Vpc/getSubnet:getSubnet
  Arguments:
    # Arguments dictionary

The following arguments are supported:

AvailabilityZone string

Specifies the availability zone (AZ) to which the subnet should belong.

Cidr string

Specifies the network segment of specific subnet to retrieve. The value must be in CIDR format.

GatewayIp string

Specifies the subnet gateway address of specific subnet.

Id string
  • Specifies a resource ID in UUID format.
Name string

Specifies the name of the specific subnet to retrieve.

PrimaryDns string

Specifies the IP address of DNS server 1 on the specific subnet.

Region string

Specifies the region in which to obtain the subnet. If omitted, the provider-level region will be used.

SecondaryDns string

Specifies the IP address of DNS server 2 on the specific subnet.

Status string

Specifies the value can be ACTIVE, DOWN, UNKNOWN, or ERROR.

VpcId string

Specifies the id of the VPC that the desired subnet belongs to.

AvailabilityZone string

Specifies the availability zone (AZ) to which the subnet should belong.

Cidr string

Specifies the network segment of specific subnet to retrieve. The value must be in CIDR format.

GatewayIp string

Specifies the subnet gateway address of specific subnet.

Id string
  • Specifies a resource ID in UUID format.
Name string

Specifies the name of the specific subnet to retrieve.

PrimaryDns string

Specifies the IP address of DNS server 1 on the specific subnet.

Region string

Specifies the region in which to obtain the subnet. If omitted, the provider-level region will be used.

SecondaryDns string

Specifies the IP address of DNS server 2 on the specific subnet.

Status string

Specifies the value can be ACTIVE, DOWN, UNKNOWN, or ERROR.

VpcId string

Specifies the id of the VPC that the desired subnet belongs to.

availabilityZone String

Specifies the availability zone (AZ) to which the subnet should belong.

cidr String

Specifies the network segment of specific subnet to retrieve. The value must be in CIDR format.

gatewayIp String

Specifies the subnet gateway address of specific subnet.

id String
  • Specifies a resource ID in UUID format.
name String

Specifies the name of the specific subnet to retrieve.

primaryDns String

Specifies the IP address of DNS server 1 on the specific subnet.

region String

Specifies the region in which to obtain the subnet. If omitted, the provider-level region will be used.

secondaryDns String

Specifies the IP address of DNS server 2 on the specific subnet.

status String

Specifies the value can be ACTIVE, DOWN, UNKNOWN, or ERROR.

vpcId String

Specifies the id of the VPC that the desired subnet belongs to.

availabilityZone string

Specifies the availability zone (AZ) to which the subnet should belong.

cidr string

Specifies the network segment of specific subnet to retrieve. The value must be in CIDR format.

gatewayIp string

Specifies the subnet gateway address of specific subnet.

id string
  • Specifies a resource ID in UUID format.
name string

Specifies the name of the specific subnet to retrieve.

primaryDns string

Specifies the IP address of DNS server 1 on the specific subnet.

region string

Specifies the region in which to obtain the subnet. If omitted, the provider-level region will be used.

secondaryDns string

Specifies the IP address of DNS server 2 on the specific subnet.

status string

Specifies the value can be ACTIVE, DOWN, UNKNOWN, or ERROR.

vpcId string

Specifies the id of the VPC that the desired subnet belongs to.

availability_zone str

Specifies the availability zone (AZ) to which the subnet should belong.

cidr str

Specifies the network segment of specific subnet to retrieve. The value must be in CIDR format.

gateway_ip str

Specifies the subnet gateway address of specific subnet.

id str
  • Specifies a resource ID in UUID format.
name str

Specifies the name of the specific subnet to retrieve.

primary_dns str

Specifies the IP address of DNS server 1 on the specific subnet.

region str

Specifies the region in which to obtain the subnet. If omitted, the provider-level region will be used.

secondary_dns str

Specifies the IP address of DNS server 2 on the specific subnet.

status str

Specifies the value can be ACTIVE, DOWN, UNKNOWN, or ERROR.

vpc_id str

Specifies the id of the VPC that the desired subnet belongs to.

availabilityZone String

Specifies the availability zone (AZ) to which the subnet should belong.

cidr String

Specifies the network segment of specific subnet to retrieve. The value must be in CIDR format.

gatewayIp String

Specifies the subnet gateway address of specific subnet.

id String
  • Specifies a resource ID in UUID format.
name String

Specifies the name of the specific subnet to retrieve.

primaryDns String

Specifies the IP address of DNS server 1 on the specific subnet.

region String

Specifies the region in which to obtain the subnet. If omitted, the provider-level region will be used.

secondaryDns String

Specifies the IP address of DNS server 2 on the specific subnet.

status String

Specifies the value can be ACTIVE, DOWN, UNKNOWN, or ERROR.

vpcId String

Specifies the id of the VPC that the desired subnet belongs to.

getSubnet Result {#result}

The following output properties are available:

AvailabilityZone string
Cidr string
Description string
DhcpEnable bool
DnsLists List<string>
GatewayIp string
Id string
Ipv4SubnetId string
Ipv6Cidr string
Ipv6Enable bool
Ipv6Gateway string
Ipv6SubnetId string
Name string
PrimaryDns string
Region string
SecondaryDns string
Status string
SubnetId string
VpcId string
AvailabilityZone string
Cidr string
Description string
DhcpEnable bool
DnsLists []string
GatewayIp string
Id string
Ipv4SubnetId string
Ipv6Cidr string
Ipv6Enable bool
Ipv6Gateway string
Ipv6SubnetId string
Name string
PrimaryDns string
Region string
SecondaryDns string
Status string
SubnetId string
VpcId string
availabilityZone String
cidr String
description String
dhcpEnable Boolean
dnsLists List<String>
gatewayIp String
id String
ipv4SubnetId String
ipv6Cidr String
ipv6Enable Boolean
ipv6Gateway String
ipv6SubnetId String
name String
primaryDns String
region String
secondaryDns String
status String
subnetId String
vpcId String
availabilityZone string
cidr string
description string
dhcpEnable boolean
dnsLists string[]
gatewayIp string
id string
ipv4SubnetId string
ipv6Cidr string
ipv6Enable boolean
ipv6Gateway string
ipv6SubnetId string
name string
primaryDns string
region string
secondaryDns string
status string
subnetId string
vpcId string
availabilityZone String
cidr String
description String
dhcpEnable Boolean
dnsLists List<String>
gatewayIp String
id String
ipv4SubnetId String
ipv6Cidr String
ipv6Enable Boolean
ipv6Gateway String
ipv6SubnetId String
name String
primaryDns String
region String
secondaryDns String
status String
subnetId String
vpcId String

Package Details

Repository
https://github.com/huaweicloud/pulumi-huaweicloud
License
Apache-2.0
Notes

This Pulumi package is based on the huaweicloud Terraform Provider.