【发布时间】:2019-03-26 14:46:55
【问题描述】:
在几个月没有处理基础架构更改之后,我尝试在一台新机器上加载我们的 terragrunt 文件并遇到了几个错误,我找不到解决方案。
基本上,当存在-var 或-var-file 选项时,似乎terraform.tfvars 文件(或任何*.auto.tfvars 文件)会被terraform 忽略。
我们使用分层 terragrunt 配置为不同的环境提供不同的凭据配置,这就是为什么有一个包含所有数据的 account.tfvars 文件。
直到今年 8 月,一切都正常运行,所以也许有一个我在更新日志中没有发现的变化?
模块特定terraform.tfvars:
terragrunt = {
include {
path = "${find_in_parent_folders()}"
}
terraform {
source = "../../../modules//cockpit"
}
}
bucket_prefix = "cockpit-"
domain_name = "cockpit.donutapp.io"
父terraform.tfvars:
terragrunt = {
remote_state {
backend = "s3"
config {
encrypt = true
bucket = "my-${get_aws_account_id()}-tfstate"
key = "production/${path_relative_to_include()}/terraform.tfstate"
region = "us-east-1"
dynamodb_table = "terraform-locks"
}
}
terraform {
extra_arguments "bucket" {
commands = ["${get_terraform_commands_that_need_vars()}"]
optional_var_files = [
"${get_tfvars_dir()}/${find_in_parent_folders("account.tfvars", "ignore")}",
]
arguments = [
"-var",
"terraform_bucket=my-${get_aws_account_id()}-tfstate",
]
}
extra_arguments "disable_input" {
commands = ["${get_terraform_commands_that_need_input()}"]
arguments = ["-input=false"]
}
}
}
terragrunt 执行的命令:
terraform plan -var terraform_bucket=my-accountid-tfstate \
-var-file=some-path/../account.tfvars \
-input=false
当我将-var-file=terraform.tfvars 作为参数添加到.terragrunt-cache 文件夹中的terraform plan 命令时,它确实有效,所以它不会自动加载。
有什么想法吗?
【问题讨论】:
-
我在这里遇到了同样的问题,Terraform 文档似乎没有详细说明如何加载变量或赋予它们什么优先级。在我的情况下,将
-var-file参数添加到计划命令是一种可行的解决方法,但可能不适用于所有人。 -
我不得不将 terraform.tfvars 重命名为 prod.auto.tfvars,然后它就起作用了。 terraform.tfvars 和 *.auto.tfvars 都应该工作没有意义。
标签: terraform terragrunt