对于这个 terragrunt 目录结构:
project
environment-dev
_common
region
apps
app-a
subenv.hcl
app-b
subenv.hcl
app-c
subenv.hcl
... # other apps can be added in the future
app-x
subenv.hcl
account.hcl
并且在每个
subenv.hcl
文件中(以及其他配置)都有这个片段:
# tags
app_tags = {
"App_tag" = "app-x"
}
我想在
account.hcl
中有一个名为 app_name
的局部变量,其值是手动输入的,但要为此值添加验证,https://developer.hashicorp.com/terraform/language/expressions/custom -条件#输入变量验证。此验证仅允许目录树中每个 app_name
文件的 account.hcl
值中的 App_tag
中的 subenv.hcl
值。
read_terragrunt_config
与“find_in_parent_folders”一起使用,https://terragrunt.gruntwork.io/docs/reference/built-in-functions/#read_terragrunt_config 但“find_in_parent_folders”在目录树中向上搜索而不是向下搜索; account.hcl
文件应该从树下的文件以及目录树下找到的所有文件中获取变量值。
您只能使用静态定义的
include
配置块,这意味着对于每个 app-n
,您必须将 include 添加到您的 account.hcl
。
将
app_name
约束存储在层次结构中更高的位置并在 account.hcl
和 subenv.hcl
s 中引用它会更容易