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:
new = true- the address was born with the server and goes with it: destroying (or replacing) the server releases it to the platform's shared pool, and it is not billed any more. A released address cannot be taken back - another customer may receive it. The platform releases EVERY public address attached to the server at that moment, including one attached outside this configuration. A replacement releases the address before the new server is created, and the new server takes a free address from the shared pool, which may or may not be the same one - do not rely on keeping it. The plan warns about this when a change in the configuration replaces the server;-replaceandtaintreplace it without that warning: the provider cannot tell these replacements apart when it plans them.id- the address is its own resource. Destroying the server only detaches it; on replacement it moves to the new server in the same run, anddestroyreleases it through its ownfiberax_ipresource.reuse = true- the address belongs to the project's pool of free addresses. Destroying the server detaches it and leaves it with the project, still billed, so the next server withreuse = truecan take it again. This holds even whenreusefound no free address and had to allocate a new one.reusetakes the free address with the lowest id in the pools of the new server's type - usually the old one; when another free address has a lower id, or the new type draws from other pools, the server gets that one, and the old address stays with the project, billed.- No
public_ipv4block (an imported server included) - the addresses stay with the project, still billed: the provider does not destroy addresses this configuration did not order.
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:
- On a server Terraform created - without the block, or with one that was removed later - adding the block is a change of form: the server is replaced and its disks are erased.
- On a server taken over with
terraform import, a block written before the first successful apply whose plan shows a change for that server is only recorded in state - nothing happens on the platform (see Importing what you already have). That apply ends the allowance even when its change only records values in state; an apply with no change for the server (a refresh, changes to other resources) does not. From then on the server behaves like a created one, and the plan does not warn you: the replacement shows only as the usual "forces replacement".
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:
-
Remove the
public_ipv4block 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. -
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 ondestroydeletes the server first and then releases the address through that resource, and destroying the server alone leaves the address with the project. Do not skipdepends_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 with409 ip_in_use- Terraform reports it as "The address is held by a server", containingfiberax API: ip_in_use (IP address is attached to a server). The server is gone by then, so a second plaindestroystops on "The server has no network" - runterraform destroy -refresh=falseinstead, as the next paragraph says.When the server is gone and the description stays. After
terraform destroy -target=fiberax_server.web, a firstdestroystopped byip_in_use, or a server deleted outside Terraform, this configuration describes a server that is no longer in state and has no network. A plainterraform destroyplans the configuration first, plans that server as new and stops on "The server has no network". Runterraform destroy -refresh=false(tofu destroy -refresh=falsein OpenTofu): it destroys what state holds and releases the address. Or remove the server from the configuration and runterraform destroyagain. Do not addpublic_ipv4ornetworksto get past the error: an apply of that configuration creates a new billed server.depends_onties the server to the address in the other direction too.terraform destroy -target=fiberax_ip.webdestroys everything that depends on the target, so it deletes the server as well - with its disks. A server that names the address withpublic_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:
-
Remove whatever ties the server to the address in the configuration -
depends_on = [fiberax_ip.web]orpublic_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 thenterraform destroy -target=fiberax_ip.webstill deletes the server as well. -
Take the address off
net0:PATCH /v1/servers/{id}/network-interfaces/net0with{"ips": []}- the card stays in the public network with no address - or with{"network_id": N}to move the card into private networkN; 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'sipsas changed outside Terraform; that needs nothing from you. -
Remove the
fiberax_ip.webresource from the configuration and apply: that releases the address.terraform destroy -target=fiberax_ip.webreleases 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 with409 ip_in_use, and until it succeeds the address stays with the project, billed.If the configuration has no
fiberax_ipfor this address - a server withnew = true, the usual case - release it withDELETE /v1/ips/{id}once step 2 has finished, or import it as afiberax_ipand then remove that resource. Afiberax_ipwritten withoutterraform importtakes a NEW billed address instead. Thenew = trueblock 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.