【发布时间】:2019-10-19 17:40:33
【问题描述】:
我需要在 GITHUB 中为很多存储库创建 CI/CD 管道 并保护一些特定的分支。但如果远程分支不存在,我会收到错误消息。
仅当我已经在 GITHUB 中创建了远程分支时它才有效。但我需要通过 Terraform 或自动化方式来完成这一切。
# Configure the GitHub Provider
provider "github" {
token = "${var.github_token}"
organization = "${var.github_organization}"
}
# Protect the CI/CD branch of the foo repository
resource "github_branch_protection" "foo" {
repository = "foo"
branch = "staging"
enforce_admins = true
required_pull_request_reviews {
required_approving_review_count = 2
}
}
带有 GITHUB 远程分支的 Terraform 结果:
github_branch_protection.foo: Creating...
github_branch_protection.foo: Creation complete after 3s [id=foo:staging]
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
(实际错误)没有 GITHUB 远程分支的 Terraform 结果:
Error: PUT https://api.github.com/repos/jetprogramming/foo/branches/staging/protection: 404 Branch not found []
【问题讨论】:
标签: github terraform terraform-provider-github