dtcloud_network (Resource)
Manages a network and, when IPAM is enabled, the subnet inside it.
One resource covers both because the API does not manage them apart: a single call creates the network and its subnet, and the details endpoint reports them together.
Example Usage
# A network with IPAM on: the provider also manages the subnet inside it.
resource "dtcloud_network" "app" {
name = "app-net"
ipam_enabled = true
cidr = "10.20.0.0/24"
gateway_ip = "10.20.0.1"
enable_dhcp = true
dns_nameservers = ["8.8.8.8", "8.8.4.4"]
}
# With IPAM off there is no subnet, and addresses are managed outside Terraform.
resource "dtcloud_network" "flat" {
name = "flat-net"
ipam_enabled = false
}
Schema
Required
name(String) Name of the network. Can be changed in place.
Optional
allocation_pools(Block List) Address ranges the subnet allocates from. The platform picks a sensible default when omitted. (see below for nested schema)cidr(String) IPv4 range for the subnet, e.g. 10.0.0.0/24. Required when ipam_enabled is true, and rejected when it is false. Changing this forces a new resource to be created.dns_nameservers(List of String) DNS servers advertised to instances on this network.enable_dhcp(Boolean) Whether the subnet hands out addresses over DHCP.gateway_ip(String) Gateway address. The platform picks the first usable address when omitted.ipam_enabled(Boolean) Whether the platform manages addressing on this network. With it on, a subnet is created fromcidrand port security is enabled. With it off there is no subnet at all: no CIDR, no gateway, no DHCP. Changing this forces a new resource to be created.timeouts(Block, Optional) (see below for nested schema)
Read-Only
id(String) The ID of this resource.ip_version(Number) IP version of the subnet. The API creates IPv4 only.network_type(String) Virtual or Physical, as reported by the platform.subnet_id(String) ID of the subnet, empty when ipam_enabled is false.
Nested Schema for allocation_pools
Required:
end(String) Last address in the range.start(String) First address in the range.
Nested Schema for timeouts
Optional:
create(String)delete(String)update(String)
Behaviour worth knowing
ipam_enabled is one flag doing two jobs. It becomes the network's port security setting,
and it decides whether a subnet exists at all. With it off there is no subnet, so cidr,
gateway_ip, dns_nameservers, allocation_pools and enable_dhcp = false have nothing to apply
to, and setting any of them is refused at plan time.
- What changes in place.
name, and the subnet'sgateway_ip,enable_dhcp,dns_nameserversandallocation_pools.ipam_enabledandcidrforce a new network: neither the subnet's address range nor its existence can be changed afterwards. - Subnet edits send the complete set. The subnet endpoint requires
enable_dhcp,dns_nameserversandallocation_poolstogether, so changing one of them sends all four subnet settings,gateway_ipincluded. A change made outside Terraform to one of them is overwritten the next time any of them changes here. ip_versionis not an argument. The API creates IPv4 subnets whatever the request asks for, so the version is only reported back.- Creating and deleting are asynchronous. A network has no status to poll, so the provider waits until it reads back, or stops resolving.
Timeouts
create defaults to 15 minutes, update to 10 minutes and delete to 15 minutes. Override them
with a timeouts block:
resource "dtcloud_network" "app" {
# ...
timeouts {
create = "30m"
}
}
Import
terraform import dtcloud_network.app 3d2b9c88-4a71-4e5f-b0c2-9e8a1d7f4c33
Everything is read back, the subnet settings included, so a plan straight after an import is empty when the configuration matches the network.