clan-infra/terraform/web01/main.tf

40 lines
1.2 KiB
Terraform
Raw Normal View History

2023-07-04 14:43:31 +00:00
# Record the SSH public key into Hetzner Cloud
2023-07-04 15:23:29 +00:00
data "hcloud_ssh_keys" "server" {
with_selector = "web01=true"
2023-07-04 14:43:31 +00:00
}
2023-07-04 15:23:29 +00:00
resource "hcloud_server" "server" {
2023-07-04 14:43:31 +00:00
image = "debian-10"
keep_disk = true
2023-07-04 15:23:29 +00:00
name = "web01"
2023-07-04 14:43:31 +00:00
server_type = var.server_type
2023-07-04 15:23:29 +00:00
ssh_keys = data.hcloud_ssh_keys.server.ssh_keys.*.name
2023-07-04 14:43:31 +00:00
backups = false
labels = var.tags
location = var.server_location
lifecycle {
# Don't destroy server instance if ssh keys changes.
ignore_changes = [ssh_keys]
prevent_destroy = false
}
}
module "deploy" {
depends_on = [local_file.nixos_vars]
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-07-04 15:23:29 +00:00
target_host = hcloud_server.server.ipv4_address
instance_id = hcloud_server.server.id
2023-07-04 14:43:31 +00:00
debug_logging = true
}
locals {
nixos_vars = {
2023-07-04 15:23:29 +00:00
ipv6_address = hcloud_server.server.ipv6_address
ssh_keys = data.hcloud_ssh_keys.server.ssh_keys.*.public_key
2023-07-04 14:43:31 +00:00
}
}