Terraform provider reference / guides / lifecycle

A project end to end

The same run as the API guide A server from start to finish, written as one configuration. Read it before you let a pipeline create and destroy servers on its own: the interesting part is not the creation, it is what stays behind after destroy.

The configuration

resource "fiberax_network" "backend" {
  name = "backend"
  cidr = "10.42.0.0/24"
}

resource "fiberax_server" "app" {
  name           = "app-01"
  server_type_id = 4
  image          = data.fiberax_images.os.images[0].id

  cores     = 2
  memory_mb = 4096
  disk_gb   = 40

  public_ipv4 = { reuse = true }
  ssh_keys    = [fiberax_ssh_key.laptop.id]
}

# The private card is its own resource: a server may have several, and each one
# is managed separately.
resource "fiberax_network_interface" "app_backend" {
  server_id  = fiberax_server.app.id
  network_id = fiberax_network.backend.id
}

resource "fiberax_server_firewall" "app" {
  server_id = fiberax_server.app.id
  enabled   = true

  policy_in  = "drop"   # anything not allowed below is dropped
  policy_out = "accept" # outbound traffic is not restricted

  # The rule set is ONE field, replaced as a whole, and the order in it is the
  # order the platform checks: the first matching rule wins.
  rules = [
    {
      direction        = "in"
      action           = "accept"
      protocol         = "tcp"
      destination_port = "22"
      description      = "ssh"
    },
    {
      direction        = "in"
      action           = "accept"
      protocol         = "tcp"
      destination_port = "80,443"
      description      = "web"
    },
  ]
}

resource "fiberax_server_backup_policy" "app" {
  server_id = fiberax_server.app.id
  enabled   = true
  days      = ["mon", "wed", "fri"]
  hour      = 2
  minute    = 0

  # `keep` is read-only here: how many backups are kept comes from the product,
  # and writing it is refused as an unknown field.
}

What the order looks like

Terraform works out the order from the references, and there is nothing to arrange by hand: the card waits for both the network and the server, the firewall and the policy wait for the server. A private network takes about a minute to appear on the platform, and the provider waits for it, so the first apply of a new network is the slowest step of the run.

What destroy does not remove

This is the part worth reading twice.

Reading the plan

Two habits save time:

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