2023-05-10 21:05:10 +02:00
|
|
|
# Record the SSH public key into Hetzner Cloud
|
|
|
|
resource "hcloud_ssh_key" "hcloud" {
|
|
|
|
for_each = var.admin_ssh_keys
|
2023-05-11 00:29:15 +02:00
|
|
|
name = "${var.domain}-${each.key}"
|
2023-05-10 21:05:10 +02:00
|
|
|
public_key = each.value
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "hcloud_server" "nixos_wiki" {
|
|
|
|
image = "debian-10"
|
|
|
|
keep_disk = true
|
|
|
|
name = "nixos-wiki"
|
|
|
|
server_type = var.server_type
|
2023-05-11 00:29:15 +02:00
|
|
|
ssh_keys = [for k in hcloud_ssh_key.hcloud : k.id]
|
2023-05-10 21:05:10 +02:00
|
|
|
backups = false
|
|
|
|
labels = var.tags
|
|
|
|
|
2023-05-11 00:29:15 +02:00
|
|
|
location = var.server_location
|
2023-05-10 21:05:10 +02:00
|
|
|
|
|
|
|
lifecycle {
|
|
|
|
# Don't destroy server instance if ssh keys changes.
|
|
|
|
ignore_changes = [ssh_keys]
|
|
|
|
prevent_destroy = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module "deploy" {
|
2023-05-11 00:29:15 +02:00
|
|
|
depends_on = [local_file.nixos_vars]
|
2023-05-10 21:05:10 +02:00
|
|
|
source = "github.com/numtide/nixos-anywhere//terraform/all-in-one"
|
|
|
|
nixos_system_attr = ".#nixosConfigurations.${var.nixos_flake_attr}.config.system.build.toplevel"
|
|
|
|
nixos_partitioner_attr = ".#nixosConfigurations.${var.nixos_flake_attr}.config.system.build.diskoNoDeps"
|
2023-05-11 00:29:15 +02:00
|
|
|
target_host = hcloud_server.nixos_wiki.ipv4_address
|
|
|
|
instance_id = hcloud_server.nixos_wiki.id
|
2023-05-10 21:05:10 +02:00
|
|
|
debug_logging = true
|
|
|
|
}
|
|
|
|
|
|
|
|
locals {
|
|
|
|
nixos_vars = {
|
|
|
|
ipv6_address = hcloud_server.nixos_wiki.ipv6_address
|
|
|
|
}
|
|
|
|
}
|