I've been following terragrunt docs and I end up with a structure like the following one:
- services/lb
- services/backend
- vpc
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:
- prod
- stage
- ...
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::git@gitlab.com:project/infrastructure-modules.git//vpc"
}
infrastructure-live/prod/backend/terragrunt.hcl
terraform {
source = "git::git@gitlab.com: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.