Hacker News new | ask | show | jobs
by dayallnash 483 days ago
Terragrunt goes a long way to providing a near-perfect way to structure Terraform repos.
1 comments

I didn't understand the benefit of using terragrunt. Modern terraform supports all of the features terragrunt was originally designed to work around way back when.

Outside of being able to use variables in very niche places that you can't in terraform (and can easily work around, and that last I heard is on the road map for open tofu), what does terragrunt do that using regular module imports in terraform don't?

This may be anecdotal but every terragrunt repository I've ever seen was a mess of spaghetti trying too hard to stay DRY.

I'm from Gruntwork; we're the maintainers of Terragrunt.

We get this question a lot because Terragrunt did in fact start as a feature shim for Terraform. But that was a long time ago and Terragrunt has evolved into a first-class "orchestration" tool for Terraform or OpenTofu.

We wrote a blog post addressing exactly your concern that you might find helpful: https://blog.gruntwork.io/terragrunt-opentofu-better-togethe....

1) I use terragrunt to generate all the 'boilerplate' files, for example the backend configuration to ensure they are all in spec.

2) I use terragrunt to provide inherited values, such as region, environment, etc. I have a directory tree of `dev/us-west-2/` I can set a variable in my `dev/environment.hcl` that is inherited across everything under that environment. This is useful if you have more than one dev, prod, etc environment.

3) I use terragrunt to allow shared, versioned root modules. I don't include any terraform in my terragrunt repo. The terragrunt repo is just configuration. In my terragrunt.hcl I can reference something like `source = "github.com/example.com/root.git//ipv6-vpc?ref=v0.1.3"` to pull in the version of the root module I want. Again this is useful if you have multiple dev/stage/prod environments.

None of this is actually possible with plain terraform.

This is exactly what I'm talking about.

Using variables isn't supported in backends - e.g. "niche places" (although it sounds like it is in OpenTofu)

And #2 and #3 are exactly the use-case for just regular old tfvars files and module imports.

Terragrunt encourages you to abstract things way, way too far, until you have an absolute mess of tangled imports and deeply nested directories.

Nothing wrong with having a root module, some child modules, and a single tfvars file being fed in on the front end.

Not just on the roadmap!

With OpenTofu as of the latest release you can already use constant variables in places like module sources and versions, backend configurations, and even in order to for_each on providers!

Disclaimer: involved in OpenTofu

Pain and suffering lies behind any attempts to make tf DRY. Unless you have a really insane amount of envs, I just copy/pasta these days. Fuck it. Life is too short.