I've been following terragrunt docs and I end up with a structure like the following one:
I had set a dependency of vpc in services/lb and in services/backend and it works standalone making terragrunt run-all apply.
Then I tried to move this configuration to infrastructure modules following https://terragrunt.gruntwork.io/docs/getting-started/quick-start/#promote-immutable-versioned-terraform-modules-across-environments and create a new repository with the different stages:
Making this I learned (if I am not missing anything) that when importing a source, terragrunt.hcl dependencies configuration of that source are ignored.
samuel@angel:~/Documents/infrastructure-live/prod$ terragrunt_linux_amd64 run-all apply
INFO[0000] Stack at /home/samuel/Documents/infrastructure-live/prod:
=> Module /home/samuel/Documents/infrastructure-live/prod (excluded: false, dependencies: [])
=> Module /home/samuel/Documents/infrastructure-live/prod/services/backend (excluded: false, dependencies: [])
=> Module /home/samuel/Documents/infrastructure-live/prod/services/lb (excluded: false, dependencies: [])
=> Module /home/samuel/Documents/infrastructure-live/prod/vpc (excluded: false, dependencies: [])
Are you sure you want to run 'terragrunt apply' in each folder of the stack described above? (y/n) y
So I add explicit dependency configuration in my infrastructure-live terragrunt modules:
infrastructure-live/prod/vpc/terragrunt.hcl
include {
path = find_in_parent_folders()
}
terraform {
extra_arguments "common_vars" {
commands = get_terraform_commands_that_need_vars()
arguments = [
"-var-file=../network.tfvars",
"-var-file=../region.tfvars"
]
}
source = "git::[email protected]:project/infrastructure-modules.git//vpc"
}
infrastructure-live/prod/backend/terragrunt.hcl
terraform {
source = "git::[email protected]:project/infrastructure-modules.git//services/backend"
}
include {
path = find_in_parent_folders()
}
dependency "vpc" {
config_path = "../../vpc"
}
inputs = {
backend_vpc_id = dependency.vpc.outputs.backend_vpc_id
}
Dependency information from shell:
INFO[0000] Stack at /home/samuel/Documents/infrastructure-live/prod:
=> Module /home/samuel/Documents/infrastructure-live/prod (excluded: false, dependencies: [])
=> Module /home/samuel/Documents/infrastructure-live/prod/services/backend (excluded: false, dependencies: [/home/samuel/Documents/infrastructure-live/prod/vpc])
=> Module /home/samuel/Documents/infrastructure-live/prod/services/lb (excluded: false, dependencies: [/home/samuel/Documents/infrastructure-live/prod/vpc, /home/samuel/Documents/infrastructure-live/prod/services/backend])
=> Module /home/samuel/Documents/infrastructure-live/prod/vpc (excluded: false, dependencies: [])
But now it says that the dependency does not have outputs. But they are outputs in the module of the imported source!
ERRO[0061] Module /home/samuel/Documents/infrastructure-live/prod/services/backend has finished with an error: /home/samuel/Documents/infrastructure-live/prod/vpc/terragrunt.hcl is a dependency of /home/samuel/Documents/infrastructure-live/prod/services/backend/terragrunt.hcl but detected no outputs. Either the target module has not been applied yet, or the module has no outputs. If this is expected, set the skip_outputs flag to true on the dependency block. prefix=[/home/samuel/Documents/infrastructure-live/prod/services/backend]ERRO[0061] Dependency /home/samuel/Documents/infrastructure-live/prod/services/backend of module /home/samuel/Documents/infrastructure-live/prod/services/lb just finished with an error. Module /home/samuel/Documents/infrastructure-live/prod/services/lb will have to return an error too. prefix=[/home/samuel/Documents/infrastructure-live/prod/services/lb]
ERRO[0061] Module /home/samuel/Documents/infrastructure-live/prod/services/lb has finished with an error: Cannot process module Module /home/samuel/Documents/infrastructure-live/prod/services/lb (excluded: false, dependencies: [/home/samuel/Documents/infrastructure-live/prod/vpc, /home/samuel/Documents/infrastructure-live/prod/services/backend]) because one of its dependencies, Module /home/samuel/Documents/infrastructure-live/prod/services/backend (excluded: false, dependencies: [/home/samuel/Documents/infrastructure-live/prod/vpc]), finished with an error: /home/samuel/Documents/infrastructure-live/prod/vpc/terragrunt.hcl is a dependency of /home/samuel/Documents/infrastructure-live/prod/services/backend/terragrunt.hcl but detected no outputs. Either the target module has not been applied yet, or the module has no outputs. If this is expected, set the skip_outputs flag to true on the dependency block. prefix=[/home/samuel/Documents/infrastructure-live/prod/services/lb]ERRO[0061] Encountered the following errors:Cannot process module Module /home/samuel/Documents/infrastructure-live/prod/services/lb (excluded: false, dependencies: [/home/samuel/Documents/infrastructure-live/prod/vpc, /home/samuel/Documents/infrastructure-live/prod/services/backend]) because one of its dependencies, Module /home/samuel/Documents/infrastructure-live/prod/services/backend (excluded: false, dependencies: [/home/samuel/Documents/infrastructure-live/prod/vpc]), finished with anerror: /home/samuel/Documents/infrastructure-live/prod/vpc/terragrunt.hcl is a dependency of /home/samuel/Documents/infrastructure-live/prod/services/backend/terragrunt.hcl but detected no outputs. Either the target module has not been applied yet, or the module has no outputs. If this is expected, set the skip_outputs flag to true on the dependency block.
/home/samuel/Documents/infrastructure-live/prod/vpc/terragrunt.hcl is a dependency of /home/samuel/Documents/infrastructure-live/prod/services/backend/terragrunt.hcl but detected no outputs. Either the target module has not been applied yet, or the module has no outputs. If this is expected, set the skip_outputs flag to true on the dependency block. ERRO[0061] Unable to determine underlying exit code, so Terragrunt will exit with error code 1
This is terragrunt cache for VPC. We can see that outputs.tf exists so vpc has outputs.
Content of outputs.tf
output "backend_vpc_id" {
value = digitalocean_vpc.backend_vpc.id
description = "Backend VPC ID"
}
What I am missing? What I have to do to access to the outputs of a imported source?
Thanks a lot for the help.
For those who are still suffering about this issue, you may also try adding a mock_outputs
to the dependency and see if it works:
dependency "vpc" {
config_path = find_in_parent_folders("vpc")
mock_outputs = {
vpc_id = "temp-id"
}
}
inputs = {
vpc_id = dependency.vpc.outputs.vpc_id
}
https://terragrunt.gruntwork.io/docs/features/execute-terraform-commands-on-multiple-modules-at-once/#unapplied-dependency-and-mock-outputs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With