Skip to main content

dtcloud_elastic_ip (Resource)

Allocates a public (elastic) IP address and, optionally, points it at a port.

The three verbs map onto Terraform directly: create allocates the address, update associates and disassociates it, delete releases it. port_id is the association and the only argument that writes it; there is no separate association resource. The API and the SDK call this a floating IP.

Example Usage​

# Allocate a public address and leave it unattached.
resource "dtcloud_elastic_ip" "spare" {
floating_network_id = var.external_network_id
}

# Allocate and point it at a machine's port. Moving the address to another port
# is an in-place update: the address itself is never released.
resource "dtcloud_elastic_ip" "web" {
floating_network_id = var.external_network_id
port_id = dtcloud_vm_network_interface.web.port_id
}
note

Finding the external network. floating_network_id is the external network, not the network your machine is on: it is the network your router's gateway is on. dtcloud_router reports it as external_network_id -- on the resource when you manage the router, through the data source when you do not -- and dtctl router externals prints the same thing.

Schema​

Required​

  • floating_network_id (String) ID of the external network to allocate the address from: the one your router's gateway is on, which dtcloud_router reports as external_network_id. Changing this forces a new resource to be created.

Optional​

  • fixed_ip_address (String) Which address on the port to map to, for a port that has several. The platform picks one when omitted.
  • port_id (String) ID of the port to point the address at. Remove it to disassociate. A VM's ports are on its network_interface blocks: dtcloud_vm.web.network_interface[0].port_id.
  • subnet_id (String) ID of a specific subnet of the external network to take the address from. Only used when allocating, and never reported back — see the note on import. Changing this forces a new resource to be created.
  • timeouts (Block, Optional) (see below for nested schema)

Read-Only​

  • created_at (String) When the address was allocated, in RFC 3339 format.
  • description (String) Description of the address. Read-only: neither the create nor the update route accepts one, so this is only ever set for an address created outside Terraform.
  • device_id (String) ID of the resource behind the port — the virtual machine or load balancer this address currently reaches. Empty when the address is not associated.
  • device_owner (String) What kind of thing is behind the port, as the platform labels it, e.g. compute:nova for a VM. Empty when the address is not associated.
  • id (String) The ID of this resource.
  • ip_address (String) The public address that was allocated. This is the value to hand out.
  • router_id (String) ID of the router carrying the traffic, filled in once the address is associated.
  • status (String) ACTIVE when the address is associated, DOWN when it is not. DOWN is a resting state, not a fault.
  • updated_at (String) When the address was last changed, in RFC 3339 format.

Nested Schema for timeouts​

Optional:

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

Behaviour worth knowing​

  • Moving the address is an update, not a replacement. Changing port_id points the same address somewhere else, so an address that is already in DNS or in a firewall rule is never given up. Only floating_network_id and subnet_id force a new address.
  • Disassociation is all-or-nothing. The update endpoint has no partial mode: a request that names no port detaches the address. That is also why the association lives on this resource: two resources writing the same field through the same call would undo each other.
  • DOWN is a resting state. An allocated address with nothing attached reports DOWN. It still occupies quota and is still billed; dtcloud_elastic_ips with status = "DOWN" finds these.
  • fixed_ip_address needs port_id. Setting it without a port is refused at plan time. Left out, it is never sent and the platform picks an address on the port, which is what lets the address move to a port that does not have the previous address.
  • A port with several IPv4 addresses needs fixed_ip_address. The platform will not choose one for you, and what addresses a port has is only known when the call is made, so this fails at apply rather than at plan.
  • Changing port_id refreshes what the address reaches. status, device_id, device_owner and router_id show as known after apply.

Timeouts​

create, update and delete each default to 10 minutes. Allocating and associating are asynchronous: the provider waits until the address reports the port it was asked for. Override them with a timeouts block:

resource "dtcloud_elastic_ip" "web" {
# ...

timeouts {
update = "20m"
}
}

Import​

terraform import dtcloud_elastic_ip.web 5c1e7b93-2fd4-4a08-9b6e-1c3a7d2f8e44

port_id, fixed_ip_address and the read-only attributes are read back. subnet_id is not: the API never reports it, so an imported address has it empty. An empty value is not treated as a change, so no new address is proposed, but write it into the configuration if it matters which subnet the address came from.