1. Packages
  2. Gcorelabs Provider
  3. API Docs
  4. Subnet
gcorelabs 0.3.63 published on Monday, Apr 14, 2025 by g-core

gcorelabs.Subnet

Explore with Pulumi AI

Represent subnets. Subnetwork is a range of IP addresses in a cloud network. Addresses from this range will be assigned to machines in the cloud

Example Usage

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

const network = new gcore.index.Gcore_network("network", {
    name: "network_example",
    mtu: 1450,
    type: "vxlan",
    regionId: 1,
    projectId: 1,
});
const subnet = new gcore.index.Gcore_subnet("subnet", {
    name: "subnet_example",
    cidr: "192.168.10.0/24",
    networkId: network.id,
    dnsNameservers: _var.dns_nameservers,
    dynamic: [{
        iterator: hr,
        forEach: _var.host_routes,
        content: [{
            destination: hr.value.destination,
            nexthop: hr.value.nexthop,
        }],
    }],
    gatewayIp: "192.168.10.1",
    regionId: 1,
    projectId: 1,
});
Copy
import pulumi
import pulumi_gcore as gcore

network = gcore.index.Gcore_network("network",
    name=network_example,
    mtu=1450,
    type=vxlan,
    region_id=1,
    project_id=1)
subnet = gcore.index.Gcore_subnet("subnet",
    name=subnet_example,
    cidr=192.168.10.0/24,
    network_id=network.id,
    dns_nameservers=var.dns_nameservers,
    dynamic=[{
        iterator: hr,
        forEach: var.host_routes,
        content: [{
            destination: hr.value.destination,
            nexthop: hr.value.nexthop,
        }],
    }],
    gateway_ip=192.168.10.1,
    region_id=1,
    project_id=1)
Copy
package main

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

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		network, err := gcore.NewGcore_network(ctx, "network", &gcore.Gcore_networkArgs{
			Name:      "network_example",
			Mtu:       1450,
			Type:      "vxlan",
			RegionId:  1,
			ProjectId: 1,
		})
		if err != nil {
			return err
		}
		_, err = gcore.NewGcore_subnet(ctx, "subnet", &gcore.Gcore_subnetArgs{
			Name:           "subnet_example",
			Cidr:           "192.168.10.0/24",
			NetworkId:      network.Id,
			DnsNameservers: _var.Dns_nameservers,
			Dynamic: []map[string]interface{}{
				map[string]interface{}{
					"iterator": hr,
					"forEach":  _var.Host_routes,
					"content": []map[string]interface{}{
						map[string]interface{}{
							"destination": hr.Value.Destination,
							"nexthop":     hr.Value.Nexthop,
						},
					},
				},
			},
			GatewayIp: "192.168.10.1",
			RegionId:  1,
			ProjectId: 1,
		})
		if err != nil {
			return err
		}
		return nil
	})
}
Copy
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Gcore = Pulumi.Gcore;

