resource "hcloud_ssh_key" "cc_ci" {
  name       = "cc-ci-deploy"
  public_key = var.ssh_public_key

  labels = {
    project = "cc-ci"
    managed = "terraform"
  }
}

resource "hcloud_server" "cc_ci" {
  name        = var.server_name
  server_type = var.server_type
  image       = var.image
  location    = var.location
  ssh_keys    = [hcloud_ssh_key.cc_ci.id]

  # Stage 1: cloud-init runs nixos-infect on first boot, converting Ubuntu to NixOS,
  # then reboots. See user-data.sh for the pinned infect revision.
  user_data = file("${path.module}/user-data.sh")

  public_net {
    ipv4_enabled = true
    ipv6_enabled = false
  }

  labels = {
    project = "cc-ci"
    managed = "terraform"
    stage   = "infect"
  }
}
