Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exposing terraform info back to nixos configurations #413

Open
KiaraGrouwstra opened this issue Oct 23, 2024 · 1 comment
Open

exposing terraform info back to nixos configurations #413

KiaraGrouwstra opened this issue Oct 23, 2024 · 1 comment

Comments

@KiaraGrouwstra
Copy link
Contributor

KiaraGrouwstra commented Oct 23, 2024

in order to prevent duplication and hard-coding, it would be nice if we had a way to pass info from TF to the nixos configurations.

before nixos-anywhere i used teraflops, which exposed a static TF show -json dump thru a specialArgs parameter resources.
now, they can use such a static dump as they deploy the nix bits after terraform. as nixos-anywhere deploys nixos during terraform execution, here such info would instead need to be passed from within the terraform.

this could be facilitated in different ways, e.g. opinionated like teraflops (exposing such info in a given format), versus more generically by just passing thru more nix arguments, while leaving the details to the user.

there would also be considerations there between exposing info in a pure vs impure way:

  • passing info in a pure way, as files
    • pros:
      • may be preferred by nix
    • cons:
      • irrelevant changes in ephemeral TF info may show up in git (if not also triggering unnecessary rebuilds)
  • passing info in an impure way, as env vars
    • pros:
      • no fighting flakes about needing to stage files to git
    • cons:
      • if this is impure, i'm not sure if nix would still know whether it should rebuild if just the contents change
KiaraGrouwstra added a commit to KiaraGrouwstra/nixos-anywhere that referenced this issue Oct 23, 2024
@lina-bh
Copy link

lina-bh commented Oct 24, 2024

i had this same problem and after fighting forever with flakes, i touched upon this solution for now:

resource "local_file" "arm-nixincludes" {
  filename        = "${path.module}/arm/tofuout.nix"
  file_permission = "0644"
  content         = <<EOT
{ networking.hostName = "${oci_core_instance.arm.display_name}"; }
EOT
}

module "nixos-anywhere" {
  source = "github.com/nix-community/nixos-anywhere/terraform/all-in-one"
  depends_on = [
    local_file.arm-nixincludes
  ]
  ...

another solution i thought about sitting on the toilet: allow the nixos-rebuild module to create a configuration from a function defined in the flake, to which you can pass --args from the terraform side. but like you say this might have dependency tracking pitfalls. EDIT: i personally decided to split up the responsibilities between cloud infra and system deployment, but while i did i hacked up a script in a couple hours which injects values into the nixos configuration through a function, gets the store path of that derivation, builds its output and pushes it to a target much like the terraform/nixos-rebuild module. https://gist.github.com/lina-bh/b652678579d55949d1bfbd71d34d2720

put this down to the long list of problems caused by flakes' behaviour with git, and not having an impure escape hatch

KiaraGrouwstra added a commit to KiaraGrouwstra/nixos-anywhere that referenced this issue Oct 26, 2024
This PR adds a Terraform input variable I so far named `content`.
This allows passing in a string from Terraform to expose to
nixos-anywhere's build step to make available as a file (default:
`./nixos-vars.json`) within a NixOS configuration, as suggested by
@Mic92 at nix-community#414.
Note the file is staged even if added to gitignore, making this less
suited for development in case the file includes ephemeral content.
As a result, I would consider this approach complementary rather than as
superseding nix-community#414.

Example usage:

```nix
let
  servers = ...;
  variable = ...;
  data = ...;
  resource = ...;
in
{
  inherit variable data resource;
  module =
    lib.mapAttrs (server_name: _server_config: let
    in {
      # pin module version by nix flake inputs
      source =
"github.com/numtide/nixos-anywhere?ref=${inputs.nixos-anywhere.sourceInfo.rev}/terraform/all-in-one";
      ...
      content = lib.tfRef "jsonencode(${lib.strings.toJSON {
        # all variables
        # TF_VARS = lib.mapAttrs (k: _: lib.tfRef
"jsonencode(var.${k})") variable;
        # non-sensitive variables
        TF_VARS = lib.mapAttrs (k: _: lib.tfRef "var.${k}")
(lib.filterAttrs (_k: v: !(v ? sensitive && v.sensitive)) variable);
        TF_DATA = lib.mapAttrs (type: instances: lib.mapAttrs (k: _:
tfRef "data.${type}.${k}") instances) data;
        TF_RESOURCES = lib.mapAttrs (type: instances: lib.mapAttrs (k:
_: tfRef "resource.${type}.${k}") instances) resource;
        TF_SERVER = lib.tfRef "resource.hcloud_server.${server_name}";
        SERVER_NAME = server_name;
      }})";
    })
    servers;
}
```

