Terraform provider reference / guides / addresses

Public addresses and what they cost

A public address is billed while the project holds it, whether or not anything uses it. That single sentence explains every rule below.

What destroying the server does with its address

It depends on how the server got the address:

The provider tells the platform which of these it wants on every destroy (release_ips of DELETE /v1/servers/{id}), so the platform's own default plays no part. Addresses that stay with the project are named in a warning when the server is destroyed, with two exceptions. An address named with id = ... (a fiberax_ip reference or a literal number) is not listed: you chose it; it stays with the project and is billed until released. And an address a fiberax_ip of the same configuration manages is not listed when the server depends on that resource through depends_on, as in the recipe below: destroying the resource releases it. When the server and the fiberax_ip are removed from the configuration at once, the warning may still name the address; the same run releases it all the same. With -refresh=false the provider relies on the last refresh: right after terraform state rm of the fiberax_ip, run a plan with refresh before destroying the server, or the warning may stay silent about an address that is still billed. A server that was already being deleted elsewhere (client area, support) when Terraform destroyed it follows that deletion's choice; the provider warns when it differs from what the configuration asked for.

Provider 0.6.0 and earlier lose every address of the server. They do not tell the platform anything on destroy, so the platform's default applies: deleting a server releases all its public addresses to the shared pool. With such a version, destroying or replacing a server releases its addresses whatever the form - one named by id included, which then leaves its fiberax_ip pointing at an address the project no longer holds - and a released address cannot be taken back. Upgrade to 0.7.0 or later (version = "~> 0.11.0" for the current version) before you destroy or replace a server whose address you want to keep.

Changing the form on an existing server replaces the server: a new server is created from the image and the disks of the old one are erased. The rules above apply to that replacement as to any destroy: the old server is deleted according to its OLD form. Removing the public_ipv4 block does not replace anything.

Imported or created - not the same. Writing the block where state has none means different things:

A server created with new = true whose address you now want to keep. Do not switch it to id or to reuse = true: that change replaces the server, and the replacement releases the address before the new server can take it - id would name an address that is gone, and reuse would take another one (the provider refuses both plans). Instead:

  1. Remove the public_ipv4 block from the server and apply. Nothing changes on the platform, and from then on destroying or replacing the server keeps its addresses with the project. That alone keeps the address - but it stays billed until you release it, and nothing in the configuration manages it: destroying the configuration leaves it behind.

  2. To manage the address in the configuration, import it and tie the server to it:

    resource "fiberax_ip" "web" {}
    
    resource "fiberax_server" "web" {
      # ... as before, with no public_ipv4 block
      depends_on = [fiberax_ip.web]
    }
    

    Run terraform import fiberax_ip.web <id> and apply: the plan is empty, the server is not touched. From then on destroy deletes the server first and then releases the address through that resource, and destroying the server alone leaves the address with the project. Do not skip depends_on: without it Terraform destroys the server and the address at the same time, the platform still holds the address on the server while it deletes the server, and releasing the address fails with 409 ip_in_use - Terraform reports it as "The address is held by a server", containing fiberax API: ip_in_use (IP address is attached to a server). The server is gone by then, so a second plain destroy stops on "The server has no network" - run terraform destroy -refresh=false instead, as the next paragraph says.

    When the server is gone and the description stays. After terraform destroy -target=fiberax_server.web, a first destroy stopped by ip_in_use, or a server deleted outside Terraform, this configuration describes a server that is no longer in state and has no network. A plain terraform destroy plans the configuration first, plans that server as new and stops on "The server has no network". Run terraform destroy -refresh=false (tofu destroy -refresh=false in OpenTofu): it destroys what state holds and releases the address. Or remove the server from the configuration and run terraform destroy again. Do not add public_ipv4 or networks to get past the error: an apply of that configuration creates a new billed server.

    depends_on ties the server to the address in the other direction too. terraform destroy -target=fiberax_ip.web destroys everything that depends on the target, so it deletes the server as well - with its disks. A server that names the address with public_ipv4 = { id = fiberax_ip.web.id } depends on it the same way. The order that releases only the address and keeps the server is in "Releasing only the address of a server" below.

Do not then write public_ipv4 = { id = fiberax_ip.web.id } on the same server to "finish" the move: on a server Terraform created that REPLACES the server and erases its disks. Write it only together with a change that replaces the server anyway (another image, say): the new server then gets the same address.

Keep an address across servers by managing it explicitly. Then destroy takes it with everything else:

