Terraform Advanced — Terragrunt Dependency Blocks
Reference outputs from other stacks without terraform_remote_state data sources.
The dependency Block
# environments/prod/eks/terragrunt.hcl
include "root" {
path = find_in_parent_folders()
}
terraform {
source = "../../../modules/eks"
}
dependency "vpc" {
config_path = "../vpc"
}
dependency "rds" {
config_path = "../rds"
}
inputs = {
vpc_id = dependency.vpc.outputs.vpc_id
subnet_ids = dependency.vpc.outputs.private_subnet_ids
db_host = dependency.rds.outputs.endpoint
}
How It Works
terragrunt apply (in prod/eks/)
1. Detects dependency on prod/vpc/ and prod/rds/
2. Reads their state files to get outputs
3. Passes outputs as inputs to the EKS module
Mock Outputs (for plan Before Dependencies Exist)
dependency "vpc" {
config_path = "../vpc"
mock_outputs = {
vpc_id = "vpc-mock"
private_subnet_ids = ["subnet-mock-1", "subnet-mock-2"]
}
mock_outputs_allowed_terraform_commands = ["plan", "validate"]
}
💡 Production Tip: Mock outputs let you
terragrunt planbefore dependencies are applied — essential for CI/CD pipelines.
What’s Next?
Apply entire folder trees with run-all.