return await Deployment.RunAsync(() => 
{
    var network = new Gcore.Index.Gcore_network("network", new()
    {
        Name = "network_example",
        Mtu = 1450,
        Type = "vxlan",
        RegionId = 1,
        ProjectId = 1,
    });

    var subnet = new Gcore.Index.Gcore_subnet("subnet", new()
    {
        Name = "subnet_example",
        Cidr = "192.168.10.0/24",
        NetworkId = network.Id,
        DnsNameservers = @var.Dns_nameservers,
        Dynamic = new[]
        {
            
            {
                { "iterator", hr },
                { "forEach", @var.Host_routes },
                { "content", new[]
                {
                    
                    {
                        { "destination", hr.Value.Destination },
                        { "nexthop", hr.Value.Nexthop },
                    },
                } },
            },
        },
        GatewayIp = "192.168.10.1",
        RegionId = 1,
        ProjectId = 1,
    });

});
Copy
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcore.gcore_network;
import com.pulumi.gcore.Gcore_networkArgs;
import com.pulumi.gcore.gcore_subnet;
import com.pulumi.gcore.Gcore_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) {
        var network = new Gcore_network("network", Gcore_networkArgs.builder()
            .name("network_example")
            .mtu(1450)
            .type("vxlan")
            .regionId(1)
            .projectId(1)
            .build());

        var subnet = new Gcore_subnet("subnet", Gcore_subnetArgs.builder()
            .name("subnet_example")
            .cidr("192.168.10.0/24")
            .networkId(network.id())
            .dnsNameservers(var_.dns_nameservers())
            .dynamic(%!v(PANIC=Format method: runtime error: invalid memory address or nil pointer dereference))
            .gatewayIp("192.168.10.1")
            .regionId(1)
            .projectId(1)
            .build());

    }
}
Copy
resources:
  network:
    type: gcore:gcore_network
    properties:
      name: network_example
      mtu: 1450
      type: vxlan
      regionId: 1
      projectId: 1
  subnet:
    type: gcore:gcore_subnet
    properties:
      name: subnet_example
      cidr: 192.168.10.0/24
      networkId: ${network.id}
      dnsNameservers: ${var.dns_nameservers}
      dynamic:
        - iterator: ${hr}
          forEach: ${var.host_routes}
          content:
            - destination: ${hr.value.destination}
              nexthop: ${hr.value.nexthop}
      gatewayIp: 192.168.10.1
      regionId: 1
      projectId: 1
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,
           cidr: Optional[str] = None,
           network_id: Optional[str] = None,
           enable_dhcp: Optional[bool] = None,
           dns_nameservers: Optional[Sequence[str]] = None,
           gateway_ip: Optional[str] = None,
           host_routes: Optional[Sequence[SubnetHostRouteArgs]] = None,
           last_updated: Optional[str] = None,
           metadata_map: Optional[Mapping[str, str]] = None,
           name: Optional[str] = None,
           connect_to_network_router: Optional[bool] = None,
           project_id: Optional[float] = None,
           project_name: Optional[str] = None,
           region_id: Optional[float] = None,
           region_name: Optional[str] = None,
           subnet_id: Optional[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: gcorelabs: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.

Constructor example

The following reference example uses placeholder values for all input properties.

var subnetResource = new Gcorelabs.Subnet("subnetResource", new()
{
    Cidr = "string",
    NetworkId = "string",
    EnableDhcp = false,
    DnsNameservers = new[]
    {
        "string",
    },
    GatewayIp = "string",
    HostRoutes = new[]
    {
        new Gcorelabs.Inputs.SubnetHostRouteArgs
        {
            Destination = "string",
            Nexthop = "string",
        },
    },
    LastUpdated = "string",
    MetadataMap = 
    {
        { "string", "string" },
    },
    Name = "string",
    ConnectToNetworkRouter = false,
    ProjectId = 0,
    ProjectName = "string",
    RegionId = 0,
    RegionName = "string",
    SubnetId = "string",
});
Copy
example, err := gcorelabs.NewSubnet(ctx, "subnetResource", &gcorelabs.SubnetArgs{
Cidr: pulumi.String("string"),
NetworkId: pulumi.String("string"),
EnableDhcp: pulumi.Bool(false),
DnsNameservers: pulumi.StringArray{
pulumi.String("string"),
},
GatewayIp: pulumi.String("string"),
HostRoutes: .SubnetHostRouteArray{
&.SubnetHostRouteArgs{
Destination: pulumi.String("string"),
Nexthop: pulumi.String("string"),
},
},
LastUpdated: pulumi.String("string"),
MetadataMap: pulumi.StringMap{
"string": pulumi.String("string"),
},
Name: pulumi.String("string"),
ConnectToNetworkRouter: pulumi.Bool(false),
ProjectId: pulumi.Float64(0),
ProjectName: pulumi.String("string"),
RegionId: pulumi.Float64(0),
RegionName: pulumi.String("string"),
SubnetId: pulumi.String("string"),
})
Copy
var subnetResource = new Subnet("subnetResource", SubnetArgs.builder()
    .cidr("string")
    .networkId("string")
    .enableDhcp(false)
    .dnsNameservers("string")
    .gatewayIp("string")
    .hostRoutes(SubnetHostRouteArgs.builder()
        .destination("string")
        .nexthop("string")
        .build())
    .lastUpdated("string")
    .metadataMap(Map.of("string", "string"))
    .name("string")
    .connectToNetworkRouter(false)
    .projectId(0)
    .projectName("string")
    .regionId(0)
    .regionName("string")
    .subnetId("string")
    .build());
Copy
subnet_resource = gcorelabs.Subnet("subnetResource",
    cidr="string",
    network_id="string",
    enable_dhcp=False,
    dns_nameservers=["string"],
    gateway_ip="string",
    host_routes=[{
        "destination": "string",
        "nexthop": "string",
    }],
    last_updated="string",
    metadata_map={
        "string": "string",
    },
    name="string",
    connect_to_network_router=False,
    project_id=0,
    project_name="string",
    region_id=0,
    region_name="string",
    subnet_id="string")
Copy
const subnetResource = new gcorelabs.Subnet("subnetResource", {
    cidr: "string",
    networkId: "string",
    enableDhcp: false,
    dnsNameservers: ["string"],
    gatewayIp: "string",
    hostRoutes: [{
        destination: "string",
        nexthop: "string",
    }],
    lastUpdated: "string",
    metadataMap: {
        string: "string",
    },
    name: "string",
    connectToNetworkRouter: false,
    projectId: 0,
    projectName: "string",
    regionId: 0,
    regionName: "string",
    subnetId: "string",
});
Copy
type: gcorelabs:Subnet
properties:
    cidr: string
    connectToNetworkRouter: false
    dnsNameservers:
        - string
    enableDhcp: false
    gatewayIp: string
    hostRoutes:
        - destination: string
          nexthop: string
    lastUpdated: string
    metadataMap:
        string: string
    name: string
    networkId: string
    projectId: 0
    projectName: string
    regionId: 0
    regionName: string
    subnetId: string
Copy

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:

Cidr This property is required. string
NetworkId This property is required. string
ConnectToNetworkRouter bool
True if the network's router should get a gateway in this subnet. Must be explicitly 'false' when gateway_ip is null. Default true.
DnsNameservers List<string>
EnableDhcp bool
GatewayIp string
HostRoutes List<SubnetHostRoute>
LastUpdated string
MetadataMap Dictionary<string, string>
Name string
ProjectId double
ProjectName string
RegionId double
RegionName string
SubnetId string
The ID of this resource.
Cidr This property is required. string
NetworkId This property is required. string
ConnectToNetworkRouter bool
True if the network's router should get a gateway in this subnet. Must be explicitly 'false' when gateway_ip is null. Default true.
DnsNameservers []string
EnableDhcp bool
GatewayIp string
HostRoutes []SubnetHostRouteArgs
LastUpdated string
MetadataMap map[string]string
Name string
ProjectId float64
ProjectName string
RegionId float64
RegionName string
SubnetId string
The ID of this resource.
cidr This property is required. String
networkId This property is required. String
connectToNetworkRouter Boolean
True if the network's router should get a gateway in this subnet. Must be explicitly 'false' when gateway_ip is null. Default true.
dnsNameservers List<String>
enableDhcp Boolean
gatewayIp String
hostRoutes List<SubnetHostRoute>
lastUpdated String
metadataMap Map<String,String>
name String
projectId Double
projectName String
regionId Double
regionName String
subnetId String
The ID of this resource.
cidr This property is required. string
networkId This property is required. string
connectToNetworkRouter boolean
True if the network's router should get a gateway in this subnet. Must be explicitly 'false' when gateway_ip is null. Default true.
dnsNameservers string[]
enableDhcp boolean
gatewayIp string
hostRoutes SubnetHostRoute[]
lastUpdated string
metadataMap {[key: string]: string}
name string
projectId number
projectName string
regionId number
regionName string
subnetId string
The ID of this resource.
cidr This property is required. str
network_id This property is required. str
connect_to_network_router bool
True if the network's router should get a gateway in this subnet. Must be explicitly 'false' when gateway_ip is null. Default true.
dns_nameservers Sequence[str]
enable_dhcp bool
gateway_ip str
host_routes Sequence[SubnetHostRouteArgs]
last_updated str
metadata_map Mapping[str, str]
name str
project_id float
project_name str
region_id float
region_name str
subnet_id str
The ID of this resource.
cidr This property is required. String
networkId This property is required. String
connectToNetworkRouter Boolean
True if the network's router should get a gateway in this subnet. Must be explicitly 'false' when gateway_ip is null. Default true.
dnsNameservers List<String>
enableDhcp Boolean
gatewayIp String
hostRoutes List<Property Map>
lastUpdated String
metadataMap Map<String>
name String
projectId Number
projectName String
regionId Number
regionName String
subnetId String
The ID of this resource.

Outputs

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

Id string
The provider-assigned unique ID for this managed resource.
MetadataReadOnlies List<SubnetMetadataReadOnly>
Id string
The provider-assigned unique ID for this managed resource.
MetadataReadOnlies []SubnetMetadataReadOnly
id String
The provider-assigned unique ID for this managed resource.
metadataReadOnlies List<SubnetMetadataReadOnly>
id string
The provider-assigned unique ID for this managed resource.
metadataReadOnlies SubnetMetadataReadOnly[]
id str
The provider-assigned unique ID for this managed resource.
metadata_read_onlies Sequence[SubnetMetadataReadOnly]
id String
The provider-assigned unique ID for this managed resource.
metadataReadOnlies List<Property Map>

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,
        cidr: Optional[str] = None,
        connect_to_network_router: Optional[bool] = None,
        dns_nameservers: Optional[Sequence[str]] = None,
        enable_dhcp: Optional[bool] = None,
        gateway_ip: Optional[str] = None,
        host_routes: Optional[Sequence[SubnetHostRouteArgs]] = None,
        last_updated: Optional[str] = None,
        metadata_map: Optional[Mapping[str, str]] = None,
        metadata_read_onlies: Optional[Sequence[SubnetMetadataReadOnlyArgs]] = None,
        name: Optional[str] = None,
        network_id: Optional[str] = None,
        project_id: Optional[float] = None,
        project_name: Optional[str] = None,
        region_id: Optional[float] = None,
        region_name: Optional[str] = None,
        subnet_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: gcorelabs: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:
Cidr string
ConnectToNetworkRouter bool
True if the network's router should get a gateway in this subnet. Must be explicitly 'false' when gateway_ip is null. Default true.
DnsNameservers List<string>
EnableDhcp bool
GatewayIp string
HostRoutes List<SubnetHostRoute>
LastUpdated string
MetadataMap Dictionary<string, string>
MetadataReadOnlies List<SubnetMetadataReadOnly>
Name string
NetworkId string
ProjectId double
ProjectName string
RegionId double
RegionName string
SubnetId string
The ID of this resource.
Cidr string
ConnectToNetworkRouter bool
True if the network's router should get a gateway in this subnet. Must be explicitly 'false' when gateway_ip is null. Default true.
DnsNameservers []string
EnableDhcp bool
GatewayIp string
HostRoutes []SubnetHostRouteArgs
LastUpdated string
MetadataMap map[string]string
MetadataReadOnlies []SubnetMetadataReadOnlyArgs
Name string
NetworkId string
ProjectId float64
ProjectName string
RegionId float64
RegionName string
SubnetId string
The ID of this resource.
cidr String
connectToNetworkRouter Boolean
True if the network's router should get a gateway in this subnet. Must be explicitly 'false' when gateway_ip is null. Default true.
dnsNameservers List<String>
enableDhcp Boolean
gatewayIp String
hostRoutes List<SubnetHostRoute>
lastUpdated String
metadataMap Map<String,String>
metadataReadOnlies List<SubnetMetadataReadOnly>
name String
networkId String
projectId Double
projectName String
regionId Double
regionName String
subnetId String
The ID of this resource.
cidr string
connectToNetworkRouter boolean
True if the network's router should get a gateway in this subnet. Must be explicitly 'false' when gateway_ip is null. Default true.
dnsNameservers string[]
enableDhcp boolean
gatewayIp string
hostRoutes SubnetHostRoute[]
lastUpdated string
metadataMap {[key: string]: string}
metadataReadOnlies SubnetMetadataReadOnly[]
name string
networkId string
projectId number
projectName string
regionId number
regionName string
subnetId string
The ID of this resource.
cidr str
connect_to_network_router bool
True if the network's router should get a gateway in this subnet. Must be explicitly 'false' when gateway_ip is null. Default true.
dns_nameservers Sequence[str]
enable_dhcp bool
gateway_ip str
host_routes Sequence[SubnetHostRouteArgs]
last_updated str
metadata_map Mapping[str, str]
metadata_read_onlies Sequence[SubnetMetadataReadOnlyArgs]
name str
network_id str
project_id float
project_name str
region_id float
region_name str
subnet_id str
The ID of this resource.
cidr String
connectToNetworkRouter Boolean
True if the network's router should get a gateway in this subnet. Must be explicitly 'false' when gateway_ip is null. Default true.
dnsNameservers List<String>
enableDhcp Boolean
gatewayIp String
hostRoutes List<Property Map>
lastUpdated String
metadataMap Map<String>
metadataReadOnlies List<Property Map>
name String
networkId String
projectId Number
projectName String
regionId Number
regionName String
subnetId String
The ID of this resource.

Supporting Types

SubnetHostRoute
, SubnetHostRouteArgs

Destination This property is required. string
Nexthop This property is required. string
IPv4 address to forward traffic to if it's destination IP matches 'destination' CIDR
Destination This property is required. string
Nexthop This property is required. string
IPv4 address to forward traffic to if it's destination IP matches 'destination' CIDR
destination This property is required. String
nexthop This property is required. String
IPv4 address to forward traffic to if it's destination IP matches 'destination' CIDR
destination This property is required. string
nexthop This property is required. string
IPv4 address to forward traffic to if it's destination IP matches 'destination' CIDR
destination This property is required. str
nexthop This property is required. str
IPv4 address to forward traffic to if it's destination IP matches 'destination' CIDR
destination This property is required. String
nexthop This property is required. String
IPv4 address to forward traffic to if it's destination IP matches 'destination' CIDR

SubnetMetadataReadOnly
, SubnetMetadataReadOnlyArgs

Key This property is required. string
ReadOnly This property is required. bool
Value This property is required. string
Key This property is required. string
ReadOnly This property is required. bool
Value This property is required. string
key This property is required. String
readOnly This property is required. Boolean
value This property is required. String
key This property is required. string
readOnly This property is required. boolean
value This property is required. string
key This property is required. str
read_only This property is required. bool
value This property is required. str
key This property is required. String
readOnly This property is required. Boolean
value This property is required. String

Import

import using <project_id>:<region_id>:<subnet_id> format

$ pulumi import gcorelabs:index/subnet:Subnet subnet1 1:6:447d2959-8ae0-4ca0-8d47-9f050a3637d7
Copy

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

Package Details

Repository
gcorelabs g-core/terraform-provider-gcorelabs
License
Notes
This Pulumi package is based on the gcorelabs Terraform Provider.