summaryrefslogtreecommitdiffstats
path: root/nixos/tests/vault-agent.nix
blob: 4c9f98a3df7efe041ef3cd6d582b17a9d7cb56fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
{ pkgs, ... }:
{
  name = "vault-agent";

  nodes.machine =
    { config, pkgs, ... }:
    {
      services.vault-agent.instances.example.settings = {
        vault.address = config.environment.variables.VAULT_ADDR;

        auto_auth = [
          {
            method = [
              {
                type = "token_file";
                config.token_file_path = pkgs.writeText "vault-token" config.environment.variables.VAULT_TOKEN;
              }
            ];
          }
        ];

        template = [
          {
            contents = ''
              {{- with secret "secret/example" }}
              {{ .Data.data.key }}"
              {{- end }}
            '';
            perms = "0600";
            destination = "/example";
          }
        ];
      };

      services.vault = {
        enable = true;
        dev = true;
        devRootTokenID = config.environment.variables.VAULT_TOKEN;
      };

      environment = {
        systemPackages = [ pkgs.vault ];
        variables = {
          VAULT_ADDR = "http://localhost:8200";
          VAULT_TOKEN = "root";
        };
      };
    };

  testScript = ''
    machine.wait_for_unit("vault.service")
    machine.wait_for_open_port(8200)

    machine.wait_until_succeeds('vault kv put secret/example key=example')

    machine.wait_for_unit("vault-agent-example.service")

    machine.wait_for_file("/example")
    machine.succeed('grep "example" /example')
  '';
}