You can then verify their contents from your `nixosConfigurations` like:

```nix
          lib.nixosSystem {
            inherit system;
            modules = [
              {
                environment.etc."nixos-vars.json".source =
./nixos-vars.json;
              }
            ];
          };
```

-> `ls /etc/` -> `cat /etc/nixos-vars.json`

(in practice one would instead probably parse these back to nix values
to grab specific properties from, e.g. like: `lib.strings.fromJSON
./nixos-vars.json`)
KiaraGrouwstra added a commit to KiaraGrouwstra/nixos-anywhere that referenced this issue Oct 26, 2024
This PR adds a Terraform input variable I so far named `content`.
This allows passing in a string from Terraform to expose to
nixos-anywhere's build step to make available as a file (default:
`./nixos-vars.json`) within a NixOS configuration, as suggested by
@Mic92 at nix-community#414.
Note the file is staged even if added to gitignore, making this less
suited for development in case the file includes ephemeral content.
As a result, I would consider this approach complementary rather than as
superseding nix-community#414.

Example usage:

```nix
let
  servers = ...;
  variable = ...;
  data = ...;
  resource = ...;
in
{
  inherit variable data resource;
  module =
    lib.mapAttrs (server_name: _server_config: let
    in {
      # pin module version by nix flake inputs
      source =
"github.com/numtide/nixos-anywhere?ref=${inputs.nixos-anywhere.sourceInfo.rev}/terraform/all-in-one";
      ...
      content = lib.tfRef "jsonencode(${lib.strings.toJSON {
        # all variables
        # TF_VARS = lib.mapAttrs (k: _: lib.tfRef
"jsonencode(var.${k})") variable;
        # non-sensitive variables
        TF_VARS = lib.mapAttrs (k: _: lib.tfRef "var.${k}")
(lib.filterAttrs (_k: v: !(v ? sensitive && v.sensitive)) variable);
        TF_DATA = lib.mapAttrs (type: instances: lib.mapAttrs (k: _:
tfRef "data.${type}.${k}") instances) data;
        TF_RESOURCES = lib.mapAttrs (type: instances: lib.mapAttrs (k:
_: tfRef "resource.${type}.${k}") instances) resource;
        TF_SERVER = lib.tfRef "resource.hcloud_server.${server_name}";
        SERVER_NAME = server_name;
      }})";
    })
    servers;
}
```

You can then verify their contents from your `nixosConfigurations` like:

```nix
          lib.nixosSystem {
            inherit system;
            modules = [
              {
                environment.etc."nixos-vars.json".source =
./nixos-vars.json;
              }
            ];
          };
```

-> `ls /etc/` -> `cat /etc/nixos-vars.json`

(in practice one would instead probably parse these back to nix values
to grab specific properties from, e.g. like: `lib.strings.fromJSON
./nixos-vars.json`)
KiaraGrouwstra added a commit to KiaraGrouwstra/nixos-anywhere that referenced this issue Oct 26, 2024
This PR adds a Terraform input variable I so far named `content`.
This allows passing in a string from Terraform to expose to
nixos-anywhere's build step to make available as a file (default:
`./nixos-vars.json`) within a NixOS configuration, as suggested by
@Mic92 at nix-community#414.
Note the file is staged even if added to gitignore, making this less
suited for development in case the file includes ephemeral content.
As a result, I would consider this approach complementary rather than as
superseding nix-community#414.

Example usage:

```nix
let
  servers = ...;
  variable = ...;
  data = ...;
  resource = ...;
in
{
  inherit variable data resource;
  module =
    lib.mapAttrs (server_name: _server_config: let
    in {
      # pin module version by nix flake inputs
      source =
"github.com/numtide/nixos-anywhere?ref=${inputs.nixos-anywhere.sourceInfo.rev}/terraform/all-in-one";
      ...
      content = lib.tfRef "jsonencode(${lib.strings.toJSON {
        # all variables
        # TF_VARS = lib.mapAttrs (k: _: lib.tfRef
"jsonencode(var.${k})") variable;
        # non-sensitive variables
        TF_VARS = lib.mapAttrs (k: _: lib.tfRef "var.${k}")
(lib.filterAttrs (_k: v: !(v ? sensitive && v.sensitive)) variable);
        TF_DATA = lib.mapAttrs (type: instances: lib.mapAttrs (k: _:
tfRef "data.${type}.${k}") instances) data;
        TF_RESOURCES = lib.mapAttrs (type: instances: lib.mapAttrs (k:
_: tfRef "resource.${type}.${k}") instances) resource;
        TF_SERVER = lib.tfRef "resource.hcloud_server.${server_name}";
        SERVER_NAME = server_name;
      }})";
    })
    servers;
}
```

You can then verify their contents from your `nixosConfigurations` like:

```nix
          lib.nixosSystem {
            inherit system;
            modules = [
              {
                environment.etc."nixos-vars.json".source =
./nixos-vars.json;
              }
            ];
          };
```

-> `ls /etc/` -> `cat /etc/nixos-vars.json`

(in practice one would instead probably parse these back to nix values
to grab specific properties from, e.g. like: `lib.strings.fromJSON
./nixos-vars.json`)
KiaraGrouwstra added a commit to KiaraGrouwstra/nixos-anywhere that referenced this issue Oct 26, 2024
This PR adds a Terraform input variable I so far named `content`.
This allows passing in a string from Terraform to expose to
nixos-anywhere's build step to make available as a file (default:
`./nixos-vars.json`) within a NixOS configuration, as suggested by
@Mic92 at nix-community#414.
Note the file is staged even if added to gitignore, making this less
suited for development in case the file includes ephemeral content.
As a result, I would consider this approach complementary rather than as
superseding nix-community#414.

Example usage:

```nix
let
  servers = ...;
  variable = ...;
  data = ...;
  resource = ...;
in
{
  inherit variable data resource;
  module =
    lib.mapAttrs (server_name: _server_config: let
    in {
      # pin module version by nix flake inputs
      source =
"github.com/numtide/nixos-anywhere?ref=${inputs.nixos-anywhere.sourceInfo.rev}/terraform/all-in-one";
      ...
      content = lib.tfRef "jsonencode(${lib.strings.toJSON {
        # all variables
        # TF_VARS = lib.mapAttrs (k: _: lib.tfRef
"jsonencode(var.${k})") variable;
        # non-sensitive variables
        TF_VARS = lib.mapAttrs (k: _: lib.tfRef "var.${k}")
(lib.filterAttrs (_k: v: !(v ? sensitive && v.sensitive)) variable);
        TF_DATA = lib.mapAttrs (type: instances: lib.mapAttrs (k: _:
tfRef "data.${type}.${k}") instances) data;
        TF_RESOURCES = lib.mapAttrs (type: instances: lib.mapAttrs (k:
_: tfRef "resource.${type}.${k}") instances) resource;
        TF_SERVER = lib.tfRef "resource.hcloud_server.${server_name}";
        SERVER_NAME = server_name;
      }})";
    })
    servers;
}
```

You can then verify their contents from your `nixosConfigurations` like:

```nix
          lib.nixosSystem {
            inherit system;
            modules = [
              {
                environment.etc."nixos-vars.json".source =
./nixos-vars.json;
              }
            ];
          };
```

-> `ls /etc/` -> `cat /etc/nixos-vars.json`

(in practice one would instead probably parse these back to nix values
to grab specific properties from, e.g. like: `lib.strings.fromJSON
./nixos-vars.json`)
KiaraGrouwstra added a commit to KiaraGrouwstra/nixos-anywhere that referenced this issue Oct 26, 2024
This PR adds a Terraform input variable I so far named `content`.
This allows passing in a string from Terraform to expose to
nixos-anywhere's build step to make available as a file (default:
`./nixos-vars.json`) within a NixOS configuration, as suggested by
@Mic92 at nix-community#414.
Note the file is staged even if added to gitignore, making this less
suited for development in case the file includes ephemeral content.
As a result, I would consider this approach complementary rather than as
superseding nix-community#414.

Example usage:

