Advanced Terragrunt CLI Features - Beyond Basic Infrastructure Management
Discover powerful Terragrunt CLI features that enhance infrastructure management at scale beyond traditional Terraform workflows.
1. terragrunt stack run
The terragrunt stack run command allows you to execute commands across multiple infrastructure units simultaneously. This is particularly valuable for managing complex multi-environment deployments where you need to apply changes across multiple related configurations.
# Run plan across all units in the stack
terragrunt stack run plan
# Apply changes to all units
terragrunt stack run apply
# Run with specific targeting
terragrunt stack run apply --terragrunt-include-dir prod/
2. terragrunt catalog
An interactive Terminal User Interface (TUI) for browsing and discovering Terraform modules. This command provides a visual interface to explore available modules from your catalog, making it easier to find and understand infrastructure components.
# Launch interactive catalog browser
terragrunt catalog
# Browse specific catalog path
terragrunt catalog --catalog-path ./modules
3. terragrunt scaffold
Generates configuration files from a module catalog, streamlining the creation of new infrastructure components. This command accelerates development by providing templated configurations based on existing patterns.
# Generate configuration from catalog
terragrunt scaffold
# Scaffold with specific module
terragrunt scaffold --module-name vpc --output-dir ./environments/staging
4. terragrunt find
Locate relevant Terragrunt configurations within your infrastructure codebase. This command helps navigate complex directory structures and find specific configurations quickly.
# Find all terragrunt.hcl files
terragrunt find
# Find configurations in specific directory
terragrunt find --terragrunt-working-dir ./environments/
# Find with pattern matching
terragrunt find --terragrunt-include-dir "**/prod/**"
5. terragrunt render
Fully resolve and display configuration with all dependencies, interpolations, and includes processed. This command is invaluable for debugging complex configurations and understanding how Terragrunt processes your HCL files.
# Render current configuration
terragrunt render
# Render with specific configuration file
terragrunt render --terragrunt-config custom-terragrunt.hcl
# Render and save to file
terragrunt render > resolved-config.hcl
6. terragrunt graph dag
Visualize infrastructure dependency relationships by generating a directed acyclic graph (DAG). This command helps understand the order of operations and dependencies between different infrastructure components.
# Generate dependency graph
terragrunt graph dag
# Output graph in DOT format for visualization
terragrunt graph dag --output graph.dot
# Visualize with Graphviz
terragrunt graph dag | dot -Tpng > infrastructure-deps.png
7. Auto-init Functionality
Terragrunt automatically handles terraform init
operations without explicit user commands. This feature simplifies workflow management by ensuring that workspaces are always properly initialized before executing other commands.
# Terragrunt automatically runs init when needed
terragrunt plan # Automatically initializes if needed
terragrunt apply # No manual init required
8. Enhanced Debugging and Logging
Advanced logging and debugging options for troubleshooting complex infrastructure deployments.
# Enable debug logging
terragrunt apply --terragrunt-log-level debug
# Show configuration processing details
terragrunt plan --terragrunt-debug
# Disable automatic init for troubleshooting
terragrunt apply --terragrunt-no-auto-init
9. Working with Multiple Configurations
Terragrunt provides enhanced capabilities for managing multiple related configurations simultaneously.
# Run commands on all dependencies
terragrunt run-all plan
# Apply with dependency management
terragrunt run-all apply --terragrunt-non-interactive
# Destroy in reverse dependency order
terragrunt run-all destroy
10. Advanced State Management
Terragrunt simplifies state management across multiple environments and configurations with built-in remote state handling.
# Show state information
terragrunt show
# Refresh state across all configurations
terragrunt run-all refresh
# Validate all configurations
terragrunt run-all validate
Best Practices
Use Stack Commands for Multi-Environment Management
# Coordinate changes across environments
terragrunt stack run plan --terragrunt-include-dir "environments/"
Leverage Auto-Discovery Features
# Let Terragrunt find and process configurations automatically
terragrunt run-all apply --terragrunt-working-dir ./infrastructure/
Combine Commands for Powerful Workflows
# Render configuration and validate before applying
terragrunt render && terragrunt validate && terragrunt apply
These advanced Terragrunt CLI features enable more efficient infrastructure management at scale, providing better visibility, automation, and control over complex infrastructure deployments compared to using Terraform alone.