Skip to main content

dtcloud_vm_network_interface (Resource)

Attaches an extra network interface to a virtual machine.

Interfaces declared in a dtcloud_vm network block are created with the machine and live and die with it. Use this resource for interfaces added afterwards: they get their own port, and can be detached without rebuilding the machine. The resource ID is <vm-id>:<port-id>.

Example Usage​

# An interface added after the machine was built. It has its own lifecycle and
# can be detached without recreating the VM.
resource "dtcloud_vm_network_interface" "storage" {
vm_id = dtcloud_vm.web.id
network_id = dtcloud_network.storage.id
security_groups = [dtcloud_security_group.internal.id]
}

output "storage_address" {
value = dtcloud_vm_network_interface.storage.primary_ip
}

# Pin the address instead of letting the platform choose one.
resource "dtcloud_vm_network_interface" "pinned" {
vm_id = dtcloud_vm.web.id
network_id = dtcloud_network.storage.id

fixed_ip {
ip_address = "10.30.0.50"
}
}
note

Same arguments as the network block on dtcloud_vm. Both describe a port on a network, so a block that works inline works here unchanged, except that the network is named uuid there and network_id here. Use the inline block for interfaces the machine boots with, and this resource for the ones added afterwards.

Schema​

Required​

  • network_id (String) ID of the network to attach to. Changing this forces a new resource to be created.
  • vm_id (String) ID of the virtual machine to attach the interface to. Changing this forces a new resource to be created.

Optional​

  • fixed_ip (Block List) Fixed IPs on this interface. Omit to have one address allocated. Can be changed in place. (see below for nested schema)
  • port_security_enabled (Boolean) Whether port security (and therefore security groups) applies to this interface. Defaults to the network's own setting. Changing this forces a new resource to be created.
  • security_groups (List of String) Security group IDs bound to this interface. Can be changed in place. Defaults to the project's default group.
  • timeouts (Block, Optional) (see below for nested schema)

Read-Only​

  • id (String) The ID of this resource.
  • is_public (Boolean) Whether the interface is on a public network.
  • mac_address (String) MAC address the platform assigned to this interface.
  • network_name (String) Name of the network.
  • port_id (String) ID of the port the platform created for this interface.
  • primary_ip (String) Primary IP address on this interface.

Nested Schema for fixed_ip​

Optional:

  • ip_address (String) Specific address to request. Allocated by the platform when omitted, and reported back here either way.
  • ip_version (Number) IP version, 4 or 6. Advisory on write — the platform allocates from the attached network; pin ip_address to choose an address. Reported back from the assigned address.

Nested Schema for timeouts​

Optional:

  • create (String)
  • delete (String)
  • update (String)

Behaviour worth knowing​

warning

An interface never ends up without an address. To the platform an empty address list means "no address", not "allocate one", so when fixed_ip is left out the provider requests one address instead of sending an empty list.

  • port_security_enabled left unset is not sent at all, so the network's own setting applies. The setting the platform settles on is reported back.
  • Changing fixed_ip moves primary_ip. The plan shows primary_ip as known after apply.
  • How the port id is found. The attach endpoint does not report which port it created, so the provider lists the machine's interfaces before and after the call and takes the new one. If something else attaches an interface to the same machine at the same moment, the wrong port could be picked up. This only matters when one machine gets interfaces from two places concurrently.
  • dtcloud_vm.network_interface is a snapshot from that resource's last refresh. An interface attached here in the same apply appears there only after the next refresh.

Timeouts​

create, update and delete each default to 10 minutes. Override them with a timeouts block:

resource "dtcloud_vm_network_interface" "storage" {
# ...

timeouts {
create = "30m"
}
}

Import​

# The port id is assigned by the platform at attach time:
# <vm-id>:<port-id>
terraform import dtcloud_vm_network_interface.storage 4c9a1f37-8d25-4e60-b13f-6a7c2e5b9d88:0b3e6a92-7c14-4d58-9f26-8e1a5c7b3f99

The addresses, security groups and port security setting are read back from the platform after import, so nothing needs to be declared by hand to match the interface.