【发布时间】:2019-03-03 11:35:00
【问题描述】:
使用带有 git 分支的 Terraform 模块作为源,
我指的是:
git::ssh://private_server:myport/kbf/my_repository.git//ecs-cluster?ref=v0.0.1
在我的模块源参数中,这很好用,并在 master 上的标签 v0.0.1 处为我提供了我的模块。
但是我想指定一个分支,而不是一个标签,但不知道该怎么做。
【问题讨论】:
使用带有 git 分支的 Terraform 模块作为源,
我指的是:
git::ssh://private_server:myport/kbf/my_repository.git//ecs-cluster?ref=v0.0.1
在我的模块源参数中,这很好用,并在 master 上的标签 v0.0.1 处为我提供了我的模块。
但是我想指定一个分支,而不是一个标签,但不知道该怎么做。
【问题讨论】:
正如 Terraform 文档中提到的 here:
git::ssh://private_server:myport/kbf/my_repository.git//ecs-cluster?ref=myBranch
【讨论】:
完全一样。你在那里有一个通用的 ref,假设没有冲突,Git 会计算出你所说的上下文的意思。
如果您确实有 2 个不明确的 ref,那么 Git 会出错并告诉您这是一个不明确的 ref,并强制您使用 refs/heads/branch-name 或 refs/tags/tag-name 指定完整的 ref。
【讨论】:
你可以这样使用:
module "test_module" {
source = "git::ssh://bitbucketURL/my_repo.git.git?ref=BranchName"
}
bitbucketURL:转到bitbucket UI,检查clone URL,从中复制。
如果您使用的不是 bitbucket,请参考: https://www.terraform.io/docs/modules/sources.html
【讨论】:
ref 参数的值可以是 git checkout 命令可以接受的任何引用,包括分支和标签名称。
使用 git 标签和分支使用模块的示例代码。 reference_link
用简单的语言:在 ref= 之后根据需要添加标签或分支。
module "vpc" {
source = "git::https://example.com/vpc.git?ref=v1.2.0"
}
module "vpc" {
source = "git::https://example.com/vpc.git?ref=develop"
}
【讨论】:
我知道这个问题是关于私人服务器回购的,但如果有人正在寻找不带前缀的 github.com 网址,这可行:
module "foo" {
source = "github.com/org/repo//path/to/module?ref=branch-name"
}
【讨论】:
就像之前提到的在你的 terraform 模块中引用一个分支。您需要做的就是在 ref= .. 之后提及分支名称,而不是提及标签。
所以.. 而不是
module "vpc" {
source = "git::https://example.com/vpc.git?ref=v1.2.0"
}
这是您用来引用该存储库中的标签的...使用下面的一个
module "vpc" {
source = "git::https://example.com/vpc.git?ref=YourBranchName"
}
希望它是明确的并且是有道理的。
【讨论】: