0
votes

I am trying to automate the project & resources creation, along with automating the triggers for cloud build using terraform. To use cloud build triggers I will have to mirror the bit-bucket repo into source repo of GCP.

I am using the below to create a source project https://www.terraform.io/docs/providers/google/r/cloudbuild_trigger.html, but there is no option to set mirror.

Upon digging the APIs of GCP (https://cloud.google.com/source-repositories/docs/reference/rest/v1/projects.repos/create), I can see a mirrorConfig option but the docs says it is in read-only mode. When I set the mirrorConfig for the API I get the below error.

{
  "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"
          }
        ]
      }

Is there a way to automate repo mirroring from bit-bucket to source repository in GCP using terraform? If not is there any alternate way/tool for achieving this?

1
Can someone please help me with this issue?Naveen Kulkarni

1 Answers

2
votes

As you mentioned (and as stated in the documentation) the “mirrorConfig” field is currently set to read-only, so it is not possible to set any values for it manually. Subsequently, you received the aforementioned error with the corresponding message description.

Setting up the mirror requires additional information, since Cloud Source Repositories needs authorization from Bitbucket, an action which is not exposed in the SourceRepo API.

“mirrorConfig” is a read-only at creation because this additional required information, when using the Cloud Console, is provided by relying on the user to login to both Cloud and Bitbucket sites from the same browser session. However, the API doesn't have capabilities to handle this.

It seems that currently it is not possible to mirror the repository via the API. To automate the creation of a mirrored repository there is no workaround other than using the UI, hence you will have to connect to the external sources through the Cloud Console, like explained in the Mirroring a Bitbucket repository documentation.

However, during my investigation I came across a Public Issue regarding this, but referring to GitHub. You may add comments on this Public Issue, to include the Feature for Bitbucket as well and also “star” it so that it receives more visibility and so that you may receive further updates on it.

I hope this information helps.