```nix
let
  servers = ...;
  variable = ...;
  data = ...;
  resource = ...;
in
{
  inherit variable data resource;
  module =
    lib.mapAttrs (server_name: _server_config: let
    in {
      # pin module version by nix flake inputs
      source =
"github.com/numtide/nixos-anywhere?ref=${inputs.nixos-anywhere.sourceInfo.rev}/terraform/all-in-one";
      ...
      content = lib.tfRef "jsonencode(${lib.strings.toJSON {
        # all variables
        # TF_VARS = lib.mapAttrs (k: _: lib.tfRef
"jsonencode(var.${k})") variable;
        # non-sensitive variables
        TF_VARS = lib.mapAttrs (k: _: lib.tfRef "var.${k}")
(lib.filterAttrs (_k: v: !(v ? sensitive && v.sensitive)) variable);
        TF_DATA = lib.mapAttrs (type: instances: lib.mapAttrs (k: _:
tfRef "data.${type}.${k}") instances) data;
        TF_RESOURCES = lib.mapAttrs (type: instances: lib.mapAttrs (k:
_: tfRef "resource.${type}.${k}") instances) resource;
        TF_SERVER = lib.tfRef "resource.hcloud_server.${server_name}";
        SERVER_NAME = server_name;
      }})";
    })
    servers;
}
```

You can then verify their contents from your `nixosConfigurations` like:

```nix
          lib.nixosSystem {
            inherit system;
            modules = [
              {
                environment.etc."nixos-vars.json".source =
./nixos-vars.json;
              }
            ];
          };
```

-> `ls /etc/` -> `cat /etc/nixos-vars.json`

(in practice one would instead probably parse these back to nix values
to grab specific properties from, e.g. like: `lib.strings.fromJSON
./nixos-vars.json`)
KiaraGrouwstra added a commit to KiaraGrouwstra/nixos-anywhere that referenced this issue Oct 30, 2024
This PR adds a Terraform input variable named `content`.
This allows passing in a string from Terraform to expose to
NixOS's run-time to make available as a file (default:
`/etc/nixos-vars.json`) as suggested by @Mic92 at nix-community#414.

This third iteration wraps the original `lib.nixosSystem`
call to allow passing info without either use of `--impure`
or having to stage to Git.

Note the file is staged even if added to gitignore, making this less
suited for development in case the file includes ephemeral content.
As a result, I would consider this approach complementary rather than as
superseding nix-community#414.

Example usage:

```nix
let
  servers = ...;
  variable = ...;
  data = ...;
  resource = ...;
in
{
  inherit variable data resource;
  module =
    lib.mapAttrs (server_name: _server_config: let
    in {
      # pin module version by nix flake inputs
      source =
"github.com/numtide/nixos-anywhere?ref=${inputs.nixos-anywhere.sourceInfo.rev}/terraform/all-in-one";
      ...
      content = lib.tfRef "jsonencode(${lib.strings.toJSON {
        # all variables
        # TF_VARS = lib.mapAttrs (k: _: lib.tfRef
"jsonencode(var.${k})") variable;
        # non-sensitive variables
        TF_VARS = lib.mapAttrs (k: _: lib.tfRef "var.${k}")
(lib.filterAttrs (_k: v: !(v ? sensitive && v.sensitive)) variable);
        TF_DATA = lib.mapAttrs (type: instances: lib.mapAttrs (k: _:
tfRef "data.${type}.${k}") instances) data;
        TF_RESOURCES = lib.mapAttrs (type: instances: lib.mapAttrs (k:
_: tfRef "resource.${type}.${k}") instances) resource;
        TF_SERVER = lib.tfRef "resource.hcloud_server.${server_name}";
        SERVER_NAME = server_name;
      }})";
    })
    servers;
}
```

You can then verify their contents from your `nixosConfigurations` like:

`cat /etc/nixos-vars.json`

However, so far I did not yet manage to reach my goal:

- On this attempt I have so far just exposed the content to run-time,
  rather than to the intended NixOS build-time.
  To address this, I consider looking into injecting thru `specialArgs`,
  tho I am not sure yet this would work, and feel open to suggestions.
- When putting the content file into `.gitignore`,
  the build currently errors on same NAR hash mismatch on the file.
KiaraGrouwstra added a commit to KiaraGrouwstra/nixos-anywhere that referenced this issue Oct 30, 2024
This PR adds a Terraform input variable named `content`.
This allows passing in a string from Terraform to expose to
NixOS's run-time to make available as a file (default:
`/etc/nixos-vars.json`) as suggested by @Mic92 at nix-community#414.

This third implementation wraps the original `lib.nixosSystem`
call to allow passing info without either use of `--impure`
or having to stage to Git.

Example usage:

