diff --git a/terraform/modules/wiki/dns.tf b/terraform/modules/wiki/dns.tf index 0da6e4c..c9d7112 100644 --- a/terraform/modules/wiki/dns.tf +++ b/terraform/modules/wiki/dns.tf @@ -4,14 +4,14 @@ resource "netlify_dns_zone" "nixos" { } resource "netlify_dns_record" "nixos_wiki_a" { - zone_id = var.zone_id + zone_id = netlify_dns_zone.nixos.id hostname = var.domain type = "A" value = hcloud_server.nixos_wiki.ipv4_address } resource "netlify_dns_record" "nixos_wiki_aaaa" { - zone_id = var.zone_id + zone_id = netlify_dns_zone.nixos.id hostname = var.domain type = "AAAA" value = hcloud_server.nixos_wiki.ipv6_address diff --git a/terraform/modules/wiki/main.tf b/terraform/modules/wiki/main.tf index 4930960..de940fb 100644 --- a/terraform/modules/wiki/main.tf +++ b/terraform/modules/wiki/main.tf @@ -1,7 +1,7 @@ # Record the SSH public key into Hetzner Cloud resource "hcloud_ssh_key" "hcloud" { for_each = var.admin_ssh_keys - name = each.key + name = "${var.domain}-${each.key}" public_key = each.value } @@ -10,11 +10,11 @@ resource "hcloud_server" "nixos_wiki" { keep_disk = true name = "nixos-wiki" server_type = var.server_type - ssh_keys = data.hcloud_ssh_key.hcloud[*].id + ssh_keys = [for k in hcloud_ssh_key.hcloud : k.id] backups = false labels = var.tags - location = var.server_location + location = var.server_location lifecycle { # Don't destroy server instance if ssh keys changes. @@ -24,12 +24,12 @@ resource "hcloud_server" "nixos_wiki" { } module "deploy" { - depends_on = [ local_file.nixos_vars ] + 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" - target_host = hcloud_server.nixos-wiki.ipv4_address - instance_id = hcloud_server.nixos-wiki.id + target_host = hcloud_server.nixos_wiki.ipv4_address + instance_id = hcloud_server.nixos_wiki.id debug_logging = true } diff --git a/terraform/modules/wiki/variables.tf b/terraform/modules/wiki/variables.tf index b154c93..fda1fbf 100644 --- a/terraform/modules/wiki/variables.tf +++ b/terraform/modules/wiki/variables.tf @@ -29,3 +29,14 @@ variable "nixos_flake_attr" { type = string description = "NixOS configuration flake attribute" } + +variable "domain" { + type = string + description = "Domain name" +} + +variable "tags" { + type = map(string) + default = {} + description = "Tags to add to the server" +} diff --git a/terraform/targets/nixos-wiki.thalheim.io/terraform.tf b/terraform/targets/nixos-wiki.thalheim.io/terraform.tf index c572770..aad3441 100644 --- a/terraform/targets/nixos-wiki.thalheim.io/terraform.tf +++ b/terraform/targets/nixos-wiki.thalheim.io/terraform.tf @@ -15,6 +15,11 @@ module "wiki" { mic92 = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKbBp2dH2X3dcU1zh+xW3ZsdYROKpJd3n13ssOP092qE joerg@turingmachine" } netlify_dns_zone = "wiki.thalheim.io" + domain = "wiki.thalheim.io" nixos_flake_attr = "nixos-wiki-production" - nixos_vars_file = "${path.module}/nixos-vars.json" + nixos_vars_file = "${path.module}/nixos-vars.json" + tags = { + Terraform = "true" + Target = "nixos-wiki.thalheim.io" + } } diff --git a/terraform/targets/staging.nixos-wiki.thalheim.io/terraform.tf b/terraform/targets/staging.nixos-wiki.thalheim.io/terraform.tf index 930a249..9773fc9 100644 --- a/terraform/targets/staging.nixos-wiki.thalheim.io/terraform.tf +++ b/terraform/targets/staging.nixos-wiki.thalheim.io/terraform.tf @@ -17,4 +17,8 @@ module "wiki" { netlify_dns_zone = "wiki.thalheim.io" nixos_flake_attr = "nixos-wiki-staging" nixos_vars_file = "${path.module}/nixos-vars.json" + tags = { + Terraform = "true" + Target = "nixos-wiki.thalheim.io" + } }