Bitbucket 使用 terraform 进行源回购镜像

Bitbucket to source repo mirroring using terraform

我正在尝试自动创建项目和资源,同时使用 Terraform 自动触发云构建。要使用云构建触发器,我必须将位桶存储库镜像到 GCP 的源存储库中。

我正在使用以下创建源项目 https://www.terraform.io/docs/providers/google/r/cloudbuild_trigger.html,但是没有设置镜像的选项。

在挖掘 GCP (https://cloud.google.com/source-repositories/docs/reference/rest/v1/projects.repos/create) 的 API 后,我可以看到一个 mirrorConfig 选项,但文档说它处于只读模式。当我为 API 设置 mirrorConfig 时,出现以下错误。

{
  "error": {
    "code": 400,
    "message": "Request contains an invalid argument.",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.BadRequest",
        "fieldViolations": [
          {
            "field": "repo.mirror_config",
            "description": "mirror_config is a read-only field and must not be set"
          }
        ]
      }

有没有一种方法可以使用 terraform 自动从位桶到 GCP 中的源存储库进行回购镜像?如果没有,是否有替代方法 way/tool 来实现此目的?

如您所述(以及 documentation 中所述)“mirrorConfig”字段当前设置为只读,因此无法手动为其设置任何值。随后,您收到了上述错误以及相应的消息描述。

设置镜像需要额外的信息,因为 Cloud Source Repositories 需要 Bitbucket 的授权,SourceRepo 中没有公开的操作 API。

“mirrorConfig”在创建时是只读的,因为在使用 Cloud Console 时,需要用户从同一浏览器会话登录到 Cloud 和 Bitbucket 站点才能提供此额外的必需信息。然而,API 没有处理这个的能力。

目前似乎无法通过 API 镜像存储库。要自动创建镜像存储库,除了使用 UI 之外没有其他解决方法,因此您必须通过 Cloud Console 连接到外部源,如 Mirroring a Bitbucket repository 文档中所述。

然而,在我的调查过程中,我遇到了关于此的 Public Issue,但指的是 GitHub。您可以在这个 Public 问题上添加评论,以包括 Bitbucket 的功能以及“星标”它以便它获得更多可见度,这样您就可以收到关于它的进一步更新。

希望这些信息对您有所帮助。