我一直在跟踪terragrunt文档,最后得到了如下结构:
我在services/lb和services/后端中设置了vpc的依赖项,它独立工作,使terragrunt运行--都适用。
然后,我尝试将此配置转移到https://terragrunt.gruntwork.io/docs/getting-started/quick-start/#promote-immutable-versioned-terraform-modules-across-environments之后的基础设施模块,并创建一个具有不同阶段的新存储库:
我了解到(如果我没有遗漏任何东西),在导入源时,会忽略该源的terragrunt.hcl依赖项配置。
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 因此,我在我的基础设施中添加了显式依赖配置--活的terragrunt模块:
基础设施-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
}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: []) 但是现在它说依赖项没有输出。但它们是导入源模块中的输出!
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这是用于VPC的terragrunt缓存。我们可以看到outputs.tf的存在,因此vpc具有输出。

outputs.tf含量
output "backend_vpc_id" {
value = digitalocean_vpc.backend_vpc.id
description = "Backend VPC ID"
}我错过了什么?我要怎么做才能访问输入源的输出?
非常感谢你的帮助。
发布于 2021-05-24 16:55:59
您应该使用以下依赖项:
dependency "vpc" {
config_path = find_in_parent_folders("vpc")
}看起来你的vpc的路径是错误的,所以terragrunt没有检测到输出。
发布于 2021-12-01 07:53:06
对于那些仍在遭受此问题困扰的人,您也可以尝试在依赖项中添加一个mock_outputs,并查看它是否有效:
dependency "vpc" {
config_path = find_in_parent_folders("vpc")
mock_outputs = {
vpc_id = "temp-id"
}
}
inputs = {
vpc_id = dependency.vpc.outputs.vpc_id
}发布于 2022-08-25 13:40:06
当我们把资源输入地球时,我们也遇到了同样的问题。显然,在依赖路径中运行terragrunt state pull时,我们发现"outputs“对象在状态中为空。还可以通过运行terragrunt output来检查这一点。运行terragrunt refresh解决了这个问题!
https://stackoverflow.com/questions/67435792
复制相似问题