```nix
let
  servers = ...;
  variable = ...;
  data = ...;
  resource = ...;
in
{
  inherit variable data resource;
  module =
    lib.mapAttrs (server_name: _server_config: let
    in {
      # pin module version by nix flake inputs
      source =
"github.com/numtide/nixos-anywhere?ref=${inputs.nixos-anywhere.sourceInfo.rev}/terraform/all-in-one";
      ...
      special_args = lib.tfRef "jsonencode(${lib.strings.toJSON {
        tf = {
          inherit server_name;
          # all variables
          # var = lib.mapAttrs (k: _: lib.tfRef
  "jsonencode(var.${k})") variable;
          # non-sensitive variables
          var = lib.mapAttrs (k: _: lib.tfRef "var.${k}")
  (lib.filterAttrs (_k: v: !(v ? sensitive && v.sensitive)) variable);
          data = lib.mapAttrs (type: instances: lib.mapAttrs (k: _:
  tfRef "data.${type}.${k}") instances) data;
          resource = lib.mapAttrs (type: instances: lib.mapAttrs (k:
  _: tfRef "resource.${type}.${k}") instances) resource;
          server = lib.tfRef "resource.hcloud_server.${server_name}";
        };
      }})";
    })
    servers;
}
```

You can then use these in your `nixosConfigurations` thru the `tf` argument.

Status:

- [ ] resolve occasional NAR hash mismatches
- [ ] Test putting the content file into `.gitignore`.
KiaraGrouwstra added a commit to KiaraGrouwstra/nixos-anywhere that referenced this issue Oct 30, 2024
This PR adds a Terraform input variable named `content`.
This allows passing in a string from Terraform to expose to
NixOS's run-time to make available as a file (default:
`/etc/nixos-vars.json`) as suggested by @Mic92 at nix-community#414.

This third implementation wraps the original `lib.nixosSystem`
call to allow passing info without either use of `--impure`
or having to stage to Git.

Example usage:

```nix
let
  servers = ...;
  variable = ...;
  data = ...;
  resource = ...;
in
{
  inherit variable data resource;
  module =
    lib.mapAttrs (server_name: _server_config: let
    in {
      # pin module version by nix flake inputs
      source =
"github.com/numtide/nixos-anywhere?ref=${inputs.nixos-anywhere.sourceInfo.rev}/terraform/all-in-one";
      ...
      special_args = lib.tfRef "jsonencode(${lib.strings.toJSON {
        tf = {
          inherit server_name;
          # all variables
          # var = lib.mapAttrs (k: _: lib.tfRef
  "jsonencode(var.${k})") variable;
          # non-sensitive variables
          var = lib.mapAttrs (k: _: lib.tfRef "var.${k}")
  (lib.filterAttrs (_k: v: !(v ? sensitive && v.sensitive)) variable);
          data = lib.mapAttrs (type: instances: lib.mapAttrs (k: _:
  tfRef "data.${type}.${k}") instances) data;
          resource = lib.mapAttrs (type: instances: lib.mapAttrs (k:
  _: tfRef "resource.${type}.${k}") instances) resource;
          server = lib.tfRef "resource.hcloud_server.${server_name}";
        };
      }})";
    })
    servers;
}
```

You can then use these in your `nixosConfigurations` thru the `tf` argument.

Status:

- [ ] Resolve occasional NAR hash mismatches
- [ ] Test putting the content file into `.gitignore`.
- [ ] Let the user pass in a TF map rather than string.
KiaraGrouwstra added a commit to KiaraGrouwstra/nixos-anywhere that referenced this issue Oct 31, 2024
This PR adds a Terraform input variable named `special_args`.
This allows passing in a string from Terraform to expose to
NixOS's `specialArgs` at build-time.

This implementation extends the original `lib.nixosSystem`
call to allow passing info without either use of `--impure`
or having to stage to Git, thanks to @Mic92's suggestion at nix-community#414.

Example usage:

