Fediversity/deployment/check/data-model-tf/nixosTest.nix
Kiara Grouwstra 1e69b2effd
factor out TF http back-end settings
Signed-off-by: Kiara Grouwstra <kiara@procolix.eu>
2025-10-30 18:37:17 +01:00

71 lines
1.8 KiB
Nix

{
lib,
pkgs,
sources,
modulesPath,
...
}:
let
inherit (pkgs) system;
inherit (import ./constants.nix) pathToRoot;
nodeName = "target";
backendPort = builtins.toString 8080;
deploy =
(import ./data-model.nix {
inherit system modulesPath;
config = {
inherit nodeName pathToRoot;
targetSystem = system;
sshOpts = [ ];
httpBackend.address = "http://localhost:${backendPort}/state/project1/example";
};
}).default.tf-host.run;
in
{
_class = "nixosTest";
name = "deployment-model";
nodes.deployer =
{ ... }:
{
imports = [
../../modules/terraform-backend
];
environment.systemPackages = [
deploy
(pkgs.callPackage ../../run/tf-single-host/tf.nix { inherit sources; })
];
# needed only when building from deployer
system.extraDependenciesFromModule =
{ pkgs, ... }:
{
environment.systemPackages = with pkgs; [
hello
];
};
services.terraform-backend = {
enable = true;
settings = {
LISTEN_ADDR = ":${backendPort}";
KMS_KEY = "l99yC7MhbuuraACQ8bjaU1rMrT6L4PXEYupX6BzhJvY=";
};
};
};
extraTestScript = ''
with subtest("Check the status before deployment"):
target.fail("hello 1>&2")
with subtest("Run the deployment"):
deployer.wait_for_unit("multi-user.target")
deployer.succeed("curl -u basic:fake-secret -X GET http://localhost:8080/state/project1/example")
output = deployer.fail("""
${lib.getExe deploy} 2>&1
""")
assert "Timeout, server ${nodeName} not responding" in output
target.wait_for_unit("multi-user.target")
target.succeed("su - operator -c hello 1>&2")
'';
}