All checks were successful
nixos / nixos (push) Successful in 34s
The infrastructure is applied with OpenTofu; name it so. terraform/
becomes tofu/, the files end in .tofu (OpenTofu 1.8+ prefers them), the
local variables file is secrets.auto.tfvars, and both servers carry
managed_by=opentofu (an in-place label change).
The state moved to new buckets asxpio-tofu-main/-repl, key
tofu/state/tofu.tfstate, with `tofu init -migrate-state`; a plan against
it shows no changes. The old asxpio-terraform-* buckets stay, renamed
in the config with moved blocks, until the new state has been used for
a while.
asxpio-loki-main, created by hand, is adopted with an import block, and
a new asxpio-loki-repl in fsn1 receives it in the daily replica, which
now also copies the new state bucket instead of the old one.
What keeps the Terraform name is OpenTofu's own: the `terraform {}`
block and .terraform.lock.hcl.
Assisted-by: Claude:opus-5-5
116 lines
3.2 KiB
HCL
116 lines
3.2 KiB
HCL
# Debian on first boot installs NixOS over itself (cloud-init runs
|
|
# nixos-infect); the system itself is described in ../nixos.
|
|
locals {
|
|
user_data = {
|
|
for host in ["asxpio-ops", "asxpio-services"] : host => templatefile(
|
|
"${path.module}/cloud-init/nixos.yaml.tftpl", {
|
|
hostname = host
|
|
domain = "asxp.io"
|
|
# Pinned: this script replaces the operating system
|
|
infect_rev = "40f62a680bb0e8f2f607d79abfaaecd99d59401c"
|
|
infect_sha256 = "4354bd68773b41da65c0e815202c43c8549713b3ed3ff6381c71fbc0b0a840ab"
|
|
nix_channel = "nixos-26.05"
|
|
|
|
private_net = split("/", hcloud_network.main.ip_range)[0]
|
|
private_prefix = split("/", hcloud_network.main.ip_range)[1]
|
|
private_gateway = cidrhost(hcloud_network.main.ip_range, 1)
|
|
}
|
|
)
|
|
}
|
|
}
|
|
|
|
# Ops Server (2 vCPU, 4GB RAM)
|
|
resource "hcloud_server" "ops" {
|
|
name = "asxpio-ops"
|
|
image = "debian-13"
|
|
location = "hel1"
|
|
server_type = "cx23"
|
|
|
|
ssh_keys = [
|
|
hcloud_ssh_key.asxpi.id,
|
|
hcloud_ssh_key.deploy.id
|
|
]
|
|
|
|
# Off: restic backs up both hosts to object storage (ansible role
|
|
# restic_backup) for less than the 20% of the server price this costs
|
|
backups = false
|
|
delete_protection = true
|
|
rebuild_protection = true
|
|
|
|
public_net {
|
|
ipv4_enabled = true
|
|
ipv6_enabled = true
|
|
}
|
|
|
|
network {
|
|
network_id = hcloud_network.main.id
|
|
ip = "10.10.0.10"
|
|
}
|
|
|
|
firewall_ids = [hcloud_firewall.ops_fw.id]
|
|
|
|
labels = {
|
|
role = "ops"
|
|
env = "production"
|
|
managed_by = "opentofu"
|
|
project = "asxpio"
|
|
}
|
|
|
|
# First boot converts the Debian image to NixOS (see local.user_data).
|
|
# hcloud replaces the server when user_data, image or ssh_keys change.
|
|
# Never let an edit to those destroy a running machine: they apply to
|
|
# a new server or to a rebuild in place (../nixos/README.md) only.
|
|
user_data = local.user_data["asxpio-ops"]
|
|
lifecycle {
|
|
ignore_changes = [user_data, image, ssh_keys]
|
|
prevent_destroy = true
|
|
}
|
|
}
|
|
|
|
# Services Server - CX43 (8 vCPU, 16GB RAM)
|
|
resource "hcloud_server" "services" {
|
|
name = "asxpio-services"
|
|
image = "debian-13"
|
|
location = "hel1"
|
|
server_type = "cx43"
|
|
|
|
ssh_keys = [
|
|
hcloud_ssh_key.asxpi.id,
|
|
hcloud_ssh_key.deploy.id
|
|
]
|
|
|
|
# Off: restic backs up both hosts to object storage (ansible role
|
|
# restic_backup) for less than the 20% of the server price this costs
|
|
backups = false
|
|
delete_protection = true
|
|
rebuild_protection = true
|
|
|
|
public_net {
|
|
ipv4_enabled = true
|
|
ipv6_enabled = true
|
|
}
|
|
|
|
network {
|
|
network_id = hcloud_network.main.id
|
|
ip = "10.10.0.20"
|
|
}
|
|
|
|
firewall_ids = [hcloud_firewall.services_fw.id]
|
|
|
|
labels = {
|
|
role = "services"
|
|
env = "production"
|
|
managed_by = "opentofu"
|
|
project = "asxpio"
|
|
}
|
|
|
|
# First boot converts the Debian image to NixOS (see local.user_data).
|
|
# hcloud replaces the server when user_data, image or ssh_keys change.
|
|
# Never let an edit to those destroy a running machine: they apply to
|
|
# a new server or to a rebuild in place (../nixos/README.md) only.
|
|
user_data = local.user_data["asxpio-services"]
|
|
lifecycle {
|
|
ignore_changes = [user_data, image, ssh_keys]
|
|
prevent_destroy = true
|
|
}
|
|
}
|