我尝试使用一个2-repo的IaC,所谓的后端是terragrunt模块的形式,前端(或live)是用变量填充的模块的实例化。
下图描述了这两个存储库的结构(terragrunt是后端,terraform-live顾名思义就是活动存储库)。

在我的terragrunt/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发布于 2020-02-14 00:14:38
因为config.tfvars不在父文件夹中:)
find_in_parent_folders在父文件夹中查找,但不在当前文件夹中查找。并且您的config.tfvars与您的terragrunt.hcl在同一文件夹中。
尝试使用类似以下内容:
optional_var_files = [
"${get_terragrunt_dir()}/config.tfvars",
"${get_terragrunt_dir()}/secrets.auto.tfvars",
]https://stackoverflow.com/questions/58257819
复制相似问题