我正在尝试构建Terragrunt脚本,以便将基础设施部署到Microsoft云。事情进展得相当顺利,但我想不出一件事。
设置的结构如下所示:
rootdir
terragrunt.hcl
someconfig.hcl
module1dir
terragrunt.hcl
config.auto.tfvars.json
module2dir
terragrunt.hcl
config.auto.tfvars.json
module3dir
terragrunt.hcl
config.auto.tfvars.json
每个模块都使用带有config.auto.tfvars.json
的特性进行配置。我想要的是在目录结构之外拥有这些文件,并以某种方式指示Terragrunt应用正确的外部配置文件来更正子模块。
有什么想法吗?
发布于 2020-10-22 15:43:13
我以以下方式解决了这一问题:
定义您计划使用的环境变量,其中应该包含配置文件的位置。确保它没有与任何现存的东西发生冲突。在本例中,我们将使用TGR_CFGDIR。在外部配置模块中,放置模块配置文件并确保它们正确命名。每个文件都应该命名为模块,并以.auto.tfvars.json
结尾。因此,如果您的模块名为foo,则应该有配置文件foo.auto.tfvars.json
。将terragrunt模块(terragrunt.hcl)更改为具有以下语句:
locals {
moduleconfig = get_env("TGR_CFGDIR")
modulename = basename(get_terragrunt_dir())
}
generate "configuration" {
path = "config.auto.tfvars.json"
if_exists = "overwrite"
disable_signature = true
contents = file("${local.moduleconfig}/${local.modulename}.auto.tfvars.json")
}
最后像这样叫terragrunt cli:
TGR_CFGDIR="<configdir>" terragrunt "<somecommand>"
https://stackoverflow.com/questions/64464449
复制相似问题