terraform - terragrunt 不接受 vars 文件
问题描述
我正在尝试使用 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
解决方案
因为config.tfvars
不在父文件夹中:)
find_in_parent_folders
在父文件夹中查找,但不在当前文件夹中。你和你config.tfvars
的在同一个文件夹中terragrunt.hcl
。
尝试使用类似的东西:
optional_var_files = [
"${get_terragrunt_dir()}/config.tfvars",
"${get_terragrunt_dir()}/secrets.auto.tfvars",
]
推荐阅读
- reactjs - 反应:
占用超过 100% 的宽度 - android - 为什么 TRESTRequest Execute 在 android 设备上因超时异常而失败?
- python - Matplotlib 补丁 - 圆似乎是一个椭圆
- scala - 在Scala中使用joinWith时如何仅返回左侧
- python - 如何通过比较熊猫中的两个数据框来拆分输入
- android - Kotlin - Recyclerview 分页中的问题
- c# - 在c#中创建一个可供选择的方法列表并获取它们的参数数量
- c# - c# / Xamarin 相机插件
- python - Python 中的 __del__() 方法有什么用?
- java - Jersey JaxB 类型对象问题的解组