使用git分支作为源的Terraform模块

kry*_*our 3 git terraform

如果我指的是

git::ssh://private_server:myport/kbf/my_repository.git//ecs-cluster?ref=v0.0.1
Run Code Online (Sandbox Code Playgroud)

在我的模块源参数中,这很好用,并为我提供了主模块上标记为v0.0.1的模块

但是我想指定一个分支而不是一个标签,但不确定如何做到这一点。

小智 14

你可以使用这样的东西:

module "test_module" {
  source = "git::ssh://bitbucketURL/my_repo.git?ref=BranchName"
}
Run Code Online (Sandbox Code Playgroud)

bitbucketURL:转到bitbucket UI,检查clone URL并从中复制。

如果您使用的是 bitbucket 以外的其他东西,请参阅: https://www.terraform.io/docs/modules/sources.html


小智 12

ref 参数的值可以是 git checkout 命令接受的任何引用,包括分支和标记名称。

使用 git 标签和分支使用模块的示例代码。参考链接

用简单的语言来说:在 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"
}
Run Code Online (Sandbox Code Playgroud)


rah*_*311 6

完成答案后,带有分支的源链接为

git::ssh://private_server:myport/kbf/my_repository.git//ecs-cluster?ref=myBranch
Run Code Online (Sandbox Code Playgroud)

  • 是否可以指定提交 ID 和分支名称? (2认同)
  • 根据链接的文档,完整的提交 ID 似乎也有效:`source = "git::https://example.com/storage.git?ref=51d462976d84fdea54b47d80dcabbf680badcdb8"` (2认同)

yda*_*coR 5

完全一样。那里有一个通用的引用,假设Git会假设上下文没有冲突,那么您可以理解上下文的含义。

如果确实有2个引用不明确,则Git会出错并告诉您这是一个不明确的引用,并强制您使用refs/heads/branch-name或指定完整引用refs/tags/tag-name


iam*_*gga 5

我知道这个问题是关于私有服务器存储库,但如果有人正在寻找无前缀的github.com网址,这有效:

module "foo" {
  source = "github.com/org/repo//path/to/module?ref=branch-name"
}
Run Code Online (Sandbox Code Playgroud)