terraform-config/config.nix

65 lines
1.3 KiB
Nix
Raw Normal View History

2024-01-13 15:31:46 +00:00
{ config, lib, pkgs, options, specialArgs, ... }:
let
var = options.variable;
2024-01-15 21:07:10 +00:00
my-lib = import ./lib/default.nix { inherit lib; };
2024-01-15 22:42:41 +00:00
mapKeys = f: lib.mapAttrs' (k: v: lib.nameValuePair (f k) v);
inNamespace = prefix: mapKeys (k: "${prefix}_${k}");
2024-01-15 21:07:10 +00:00
setNames = lib.mapAttrs (k: v: v // { name = k; });
2024-01-13 15:31:46 +00:00
in rec {
2024-01-13 16:16:49 +00:00
provider = {
# Configure the Hetzner Cloud Provider
2024-01-14 07:43:47 +00:00
hcloud.token = lib.mkForce (lib.tfRef "var.hcloud_api_token");
2024-01-13 16:16:49 +00:00
};
2024-01-15 22:42:41 +00:00
resource = (inNamespace "hcloud" {
2024-01-13 15:31:46 +00:00
2024-01-15 21:07:10 +00:00
2024-01-15 22:42:41 +00:00
ssh_key = setNames (lib.mapAttrs (_: v: { public_key = v; }) my-lib.ssh-keys);
});
2024-01-13 16:16:49 +00:00
# Set the variable value in *.tfvars file
2024-01-14 07:43:47 +00:00
# or using -var="hcloud_api_token=..." CLI option
2024-01-13 16:16:49 +00:00
variable = {
2024-01-14 07:43:47 +00:00
hcloud_api_token = {
2024-01-13 16:16:49 +00:00
type = "string";
description = "Hetzner Cloud API Token";
sensitive = true;
};
};
2024-01-14 07:43:47 +00:00
# https://github.com/terranix/terranix-hcloud/blob/main/options.md
hcloud = {
enable = true;
# can also be specified with the TF_VAR_hcloud_api_token environment variable
provider.token = builtins.getEnv "TF_VAR_hcloud_api_token";
export.nix = "hetzner.nix";
};
2024-01-13 16:16:49 +00:00
data = {
hcloud_ssh_keys."all_keys" = {};
};
output = {
"keys_output" = {
value = lib.tfRef "data.hcloud_ssh_keys.all_keys";
2024-01-13 15:31:46 +00:00
};
};
}