Skip to content
tezvyn:

Terragrunt: A Thin Wrapper for DRY Terraform

Source: docs.terragrunt.comHardHow cards are made

Terragrunt: A Thin Wrapper for DRY Terraform

Terragrunt is a thin wrapper for Terraform/OpenTofu that automates common tasks. Just add an empty terragrunt.hcl file to get features like automatic init.

Why it exists

As Terraform projects grow, managing them becomes complex. You end up with repeated configurations, especially for backend state, and running commands across multiple modules is manual. Terragrunt exists to solve these structural problems by providing a thin wrapper around Terraform to keep your code DRY (Don't Repeat Yourself).

The mental model

Think of Terragrunt as a smart orchestrator for Terraform. You continue to write standard Terraform/OpenTofu code, but you add a terragrunt.hcl file to control the execution environment. You then run terragrunt apply instead of terraform apply, letting Terragrunt handle the boring, repetitive tasks for you.

How it works

To start, you add a terragrunt.hcl file to your Terraform project directory. You then use the terragrunt CLI for all operations. Terragrunt reads your terragrunt.hcl file, performs any configured pre-steps, and then calls the underlying terraform or tofu binary with the appropriate arguments. The simplest benefit, called Auto-init, is that Terragrunt automatically runs init for you if necessary, so you no longer have to run it manually before a plan or apply.

When to use it

Use Terragrunt when you want to manage your Terraform/OpenTofu projects more effectively. It's particularly useful as your infrastructure scales, offering features for GitOps pipelines, drift detection, automated updates, and managing stacks of modules. It helps you define configurations once and reuse them across multiple environments.

When not to use it

For a very small, single-module project with no shared state or multiple environments, Terragrunt might be overkill. If you're just learning Terraform, adding another layer of abstraction can be confusing. Master Terraform's core concepts first.

One canonical example

An engineer is working on a Terraform project. To apply changes, they must remember to run terraform init before terraform apply. By adding an empty terragrunt.hcl file to the project, they can now simply run terragrunt apply. Terragrunt's Auto-init feature detects that the project isn't initialized and automatically runs terraform init before executing the apply command, simplifying the workflow.

Interview question

What is the primary motivation for adopting Terragrunt in a Terraform project that is experiencing growth?

  • a.To introduce a new, more expressive configuration language for infrastructure definition.
  • b.To enable direct integration with cloud provider APIs without requiring Terraform providers.
  • c.To reduce configuration duplication and automate repetitive operational tasks across environments.Correct
  • d.To replace the standard Terraform CLI with a more robust and feature-rich command-line interface.
Why?

Terragrunt's core purpose is to solve the structural problems of growing Terraform projects by keeping configurations DRY (Don't Repeat Yourself) and automating repetitive tasks across multiple modules and environments. Option D is incorrect because Terragrunt acts as a wrapper that orchestrates the existing Terraform CLI, rather than replacing it entirely, to achieve these goals.

Just read this? Test yourself on what you have been reading.

Read the original → docs.terragrunt.com

Put your scrolling time to good use

Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Every open role lists the topics its interview covers, so you can prepare for the real thing rather than guessing.

See open roles