# data.fiberax_images.os and fiberax_ssh_key.laptop are declared as in "A project end to end".
resource "fiberax_ip" "web" {}

resource "fiberax_server" "web" {
  name           = "web-01"
  server_type_id = 4
  image          = data.fiberax_images.os.images[0].id
  cores          = 2
  memory_mb      = 4096
  disk_gb        = 40
  ssh_keys       = [fiberax_ssh_key.laptop.id]

  public_ipv4 = { id = fiberax_ip.web.id }
}

Or reuse what the project already holds. reuse = true takes a free address of the project and only allocates a new one when there is none (and, unlike new = true, leaves it with the project when the server is destroyed):

  public_ipv4 = { reuse = true }

Use it when a recreate should not pile up addresses and any free address of the project will do; when it must be exactly the same address, name it with id (a fiberax_ip resource). new = true no longer piles up addresses across create-and-destroy cycles either, because it releases its address with the server.

Exactly one form

public_ipv4 takes exactly one of id, new or reuse. The provider refuses a block naming more than one at plan time, even when the extra field is false - a description should read as one unambiguous choice, not as a puzzle.

Omit the block entirely for a server with no public address at all. Such a server needs a private network instead: a machine with no network card is unreachable, and the platform refuses it.

Taking the card off does not release the address

Detaching a network card, or removing the card resource, leaves the address with the project. Releasing happens only when you destroy the address itself (fiberax_ip), delete it through the API, or destroy (or replace) a server that took it with new = true.

If you inherited a project with addresses nobody uses, they are the ones with no server attached - list them and destroy what you do not need.

Releasing only the address of a server

An address taken with public_ipv4 sits on net0, the network card the server was created with. No resource manages that card for taking addresses off it. fiberax_network_interface describes cards added afterwards. It accepts terraform import fiberax_network_interface.<name> <server>,net0, but such a resource cannot be destroyed - net0 cannot be removed (409 interface_not_removable) - so it leaves the configuration only through terraform state rm or a removed block, and it describes the same card as the server's own fields: do not use it for net0. Removing the public_ipv4 block changes state only - the address stays on the server. The platform does not release an address while it is on a server, so the step that detaches it is done outside Terraform:

  1. Remove whatever ties the server to the address in the configuration - depends_on = [fiberax_ip.web] or public_ipv4 = { id = fiberax_ip.web.id } - and apply. Nothing changes on the platform, and the server is not replaced. Do not skip the apply: Terraform keeps the dependency in state until an apply records its removal, and until then terraform destroy -target=fiberax_ip.web still deletes the server as well.

  2. Take the address off net0: PATCH /v1/servers/{id}/network-interfaces/net0 with {"ips": []} - the card stays in the public network with no address - or with {"network_id": N} to move the card into private network N; or untick the address on the server's network card in the client area. A running server restarts once (its network settings change; a stopped one is not started), and afterwards it has no public IPv4 address. To give it another address in the same step, send that address's id instead: {"ips": [<id>]}. Wait for the task the call returns (GET /v1/tasks/{id}) to finish. The next plan reports the server's ips as changed outside Terraform; that needs nothing from you.

  3. Remove the fiberax_ip.web resource from the configuration and apply: that releases the address. terraform destroy -target=fiberax_ip.web releases it too, but the resource is still in the configuration, and the next apply would take a new address - billed - for it; remove it there as well. Until step 2 is done the release fails with 409 ip_in_use, and until it succeeds the address stays with the project, billed.

    If the configuration has no fiberax_ip for this address - a server with new = true, the usual case - release it with DELETE /v1/ips/{id} once step 2 has finished, or import it as a fiberax_ip and then remove that resource. A fiberax_ip written without terraform import takes a NEW billed address instead. The new = true block itself may stay: destroying the server later releases only the addresses attached to it at that moment.

A refused create does not leave one behind

When a create is refused after the address was already reserved - no capacity, the chosen host has no room, the application's password or email, the machine could not be created - the new address that this request asked for is released again, so repeating such a create does not pile up addresses. An address you named yourself with id, or one reuse = true found free, stays yours, because it was yours before the request.

What can leave an address behind is a failure the platform cannot name - a bare 500 or a dropped connection: there it cannot tell whether the address is still needed and keeps it. Look at the project's addresses before repeating such a create by hand; the provider does not repeat writes on 5xx for this reason and because the server itself may already exist - see Retries, 409 and 503.

Generated from the provider schema for version 0.11.0. How to install the provider: Terraform provider.