terragrunt
Terragrunt is a flexible orchestration tool that allows Infrastructure as Code written in OpenTofu/Terraform to scale.
Top Related Projects
Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.
Pulumi - Infrastructure as Code in any programming language 🚀
A Pluggable Terraform Linter
OpenTofu lets you declaratively manage your cloud infrastructure.
🚀 Geodesic is a DevOps Linux Toolbox in Docker
Quick Overview
Terragrunt is a thin wrapper for Terraform that provides extra tools for working with multiple Terraform modules, remote state, and locking. It aims to keep your Terraform code DRY, promote best practices, and make it easier to work with Terraform in a team environment.
Pros
- Reduces code duplication by allowing you to define common Terraform configurations once and reuse them across multiple environments
- Simplifies remote state management and locking, making it easier to work with Terraform in a team setting
- Provides built-in support for keeping your Terraform modules DRY and maintainable
- Offers enhanced CLI capabilities, including the ability to run Terraform commands on multiple modules at once
Cons
- Adds an additional layer of complexity to your Terraform workflow
- Requires learning a new tool and its specific syntax on top of Terraform
- May have a steeper learning curve for teams already familiar with vanilla Terraform
- Some users report occasional issues with version compatibility between Terragrunt and Terraform
Code Examples
- Basic Terragrunt configuration:
# terragrunt.hcl
terraform {
source = "git::git@github.com:foo/modules.git//app?ref=v0.0.1"
}
inputs = {
app_name = "my-app"
environment = "prod"
}
- Using Terragrunt to generate backend configuration:
# terragrunt.hcl
remote_state {
backend = "s3"
config = {
bucket = "my-terraform-state"
key = "${path_relative_to_include()}/terraform.tfstate"
region = "us-west-2"
}
}
- Inheriting configurations using Terragrunt:
# child/terragrunt.hcl
include {
path = find_in_parent_folders()
}
inputs = {
instance_type = "t2.micro"
}
Getting Started
-
Install Terragrunt:
brew install terragrunt
-
Create a
terragrunt.hcl
file in your project root:terraform { source = "git::git@github.com:example/modules.git//mymodule?ref=v0.1.0" } inputs = { region = "us-west-2" }
-
Run Terragrunt commands:
terragrunt init terragrunt plan terragrunt apply
Competitor Comparisons
Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.
Pros of Terraform
- Native support from HashiCorp, ensuring seamless integration with other HashiCorp products
- Larger community and ecosystem, resulting in more resources, modules, and third-party integrations
- More comprehensive documentation and official learning resources
Cons of Terraform
- Lacks built-in support for DRY (Don't Repeat Yourself) principles, often leading to code duplication
- No native way to manage multiple environments or handle code reuse across different projects
Code Comparison
Terraform:
resource "aws_instance" "example" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t2.micro"
}
Terragrunt:
include {
path = find_in_parent_folders()
}
terraform {
source = "git::git@github.com:foo/modules.git//app?ref=v0.0.1"
}
Key Differences
- Terragrunt is built on top of Terraform, providing additional features for managing Terraform configurations
- Terragrunt focuses on improving code reuse, managing remote state, and keeping configurations DRY
- Terraform is a standalone tool, while Terragrunt requires Terraform to function
Use Cases
- Use Terraform for simpler projects or when native HashiCorp support is crucial
- Choose Terragrunt for complex, multi-environment deployments or when code reuse is a priority
Pulumi - Infrastructure as Code in any programming language 🚀
Pros of Pulumi
- Supports multiple programming languages (Python, TypeScript, Go, etc.)
- Offers more flexibility in defining infrastructure as code
- Provides better integration with existing development workflows
Cons of Pulumi
- Steeper learning curve for those familiar with declarative IaC tools
- Requires more setup and configuration compared to Terragrunt
- May have slower execution times for large-scale deployments
Code Comparison
Terragrunt (HCL):
terraform {
source = "git::git@github.com:foo/modules.git//app?ref=v0.0.1"
}
inputs = {
app_name = "my-app"
}
Pulumi (Python):
import pulumi
from pulumi_aws import s3
bucket = s3.Bucket("my-bucket")
pulumi.export("bucket_name", bucket.id)
Key Differences
- Terragrunt is an extension of Terraform, while Pulumi is a standalone IaC tool
- Pulumi uses general-purpose programming languages, Terragrunt uses HCL
- Terragrunt focuses on Terraform workflow improvements, Pulumi offers a complete IaC solution
- Pulumi has built-in state management, while Terragrunt relies on Terraform's state handling
Use Cases
- Terragrunt: Best for teams already using Terraform and seeking to improve workflows
- Pulumi: Ideal for developers who prefer using familiar programming languages for IaC
A Pluggable Terraform Linter
Pros of TFLint
- Focuses on static analysis and linting of Terraform code
- Provides customizable rules and plugins for extended functionality
- Faster execution time for code checks
Cons of TFLint
- Limited to linting and doesn't provide infrastructure management features
- Requires separate integration into the development workflow
Code Comparison
TFLint example:
resource "aws_instance" "example" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t2.micro"
}
Terragrunt example:
include {
path = find_in_parent_folders()
}
terraform {
source = "git::git@github.com:foo/modules.git//app?ref=v0.0.1"
}
Key Differences
- Terragrunt is a thin wrapper for Terraform that provides extra tools for keeping configurations DRY, working with multiple Terraform modules, and managing remote state
- TFLint is specifically designed for linting Terraform code and catching errors before applying changes
- Terragrunt focuses on managing and organizing Terraform configurations across multiple environments and modules
- TFLint is more suitable for code quality checks and best practices enforcement
Use Cases
- Use Terragrunt for managing complex, multi-environment Terraform deployments
- Use TFLint for catching errors, enforcing best practices, and improving code quality in Terraform configurations
OpenTofu lets you declaratively manage your cloud infrastructure.
Pros of OpenTofu
- Fully open-source alternative to Terraform, providing more community control
- Aims to maintain compatibility with existing Terraform configurations
- Potential for faster feature development and bug fixes due to community-driven approach
Cons of OpenTofu
- Relatively new project, may lack the maturity and extensive ecosystem of Terragrunt
- Potential compatibility issues with future Terraform updates
- Limited documentation and community resources compared to Terragrunt
Code Comparison
OpenTofu (similar to Terraform):
resource "aws_instance" "example" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t2.micro"
}
Terragrunt:
include {
path = find_in_parent_folders()
}
terraform {
source = "git::git@github.com:foo/modules.git//app?ref=v0.0.3"
}
OpenTofu focuses on infrastructure-as-code definition, while Terragrunt provides a wrapper for Terraform, offering additional features like configuration management and DRY principles. OpenTofu aims to be a drop-in replacement for Terraform, maintaining similar syntax and functionality, whereas Terragrunt enhances Terraform's capabilities with its own set of features and conventions.
🚀 Geodesic is a DevOps Linux Toolbox in Docker
Pros of Geodesic
- Provides a complete DevOps toolkit with pre-configured tools and workflows
- Offers a containerized approach for consistent development environments
- Includes built-in support for multiple cloud providers and services
Cons of Geodesic
- Steeper learning curve due to its comprehensive nature
- Less focused on Terraform-specific operations compared to Terragrunt
- May introduce additional complexity for simpler projects
Code Comparison
Geodesic (Dockerfile snippet):
FROM alpine:3.14
RUN apk add --no-cache aws-cli terraform kubectl
COPY geodesic.sh /usr/local/bin/
ENTRYPOINT ["/usr/local/bin/geodesic.sh"]
Terragrunt (HCL configuration):
terraform {
source = "git::git@github.com:foo/modules.git//app?ref=v0.0.3"
}
include {
path = find_in_parent_folders()
}
inputs = {
app_name = "my-app"
}
Geodesic provides a more comprehensive DevOps environment with pre-configured tools, while Terragrunt focuses specifically on enhancing Terraform workflows. Geodesic's containerized approach ensures consistency across different environments, but it may be overkill for simpler projects. Terragrunt offers a more straightforward integration with existing Terraform setups, making it easier to adopt for teams already using Terraform. The code examples highlight the different approaches: Geodesic uses a Dockerfile to create a complete environment, while Terragrunt uses HCL configuration to extend Terraform functionality.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Terragrunt
Terragrunt is a flexible orchestration tool that allows Infrastructure as Code written in OpenTofu/Terraform to scale.
Please see the following for more info, including install instructions and complete documentation:
- Terragrunt Website
- Getting started with Terragrunt
- Terragrunt Documentation
- Contributing to Terragrunt
- Commercial Support
Join the Discord!
Join our community for discussions, support, and contributions:
License
This code is released under the MIT License. See LICENSE.txt.
Top Related Projects
Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.
Pulumi - Infrastructure as Code in any programming language 🚀
A Pluggable Terraform Linter
OpenTofu lets you declaratively manage your cloud infrastructure.
🚀 Geodesic is a DevOps Linux Toolbox in Docker
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot