如何避免多次设置模块源?

问题描述 投票:0回答:1

我的存储库多次使用来自不同存储库的 Glue 模块。每次使用都开始于:

module "bar" {
  source = "git::[email protected]:foo/modules.git//app?ref=v0.0.3"

我有一大堆这样的积木,而且都使用相同的

source
。复制路径似乎并不干,而且当我不得不颠簸
ref
时真的很烦人。所以我想我可以只使用变量:

locals {
  module_source = "git::[email protected]:foo/modules.git//app?ref=v0.0.3"
}

module "bar" {
  source = locals.module_source

但是 Terraform 不喜欢那样,给了我

Variables may not be used here.

有解决办法吗?

refactoring dry terraform-modules
1个回答
0
投票

不确定我是否理解正确但我认为你可以使用输出值

根据文档,它说:

子模块可以使用输出将其资源属性的子集公开给父模块。

我认为这就是你想要的,所以你可以尝试这样的事情:

output "module_source" {
  value = "git::[email protected]:foo/modules.git//app?ref=v0.0.3"
}

然后使用它:

module "bar" {
  source = module.your_module.module_source
}
© www.soinside.com 2019 - 2024. All rights reserved.