Terragrunt dependency and mock_outputs
dependency block
Reads outputs from another Terragrunt unit - cleaner than terraform_remote_state and aware of the apply order.
# environments/prod/eks/terragrunt.hcl
include "root" {
path = find_in_parent_folders("root.hcl")
}
dependency "vpc" {
config_path = "../vpc"
}
dependency "rds" {
config_path = "../rds"
}
inputs = {
vpc_id = dependency.vpc.outputs.vpc_id
private_subnets = dependency.vpc.outputs.private_subnet_ids
db_endpoint = dependency.rds.outputs.endpoint
}
mock_outputs
Without mock outputs, terragrunt plan fails if a dependency hasn't been applied yet - it can't fetch real outputs. Mock outputs provide placeholder values for plan only.
dependency "vpc" {
config_path = "../vpc"
mock_outputs = {
vpc_id = "vpc-00000000"
private_subnet_ids = ["subnet-00000000", "subnet-11111111"]
}
mock_outputs_allowed_terraform_commands = ["plan", "validate"]
}
mock_outputs_allowed_terraform_commands
Controls which commands use mocks - apply always uses real outputs.
mock_outputs_allowed_terraform_commands = ["plan", "validate", "destroy"]
dependency graph
Terragrunt resolves the graph automatically with run-all - units apply in the right order.
vpc ──► eks
──► rds ──► app
# applies vpc first, then rds and eks in parallel, then app
terragrunt run-all apply
Originally published at https://bard.sh/posts/terragrunt_dependency/
Top comments (0)