Using Nix to manage terraform

Hi, I’ve been thinking recently, and was wondering if an effort to help bring Nix to manage terraform is a good idea. For example, managing dependencies, providers, modules and so on.

Because, for example, one of the problems with terraform and some providers is that multiple providers of the same version can’t exist at the same time (case in point - azurerm 2 for older virtual machine modules, and azurerm 3 for newer virtual machine modules), and with Nix that wouldn’t be an issue - would it?


That is a way to write terraform files using nix, but you’re still converting it to json files that terraform interprets and it manages its own providers and modules.

From my perspective, all that it allows is to use Nix language to write terraform configuration files, but it does not replace terraform’s package/ module/ dependency management system, it still has the same flaws, like the incapability to handle multiple versions of the same provider simultaneously

I’m uncertain if this is what you’re after. But I know you can ask Nix to create a Terraform “package” with certain providers already installed.

terraform.withPlugins (p: [ p.hcloud ])

I look through the list of packaged providers on NixOS search. You can then also use projects like terranix, which @fricklerhandwerk recommended, and terraform-nixos-ng to even further “nixify” your project.

Regarding the multiple versions issue. I guess you could pin multiple nixpkgs versions that included different versions of the providers, and build your terraform “package” that way. Although I’m uncertain how well-supported this is, if at all.

1 Like