我正在尝试使用 2-repo IaC,所谓的后端采用terragrunt
模块的形式,而前端(或live
)具有正在填充变量的此类模块的实例化。
下图描述了这 2 个 repos 的结构(顾名思义是terragrunt
后端和实时的)。terraform-live
在 myterragrunt/aws-vpc/variables.tf
中,有以下声明:
variable "remote_state_bucket" {
description = "The bucket containing the terraform remote state"
}
但是,当尝试terragrunt apply
在实时目录中执行时,我得到以下信息:
var.remote_state_bucket
The bucket containing the terraform remote state
Enter a value:
这是我的terraform-live/environments/staging/terragrunt.hcl
remote_state {
backend = "s3"
config = {
bucket = "my-bucket-staging"
key = "terraform/state/var.env_name/${path_relative_to_include()}"
region = "eu-west-1"
}
}
# Configure root level variables that all resources can inherit
terraform {
extra_arguments "extra_args" {
commands = "${get_terraform_commands_that_need_vars()}"
optional_var_files = [
"${get_terragrunt_dir()}/${find_in_parent_folders("config.tfvars", "ignore")}",
"${get_terragrunt_dir()}/${find_in_parent_folders("secrets.auto.tfvars", "ignore")}",
]
}
}
更重要的是,该变量似乎是在terragrunt
指示从以下位置读取变量的文件之一中声明的:
➢ cat terraform-live/environments/staging/config.tfvars
remote_state_bucket = "pkaramol-staging"
为什么terragrunt
(或terraform
?)无法读取特定变量?
➢ terragrunt --version
terragrunt version v0.19.29
➢ terraform --version
Terraform v0.12.4