Я слежу за документами terragrunt, и в итоге я получил такую структуру:
- услуги / фунт
- услуги / бэкэнд
- vpc
Я установил зависимость vpc в services / lb и в services / backend, и он работает автономно, что позволяет применять terragrunt run-all.
Затем я попытался перенести эту конфигурацию в модули инфраструктуры, следуя 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::[email protected]:project/infrastructure-modules.git//vpc"
}
инфраструктура-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
}
Информация о зависимости от оболочки:
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. Мы видим, что существует outputs.tf, поэтому у vpc есть выходы.
Содержание outputs.tf
output "backend_vpc_id" {
value = digitalocean_vpc.backend_vpc.id
description = "Backend VPC ID"
}
Что мне не хватает? Что мне нужно сделать, чтобы получить доступ к выходным данным импортированного источника?
Большое спасибо за помощь.