```nix
let
  servers = ...;
  variable = ...;
  data = ...;
  resource = ...;
in
{
  inherit variable data resource;
  module =
    lib.mapAttrs (server_name: _server_config: let
    in {
      # pin module version by nix flake inputs
      source =
"github.com/numtide/nixos-anywhere?ref=${inputs.nixos-anywhere.sourceInfo.rev}/terraform/all-in-one";
      ...
      special_args = lib.tfRef "jsonencode(${lib.strings.toJSON {
        tf = {
          inherit server_name;
          # all variables
          # var = lib.mapAttrs (k: _: lib.tfRef
  "var.${k}") variable;
          # non-sensitive variables
          var = lib.mapAttrs (k: _: lib.tfRef "var.${k}")
  (lib.filterAttrs (_k: v: !(v ? sensitive && v.sensitive)) variable);
          data = lib.mapAttrs (type: instances: lib.mapAttrs (k: _:
  tfRef "data.${type}.${k}") instances) data;
          resource = lib.mapAttrs (type: instances: lib.mapAttrs (k:
  _: tfRef "resource.${type}.${k}") instances) resource;
          server = lib.tfRef "resource.hcloud_server.${server_name}";
        };
      }})";
    })
    servers;
}
```

You can then use these in your `nixosConfigurations`,
in this example thru the `tf` argument.
KiaraGrouwstra added a commit to KiaraGrouwstra/nixos-anywhere that referenced this issue Oct 31, 2024
This PR adds a Terraform input variable named `special_args`.
This allows passing in a string from Terraform to expose to
NixOS's `specialArgs` at build-time.

This implementation extends the original `lib.nixosSystem`
call to allow passing info without either use of `--impure`
or having to stage to Git, thanks to @Mic92's suggestion at nix-community#414.

Example usage:

```nix
let
  servers = ...;
  variable = ...;
  data = ...;
  resource = ...;
in
{
  inherit variable data resource;
  module =
    lib.mapAttrs (server_name: _server_config: let
    in {
      # pin module version by nix flake inputs
      source =
"github.com/numtide/nixos-anywhere?ref=${inputs.nixos-anywhere.sourceInfo.rev}/terraform/all-in-one";
      ...
      special_args = lib.tfRef "jsonencode(${lib.strings.toJSON {
        tf = {
          inherit server_name;
          # all variables
          # var = lib.mapAttrs (k: _: lib.tfRef
  "var.${k}") variable;
          # non-sensitive variables
          var = lib.mapAttrs (k: _: lib.tfRef "var.${k}")
  (lib.filterAttrs (_k: v: !(v ? sensitive && v.sensitive)) variable);
          data = lib.mapAttrs (type: instances: lib.mapAttrs (k: _:
  tfRef "data.${type}.${k}") instances) data;
          resource = lib.mapAttrs (type: instances: lib.mapAttrs (k:
  _: tfRef "resource.${type}.${k}") instances) resource;
          server = lib.tfRef "resource.hcloud_server.${server_name}";
        };
      }})";
    })
    servers;
}
```

You can then use these in your `nixosConfigurations`,
in this example thru the `tf` argument.
KiaraGrouwstra added a commit to KiaraGrouwstra/nixos-anywhere that referenced this issue Oct 31, 2024
This PR adds a Terraform input variable named `special_args`.
This allows passing in a JSON string from Terraform to expose to
NixOS's `specialArgs` at build-time.

This implementation extends the original `lib.nixosSystem`
call to allow passing info without either use of `--impure`
or having to stage to Git, thanks to @Mic92's suggestion at nix-community#414.

Example usage:

```nix
let
  servers = ...;
  variable = ...;
  data = ...;
  resource = ...;
in
{
  inherit variable data resource;
  module =
    lib.mapAttrs (server_name: _server_config: let
    in {
      # pin module version by nix flake inputs
      source =
"github.com/numtide/nixos-anywhere?ref=${inputs.nixos-anywhere.sourceInfo.rev}/terraform/all-in-one";
      ...
      special_args = lib.tfRef "jsonencode(${lib.strings.toJSON {
        tf = {
          inherit server_name;
          # all variables
          # var = lib.mapAttrs (k: _: lib.tfRef
  "var.${k}") variable;
          # non-sensitive variables
          var = lib.mapAttrs (k: _: lib.tfRef "var.${k}")
  (lib.filterAttrs (_k: v: !(v ? sensitive && v.sensitive)) variable);
          data = lib.mapAttrs (type: instances: lib.mapAttrs (k: _:
  tfRef "data.${type}.${k}") instances) data;
          resource = lib.mapAttrs (type: instances: lib.mapAttrs (k:
  _: tfRef "resource.${type}.${k}") instances) resource;
          server = lib.tfRef "resource.hcloud_server.${server_name}";
        };
      }})";
    })
    servers;
}
```

You can then use these in your `nixosConfigurations`,
in this example thru the `tf` argument.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants