From 58f2ff985884b8d48d98a1706e4f5117ac6ca7db Mon Sep 17 00:00:00 2001 From: Raito Bezarius Date: Sun, 27 Oct 2024 21:32:28 +0100 Subject: [PATCH] chore: connect terraform to the hive This way, we can autogenerate records for storage and builders nodes by reading directly the configuration. This makes evaluation of `nix run .#tf` slower, but this makes things more safer and easier, so it's good. Signed-off-by: Raito Bezarius --- flake.nix | 5 ++++- terraform/dnsimple.nix | 11 ++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/flake.nix b/flake.nix index f43f411..4feaf28 100644 --- a/flake.nix +++ b/flake.nix @@ -64,6 +64,9 @@ terraform = pkgs.opentofu; terraformCfg = terranix.lib.terranixConfiguration { inherit system; + extraArgs = { + inherit (self) nixosConfigurations; + }; modules = [ ./terraform { @@ -174,7 +177,7 @@ # Filter all nodes by the range data for this flavor. filteredNodes = lib.filterAttrs (name: node: lib.any (r: inRange node.bagel.baremetal.num r) ranges) nodes; # The enumeration from baremetal numbers to flavor-specific numbers. - indexes = lib.traceValSeq (reverseEnumerate (map (n: toString n.bagel.baremetal.num) (builtins.attrValues filteredNodes))); + indexes = reverseEnumerate (map (n: toString n.bagel.baremetal.num) (builtins.attrValues filteredNodes)); in # Build a new attrset with a new second-level index for the specific flavor. lib.mapAttrs (name: node: setFlavor indexes.${toString node.bagel.baremetal.num} node) filteredNodes; diff --git a/terraform/dnsimple.nix b/terraform/dnsimple.nix index 56b2d09..515a2f4 100644 --- a/terraform/dnsimple.nix +++ b/terraform/dnsimple.nix @@ -1,7 +1,10 @@ -{ lib, config, ... }: +{ nixosConfigurations, lib, config, ... }: let - inherit (lib) mkEnableOption mkIf tf genList; + inherit (lib) mkEnableOption mkIf tf genList filterAttrs; cfg = config.bagel.dnsimple; + filterBaremetalNodes = submodule: nodes: filterAttrs (name: node: node.config.bagel.baremetal.enable && node.config.bagel.baremetal.${submodule}.enable) nodes; + builderNodes = builtins.attrValues (filterBaremetalNodes "builders" nixosConfigurations); + storageNodes = builtins.attrValues (filterBaremetalNodes "storage" nixosConfigurations); in { options.bagel.dnsimple = { @@ -125,7 +128,9 @@ in (dualProxyRecords "build-coord.wob01.infra" 300 "AAAA" "2a01:584:11::1:11") # TODO: do not hardcode, just reuse the Colmena hive module outputs to generate all the required details. ] - ++ (map (index: record "builder-${toString index}.wob01.infra" 300 "AAAA" "2a01:584:11::1:${toString index}") (genList lib.id 11)) + ++ (map (index: record "bm-${toString index}.wob01.infra" 300 "AAAA" "2a01:584:11::1:${toString index}") (genList lib.id 11)) + ++ (map (node: record "builder-${toString node.config.bagel.baremetal.builders.num}.wob01.infra" 300 "CNAME" "bm-${toString node.config.bagel.baremetal.num}") builderNodes) + ++ (map (node: record "storage-${toString node.config.bagel.baremetal.storage.num}.wob01.infra" 300 "CNAME" "bm-${toString node.config.bagel.baremetal.num}") storageNodes) ++ ( let # FIXME: figure out a way to poke `config.services.s3-revproxy` and