gpt4 book ai didi

github - Terraform - 将变量传递给 "Source"参数

转载 作者:行者123 更新时间:2023-12-03 19:50:42 29 4
gpt4 key购买 nike

我以模块化方式使用 Terraform 来构建我的基础架构。我通过拥有一个调用不同模块的配置文件来做到这一点。我想传递一个基础结构变量,该变量获取应用程序应该构建的 Github 存储库的标记版本。最重要的是,我试图弄清楚如何在配置文件的“源”变量中连接字符串。

module "athenaelb" {

source = "${concat("git::https://github.com/ORG/REPONAME.git?ref=",var.infra_version)}"

aws_access_key = "${var.aws_access_key}"

aws_secret_key = "${var.aws_secret_key}"

aws_region = "${var.aws_region}"

availability_zones = "${var.availability_zones}"

subnet_id = "${var.subnet_id}"

security_group = "${var.athenaelb_security_group}"

branch_name = "${var.branch_name}"

env = "${var.env}"

sns_topic = "${var.sns_topic}"

s3_bucket = "${var.elb_s3_bucket}"

athena_elb_sns_topic = "${var.athena_elb_sns_topic}"

infra_version = "${var.infra_version}"

}

我希望它编译并且源代码看起来像这样(例如): git:: https://github.com/ORG/REPONAME.git?ref=v1

有人对如何使这项工作有任何想法吗?

谢谢,
可人

最佳答案

目前这在 Terraform 本身中是不可能的。

实现这样的事情的唯一方法是使用单独的脚本与 git 存储库交互,Terraform 克隆到 .terraform/modules 的子目录中。目录并根据您需要的版本将其切换到不同的标签。这是不理想的,因为 Terraform 根据模块路径的哈希将它们组织到目录中,但是如果您可以识别有问题的模块,则运行 git checkout 是安全的。只要您不运行 terraform get 在这些存储库中之后再次。

有关此问题的更多详细信息和讨论,请参阅 issue #1439 in Terraform's issue tracker ,请求此功能的地方。

关于github - Terraform - 将变量传递给 "Source"参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37279720/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com