dag*_*da1 2 terraform terragrunt
I have this terraform.tfvars file in the following location:
root
|_prod
|_eu-west-2
|_dev
|_terraform.tfvars
|_cognito
|_terragrunt.hcl
Run Code Online (Sandbox Code Playgroud)
it has these values:
terragrunt = {
terraform {
extra_arguments "custom_vars" {
commands = [
"apply",
"plan",
"import",
"push",
"refresh"
]
# With the get_tfvars_dir() function, you can use relative paths!
arguments = [
"-var-file=terraform.tfvars"
]
}
}
}
reply_to_email_address = "blah.blah@blah.scot"
Run Code Online (Sandbox Code Playgroud)
I can't find in the docs how to access this. I've tried get_env:
include {
path = find_in_parent_folders()
}
terraform {
// double `//` before module are important!
source = "../../../../../terraform-modules//cognito"
}
inputs = {
name = "pvg-online-${local.env}"
reply_to_email_address = get_env("reply_to_email_address", "")
}
Run Code Online (Sandbox Code Playgroud)
But it gets set to the default ""
这实际上是一个非常常见的用例,因此 terragrunt 具有内置功能。
在您的 中terragrunt.hcl,包含一个terraform{}如下所示的块:
terraform {
# Note that the double-slash (//) syntax is not needed for local relative paths
source = "../../../../../terraform-modules/cognito"
extra_arguments "common_var" {
commands = get_terraform_commands_that_need_vars()
arguments = ["-var-file=${get_terragrunt_dir()}/../terraform.tfvars"]
}
}
inputs = {
name = "pvg-online-${local.env}"
# Since reply_to_email_address is provided in the parent terraform.tfvars file,
# it is not needed as an input
}
Run Code Online (Sandbox Code Playgroud)
请注意使用,get_terraform_commands_that_need_vars()这样您就可以避免列出所有参数,以及get_terragrunt_dir()查找terragrunt.hcl.
| 归档时间: |
|
| 查看次数: |
484 次 |
| 最近记录: |