Terraform-provider-google: Cannot create Google Cloud source repository through terraform

Created on 18 Jan 2018  ·  30Comments  ·  Source: hashicorp/terraform-provider-google

_This issue was originally opened by @lkaranam as hashicorp/terraform#17128. It was migrated here as a result of the provider split. The original body of the issue is below._


I have created a simple repo.tf file to create a source repository in one project. I am the owner of that project. But cannont create source repository in GCLOUD with below terraform code.

Note:
I am able to create source repository by logging in to Google cloud web console. Also I am able to create a source repository with below gcloud command.
gcloud source repos create test-repo

Terraform Version

0.11.2

Steps to reproduce

Below is the repo.tf file code I wrote to create a test repo.
resource "google_sourcerepo_repository" "test_repo" {
name = "test-repo"
project = "${var.project}"
}

Debug Output

I am getting below error when I run 'terraform apply'

2018-01-17T12:19:54.744-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: Cache-Control: private
2018-01-17T12:19:54.744-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: Content-Type: application/json; charset=UTF-8
2018-01-17T12:19:54.744-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: Date: Wed, 17 Jan 2018 20:19:53 GMT
2018-01-17T12:19:54.744-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: Server: ESF
2018-01-17T12:19:54.744-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: Vary: Origin
2018-01-17T12:19:54.744-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: Vary: X-Origin
2018-01-17T12:19:54.744-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: Vary: Referer
2018-01-17T12:19:54.744-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: X-Content-Type-Options: nosniff
2018-01-17T12:19:54.744-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: X-Frame-Options: SAMEORIGIN
2018-01-17T12:19:54.744-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: X-Xss-Protection: 1; mode=block
2018-01-17T12:19:54.744-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe:
2018-01-17T12:19:54.744-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: {
2018-01-17T12:19:54.744-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: "error": {
2018-01-17T12:19:54.744-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: "code": 403,
2018-01-17T12:19:54.744-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: "message": "Cloud Source Repositories API has not been used in project usable-auth-library before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/sourcerepo.googleapis.com/overview?project=usable-auth-library then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.",
2018-01-17T12:19:54.744-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: "errors": [
2018-01-17T12:19:54.744-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: {
2018-01-17T12:19:54.744-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: "message": "Cloud Source Repositories API has not been used in project usable-auth-library before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/sourcerepo.googleapis.com/overview?project=usable-auth-library then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.",
2018-01-17T12:19:54.744-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: "domain": "usageLimits",
2018-01-17T12:19:54.745-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: "reason": "accessNotConfigured",
2018-01-17T12:19:54.745-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: "extendedHelp": "https://console.developers.google.com"
2018-01-17T12:19:54.745-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: }
2018-01-17T12:19:54.745-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: ],
2018-01-17T12:19:54.745-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: "status": "PERMISSION_DENIED"
2018-01-17T12:19:54.745-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: }
2018-01-17T12:19:54.745-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: }
2018-01-17T12:19:54.745-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe:
2018-01-17T12:19:54.745-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: -----------------------------------------------------
2018/01/17 12:19:55 [DEBUG] plugin: waiting for all plugin processes to complete...

Error: Error applying plan:

1 error(2018-01-17T12:19:55.376-0800 [WARN ] plugin: error closing client during Kill: err="unexpected EOF"
s) occurred:

google_sourcerepo_repository.test_repo: Error creating the Source Repo: googleapi: Error 403: Cloud Source Repositories API has not been used in project usable-auth-library before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/sourcerepo.googleapis.com/overview?project=usable-auth-library then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry., accessNotConfigured

Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.

bug upstream

All 30 comments

Hi,

Have you visited https://console.developers.google.com/apis/api/sourcerepo.googleapis.com/overview?project=usable-auth-library to enable the sourcerepo.googleapis.com API?

I tried it. Getting 'Don not have permission' error when I click on the link. Even use with 'organization owner' is getting the same error
image

sourcerepo.googleapis.com is enabled in the project that I am trying to create repo in

I'll take a look.

Okay, I have a strange question ... is billing enabled on your project? Beacuse I get no repro with:

provider "google" {
  credentials = "${file(var.provider-credentials)}"
  zone        = "${var.zone}"
}

provider "random" {}

resource "random_id" "project" {
  byte_length = 8
}

resource "google_project" "project" {
    project_id = "tf-test-${random_id.project.hex}"
    name = "Terraform source repo"
    org_id = "${var.org}"
    billing_account = "${var.billing_account}"
}

resource "google_project_service" "source_repo" {
  project = "${google_project.project.project_id}"
  service = "sourcerepo.googleapis.com"
}

resource "google_sourcerepo_repository" "test_repo" {
    name = "test-repo"
    project = "${google_project.project.project_id}"
    depends_on = ["google_project_service.source_repo"]
}

But... if I remove billing_account = "${var.billing_account}", creating a project which does not have billing, I hit a very strange upstream bug where the project I'm trying to use gets ignored (it's included correctly in the HTTP request Terraform makes, but the response references the default project for the account in question, instead, which does not have sourcerepo.googleapis.com enabled).

Alternately, can you include a few more lines of debug output? I want to see the request that your instance of terraform is making.

Here are the more debug output lines:

2018/01/18 14:04:07 [INFO] command: backend is not enhanced, wrapping in local
2018/01/18 14:04:07 [INFO] backend/local: starting Apply operation
2018/01/18 14:04:07 [INFO] terraform: building graph: GraphTypeInput
2018/01/18 14:04:07 [DEBUG] Resource state not found for "google_sourcerepo_repository.test_repo": google_sourcerepo_repository.test_repo
sformer: "provider.google" references: []
2018/01/18 14:04:07 [TRACE] Graph after step *terraform.ReferenceTransformer:

google_sourcerepo_repository.test_repo - *terraform.NodeAbstractResource
provider.google - *terraform.NodeApplyableProvider
provider.google - *terraform.NodeApplyableProvider
2018/01/18 14:04:07 [TRACE] Graph after step *terraform.CountBoundaryTransformer:

google_sourcerepo_repository.test_repo - *terraform.NodeAbstractResource
provider.google - *terraform.NodeApplyableProvider
meta.count-boundary (count boundary fixup) - *terraform.NodeCountBoundary
google_sourcerepo_repository.test_repo - *terraform.NodeAbstractResource
provider.google - *terraform.NodeApplyableProvider
provider.google - *terraform.NodeApplyableProvider
2018/01/18 14:04:07 [TRACE] Graph after step *terraform.TargetsTransformer:

google_sourcerepo_repository.test_repo - *terraform.NodeAbstractResource
provider.google - *terraform.NodeApplyableProvider
meta.count-boundary (count boundary fixup) - *terraform.NodeCountBoundary
google_sourcerepo_repository.test_repo - *terraform.NodeAbstractResource
provider.google - *terraform.NodeApplyableProvider
provider.google - *terraform.NodeApplyableProvider
2018/01/18 14:04:07 [TRACE] Graph after step *terraform.CloseProviderTransformer:

google_sourcerepo_repository.test_repo - *terraform.NodeAbstractResource
provider.google - *terraform.NodeApplyableProvider
meta.count-boundary (count boundary fixup) - *terraform.NodeCountBoundary
google_sourcerepo_repository.test_repo - *terraform.NodeAbstractResource
provider.google - *terraform.NodeApplyableProvider
provider.google - *terraform.NodeApplyableProvider
provider.google (close) - *terraform.graphNodeCloseProvider
google_sourcerepo_repository.test_repo - *terraform.NodeAbstractResource
provider.google - *terraform.NodeApplyableProvider
2018/01/18 14:04:07 [TRACE] Graph after step *terraform.CloseProvisionerTransformer:

google_sourcerepo_repository.test_repo - *terraform.NodeAbstractResource
provider.google - *terraform.NodeApplyableProvider
meta.count-boundary (count boundary fixup) - *terraform.NodeCountBoundary
google_sourcerepo_repository.test_repo - *terraform.NodeAbstractResource
provider.google - *terraform.NodeApplyableProvider
provider.google - *terraform.NodeApplyableProvider
provider.google (close) - *terraform.graphNodeCloseProvider
google_sourcerepo_repository.test_repo - *terraform.NodeAbstractResource
provider.google - *terraform.NodeApplyableProvider

2018/01/18 14:04:07 [INFO] command: backend is not enhanced, wrapping in local
2018/01/18 14:04:07 [INFO] backend/local: starting Apply operation
2018/01/18 14:04:07 [INFO] terraform: building graph: GraphTypeInput
2018/01/18 14:04:07 [DEBUG] Resource state not found for "google_sourcerepo_repository.test_repo": google_sourcerepo_repository.test_repo
sformer: "provider.google" references: []
2018/01/18 14:04:07 [TRACE] Graph after step *terraform.ReferenceTransformer:

google_sourcerepo_repository.test_repo - *terraform.NodeAbstractResource
provider.google - *terraform.NodeApplyableProvider
provider.google - *terraform.NodeApplyableProvider
2018/01/18 14:04:07 [TRACE] Graph after step *terraform.CountBoundaryTransformer:

google_sourcerepo_repository.test_repo - *terraform.NodeAbstractResource
provider.google - *terraform.NodeApplyableProvider
meta.count-boundary (count boundary fixup) - *terraform.NodeCountBoundary
google_sourcerepo_repository.test_repo - *terraform.NodeAbstractResource
provider.google - *terraform.NodeApplyableProvider
provider.google - *terraform.NodeApplyableProvider
2018/01/18 14:04:07 [TRACE] Graph after step *terraform.TargetsTransformer:

google_sourcerepo_repository.test_repo - *terraform.NodeAbstractResource
provider.google - *terraform.NodeApplyableProvider
meta.count-boundary (count boundary fixup) - *terraform.NodeCountBoundary
google_sourcerepo_repository.test_repo - *terraform.NodeAbstractResource
provider.google - *terraform.NodeApplyableProvider
provider.google - *terraform.NodeApplyableProvider
2018/01/18 14:04:07 [TRACE] Graph after step *terraform.CloseProviderTransformer:

google_sourcerepo_repository.test_repo - *terraform.NodeAbstractResource
provider.google - *terraform.NodeApplyableProvider
meta.count-boundary (count boundary fixup) - *terraform.NodeCountBoundary
google_sourcerepo_repository.test_repo - *terraform.NodeAbstractResource
provider.google - *terraform.NodeApplyableProvider
provider.google - *terraform.NodeApplyableProvider
provider.google (close) - *terraform.graphNodeCloseProvider
google_sourcerepo_repository.test_repo - *terraform.NodeAbstractResource
provider.google - *terraform.NodeApplyableProvider
2018/01/18 14:04:07 [TRACE] Graph after step *terraform.CloseProvisionerTransformer:

google_sourcerepo_repository.test_repo - *terraform.NodeAbstractResource
provider.google - *terraform.NodeApplyableProvider
meta.count-boundary (count boundary fixup) - *terraform.NodeCountBoundary
google_sourcerepo_repository.test_repo - *terraform.NodeAbstractResource
provider.google - *terraform.NodeApplyableProvider
provider.google - *terraform.NodeApplyableProvider
provider.google (close) - *terraform.graphNodeCloseProvider
google_sourcerepo_repository.test_repo - *terraform.NodeAbstractResource
provider.google - *terraform.NodeApplyableProvider

2018/01/18 14:04:07 [INFO] terraform: building graph: GraphTypeValidate
2018/01/18 14:04:07 [DEBUG] Resource state not found for "google_sourcerepo_repository.test_repo": google_sourcerepo_repository.test_repo
2018/01/18 14:04:07 [DEBUG] ReferenceTransformer: "google_sourcerepo_repository.test_repo" references: []
2018/01/18 14:04:07 [DEBUG] ReferenceTransformer: "provider.google" references: []
2018/01/18 14:04:07 [DEBUG] Starting graph walk: walkValidate
2018/01/18 14:04:07 [DEBUG] Resource state not found for "google_sourcerepo_repository.test_repo": google_sourcerepo_repository.test_repo
2018/01/18 14:04:07 [DEBUG] ReferenceTransformer: "google_sourcerepo_repository.test_repo" references: []
2018/01/18 14:04:07 [TRACE] Graph after step *terraform.ReferenceTransformer:

google_sourcerepo_repository.test_repo - *terraform.NodeValidatableResourceInstance
2018/01/18 14:04:07 [TRACE] Graph after step *terraform.RootTransformer:

google_sourcerepo_repository.test_repo - *terraform.NodeValidatableResourceInstance
2018/01/18 14:04:07 [TRACE] dag/walk: added new vertex: "google_sourcerepo_repository.test_repo"
2018/01/18 14:04:07 [TRACE] dag/walk: walking "google_sourcerepo_repository.test_repo"
2018/01/18 14:04:07 [TRACE] vertex 'root.google_sourcerepo_repository.test_repo': walking
2018/01/18 14:04:07 [INFO] backend/local: apply calling Refresh
2018/01/18 14:04:07 [INFO] terraform: building graph: GraphTypeRefresh
2018/01/18 14:04:07 [TRACE] No managed resources in state during refresh, skipping managed resource transformer
2018/01/18 14:04:07 [TRACE] ConfigTransformer: Starting for path: []
nnableResource
provider.google - *terraform.NodeApplyableProvider
meta.count-boundary (count boundary fixup) - *terraform.NodeCountBoundary
google_sourcerepo_repository.test_repo - *terraform.NodePlannableResource
provider.google - *terraform.NodeApplyableProvider
provider.google - *terraform.NodeApplyableProvider
provider.google (close) - *terraform.graphNodeCloseProvider
google_sourcerepo_repository.test_repo - *terraform.NodePlannableResource
provider.google - *terraform.NodeApplyableProvider
root - terraform.graphNodeRoot
meta.count-boundary (count boundary fixup) - *terraform.NodeCountBoundary
provider.google (close) - *terraform.graphNodeCloseProvider
2018/01/18 14:04:07 [DEBUG] Starting graph walk: walkPlan
2018/01/18 14:04:07 [TRACE] dag/walk: added new vertex: "provider.google (close)"
2018/01/18 14:04:07 [TRACE] dag/walk: added new vertex: "root"
2018/01/18 14:04:07 [TRACE] dag/walk: added new vertex: "google_sourcerepo_repository.test_repo"
2018-01-18T14:04:07.364-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: 2018/01/18 14:04:07 [INFO] Authenticating using DefaultClient
2018-01-18T14:04:07.364-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: 2018/01/18 14:04:07 [INFO] Instantiating GCE client...
2018-01-18T14:04:07.364-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: 2018/01/18 14:04:07 [INFO] Instantiating GCE Beta client...
2018-01-18T14:04:07.364-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: 2018/01/18 14:04:07 [INFO] Instantiating GKE client...
2018-01-18T14:04:07.364-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: 2018/01/18 14:04:07 [INFO] Instantiating Google Cloud DNS client...
2018-01-18T14:04:07.364-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: 2018/01/18 14:04:07 [INFO] Instantiating Google Cloud KMS Client...
2018-01-18T14:04:07.364-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: 2018/01/18 14:04:07 [INFO] Instantiating Google Stackdriver Logging client...
2018-01-18T14:04:07.364-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: 2018/01/18 14:04:07 [INFO] Instantiating Google Storage Client...
2018-01-18T14:04:07.364-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: 2018/01/18 14:04:07 [INFO] Instantiating Google SqlAdmin Client...
2018-01-18T14:04:07.364-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: 2018/01/18 14:04:07 [INFO] Instantiating Google Pubsub Client...
2018-01-18T14:04:07.364-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: 2018/01/18 14:04:07 [INFO] Instantiating Google Cloud ResourceManager Client...
2018-01-18T14:04:07.364-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: 2018/01/18 14:04:07 [INFO] Instantiating Google Cloud ResourceManager V Client...
2018-01-18T14:04:07.364-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: 2018/01/18 14:04:07 [INFO] Instantiating Google Cloud Runtimeconfig Client...
2018-01-18T14:04:07.364-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: 2018/01/18 14:04:07 [INFO] Instantiating Google Cloud IAM Client...
2018-01-18T14:04:07.364-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: 2018/01/18 14:04:07 [INFO] Instantiating Google Cloud Service Management Client...
2018-01-18T14:04:07.364-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: 2018/01/18 14:04:07 [INFO] Instantiating Google Cloud Billing Client...
2018-01-18T14:04:07.364-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: 2018/01/18 14:04:07 [INFO] Instantiating Google Cloud BigQuery Client...
2018-01-18T14:04:07.364-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: 2018/01/18 14:04:07 [INFO] Instantiating Google Cloud Source Repo Client...
2018-01-18T14:04:07.364-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: 2018/01/18 14:04:07 [INFO] Instantiating Google Cloud Spanner Client...
2018-01-18T14:04:07.364-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: 2018/01/18 14:04:07 [INFO] Instantiating Google Cloud Dataproc Client...
2018/01/18 14:04:07 [DEBUG] Resource state not found for "google_sourcerepo_repository.test_repo": google_sourcerepo_repository.test_repo
2018/01/18 14:04:07 [INFO] terraform: building graph: GraphTypeApply
2018/01/18 14:04:07 [DEBUG] Resource state not found for "google_sourcerepo_repository.test_repo": google_sourcerepo_repository.test_repo
2018/01/18 14:04:07 [DEBUG] ReferenceTransformer: "google_sourcerepo_repository.test_repo" references: []
2018/01/18 14:04:07 [DEBUG] ReferenceTransformer: "provider.google" references: []
2018/01/18 14:04:07 [TRACE] Graph after step *terraform.ReferenceTransformer:

google_sourcerepo_repository.test_repo - *terraform.NodeApplyableResource
provider.google - *terraform.NodeApplyableProvider
provider.google - *terraform.NodeApplyableProvider
2018/01/18 14:04:07 [DEBUG] Starting graph walk: walkApply
2018-01-18T14:04:07.413-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: 2018/01/18 14:04:07 [INFO] Authenticating using DefaultClient
2018-01-18T14:04:07.414-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: 2018/01/18 14:04:07 [INFO] Instantiating GCE client...
2018-01-18T14:04:07.414-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: 2018/01/18 14:04:07 [INFO] Instantiating GCE Beta client...
2018-01-18T14:04:07.414-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: 2018/01/18 14:04:07 [INFO] Instantiating GKE client...
2018-01-18T14:04:07.414-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: 2018/01/18 14:04:07 [INFO] Instantiating Google Cloud DNS client...
2018-01-18T14:04:07.414-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: 2018/01/18 14:04:07 [INFO] Instantiating Google Cloud KMS Client...
2018-01-18T14:04:07.414-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: 2018/01/18 14:04:07 [INFO] Instantiating Google Stackdriver Logging client...
2018-01-18T14:04:07.414-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: 2018/01/18 14:04:07 [INFO] Instantiating Google Storage Client...
2018-01-18T14:04:07.414-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: 2018/01/18 14:04:07 [INFO] Instantiating Google SqlAdmin Client...
2018-01-18T14:04:07.414-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: 2018/01/18 14:04:07 [INFO] Instantiating Google Pubsub Client...
2018-01-18T14:04:07.414-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: 2018/01/18 14:04:07 [INFO] Instantiating Google Cloud ResourceManager Client...
2018-01-18T14:04:07.414-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: 2018/01/18 14:04:07 [INFO] Instantiating Google Cloud ResourceManager V Client...
2018-01-18T14:04:07.414-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: 2018/01/18 14:04:07 [INFO] Instantiating Google Cloud Runtimeconfig Client...
2018-01-18T14:04:07.414-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: 2018/01/18 14:04:07 [INFO] Instantiating Google Cloud IAM Client...
2018-01-18T14:04:07.414-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: 2018/01/18 14:04:07 [INFO] Instantiating Google Cloud Service Management Client...
2018-01-18T14:04:07.414-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: 2018/01/18 14:04:07 [INFO] Instantiating Google Cloud Billing Client...
2018-01-18T14:04:07.414-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: 2018/01/18 14:04:07 [INFO] Instantiating Google Cloud BigQuery Client...
2018-01-18T14:04:07.414-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: 2018/01/18 14:04:07 [INFO] Instantiating Google Cloud Source Repo Client...
2018-01-18T14:04:07.414-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: 2018/01/18 14:04:07 [INFO] Instantiating Google Cloud Spanner Client...
2018-01-18T14:04:07.414-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: 2018/01/18 14:04:07 [INFO] Instantiating Google Cloud Dataproc Client...
2018/01/18 14:04:07 [TRACE] [walkApply] Exiting eval tree: provider.google
2018/01/18 14:04:07 [TRACE] dag/walk: walking "google_sourcerepo_repository.test_repo"
2018/01/18 14:04:07 [TRACE] vertex 'root.google_sourcerepo_repository.test_repo': walking
2018/01/18 14:04:07 [DEBUG] apply: google_sourcerepo_repository.test_repo: executing Apply
google_sourcerepo_r2018-01-18T14:04:07.431-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: 2018/01/18 14:04:07 [DEBUG] Google API Request Details:
e2018-01-18T14:04:07.431-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: ---[ REQUEST ]---------------------------------------
2018-01-18T14:04:07.431-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: POST /v1/projects/info4-research/repos?alt=json HTTP/1.1
2018-01-18T14:04:07.431-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: Host: sourcerepo.googleapis.com
2018-01-18T14:04:07.431-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: User-Agent: google-api-go-client/0.5 (windows amd64) Terraform/0.10.1
2018-01-18T14:04:07.431-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: Content-Length: 51
p2018-01-18T14:04:07.431-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: Content-Type: application/json
2018-01-18T14:04:07.432-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: Accept-Encoding: gzip
2018-01-18T14:04:07.432-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe:
2018-01-18T14:04:07.432-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe:
2018-01-18T14:04:07.432-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: -----------------------------------------------------
ository.test_repo: Creating...
name: "" => "test-repo"
project: "" => "info4-research"
size: "" => ""
2018-01-18T14:04:08.060-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: 2018/01/18 14:04:08 [DEBUG] Google API Response Details:
2018-01-18T14:04:08.060-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: ---[ RESPONSE ]--------------------------------------
2018-01-18T14:04:08.060-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: HTTP/2.0 403 Forbidden
2018-01-18T14:04:08.060-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: Alt-Svc: hq=":443"; ma=2592000; quic=51303431; quic=51303339; quic=51303338; quic=51303337; quic=51303335,quic=":443"; ma=2592000; v="41,39,38,37,35"
2018-01-18T14:04:08.060-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: Cache-Control: private
2018-01-18T14:04:08.060-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: Content-Type: application/json; charset=UTF-8
2018-01-18T14:04:08.060-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: Date: Thu, 18 Jan 2018 22:04:06 GMT
2018-01-18T14:04:08.060-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: Server: ESF
2018-01-18T14:04:08.060-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: Vary: Origin
2018-01-18T14:04:08.060-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: Vary: X-Origin
2018-01-18T14:04:08.060-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: Vary: Referer
2018-01-18T14:04:08.060-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: X-Content-Type-Options: nosniff
2018-01-18T14:04:08.060-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: X-Frame-Options: SAMEORIGIN
2018-01-18T14:04:08.060-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: X-Xss-Protection: 1; mode=block
2018-01-18T14:04:08.060-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe:
2018-01-18T14:04:08.060-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: {
2018-01-18T14:04:08.060-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: "error": {
2018-01-18T14:04:08.060-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: "code": 403,
2018-01-18T14:04:08.060-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: "message": "Cloud Source Repositories API has not been used in project usable-auth-library before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/sourcerepo.googleapis.com/overview?project=usable-auth-library then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.",
2018-01-18T14:04:08.060-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: "errors": [
2018-01-18T14:04:08.060-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: {
2018-01-18T14:04:08.060-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: "message": "Cloud Source Repositories API has not been used in project usable-auth-library before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/sourcerepo.googleapis.com/overview?project=usable-auth-library then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.",
2018-01-18T14:04:08.060-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: "domain": "usageLimits",
2018-01-18T14:04:08.060-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: "reason": "accessNotConfigured",
2018-01-18T14:04:08.060-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: "extendedHelp": "https://console.developers.google.com"
2018-01-18T14:04:08.060-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: }
2018-01-18T14:04:08.060-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: ],
2018-01-18T14:04:08.060-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: "status": "PERMISSION_DENIED"
2018-01-18T14:04:08.060-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: }
2018-01-18T14:04:08.060-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: }
2018-01-18T14:04:08.060-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe:
2018-01-18T14:04:08.060-0800 [DEBUG] plugin.terraform-provider-google_v1.4.0_x4.exe: -----------------------------------------------------
2018/01/18 14:04:08 [TRACE] root: eval: *terraform.EvalWriteState
2018/01/18 14:04:08 [TRACE] root: eval: *terraform.EvalApplyProvisioners
2018/01/18 14:04:08 [TRACE] root: eval: *terraform.EvalIf
2018/01/18 14:04:08 [TRACE] root: eval: *terraform.EvalWriteState
2018/01/18 14:04:08 [TRACE] root: eval: *terraform.EvalWriteDiff
2018/01/18 14:04:08 [TRACE] root: eval: *terraform.EvalApplyPost
2018/01/18 14:04:08 [ERROR] root: eval: *terraform.EvalApplyPost, err: 1 error(s) occurred:

  • google_sourcerepo_repository.test_repo: Error creating the Source Repo: googleapi: Error 403: Cloud Source Repositories API has not been used in project usable-auth-library before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/sourcerepo.googleapis.com/overview?project=usable-auth-library then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry., accessNotConfigured
    2018/01/18 14:04:08 [ERROR] root: eval: *terraform.EvalSequence, err: 1 error(s) occurred:

  • google_sourcerepo_repository.test_repo: Error creating the Source Repo: googleapi: Error 403: Cloud Source Repositories API has not been used in project usable-auth-library before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/sourcerepo.googleapis.com/overview?project=usable-auth-library then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry., accessNotConfigured
    2018/01/18 14:04:08 [TRACE] [walkApply] Exiting eval tree: google_sourcerepo_repository.test_repo
    2018/01/18 14:04:08 [TRACE] dag/walk: upstream errored, not walking "meta.count-boundary (count boundary fixup)"
    2018/01/18 14:04:08 [TRACE] dag/walk: upstream errored, not walking "provider.google (cl

Unfortunately that doesn't include the request I'm looking for. Can you maybe upload the entire output as a gist?

Ah, there it is.

Yep, that's the bug. Please confirm that the project info4-research has billing set up and the right permissions.

Yes, Billing is enabled on the project, source repo API is enabled. I am able to create repo using gcloud command in same project

I've reported this issue internally to Google - I'm tagging this "upstream" and will report back when the issue is closed.

Just chiming in here that I'm experiencing the same issue. It's very strange, since I don't specify the project usable-auth-library anywhere, nor do I have ownership of that project.

For anyone else who runs into this, here is a temporary workaround:

resource "google_project_service" "source-api" {
    project = "${google_project.my-project.project_id}"
    service = "sourcerepo.googleapis.com"

    provisioner "local-exec" {
        command = "gcloud source repos create --project=${google_project.my-project.project_id} my-source-repo"
    }
}

@ndmckinley any update on this bug from upstream? I've reproduced the bug with the latest google.golang.org/api/sourcerepo/v1 pkg (ee8cc1fe56761368e66676bb8262437bb035d116).

package main
import (
    "fmt"
    "golang.org/x/net/context"
    "golang.org/x/oauth2/google"
    "google.golang.org/api/sourcerepo/v1"
)
const (
    project = "my-project" # my active project with billing enabled
    repo    = "my-repo"
)
func main() {
    ctx := context.Background()
    client, err := google.DefaultClient(ctx, "https://www.googleapis.com/auth/cloud-platform")
    if err != nil {
        panic(err)
    }
    clientSourceRepo, err := sourcerepo.New(client)
    if err != nil {
        panic(err)
    }
    // path parameter project required to be in the form projects/*
    // https://cloud.google.com/source-repositories/docs/reference/rest/v1/projects.repos/create
    p := "projects/" + project
    // Resource name of the repository, of the form projects/<project>/repos/<repo>
    // https://cloud.google.com/source-repositories/docs/reference/rest/v1/projects.repos#Repo
    r := &sourcerepo.Repo{
        Name: "projects/" + project + "/repos/" + repo,
    }
    op, err := clientSourceRepo.Projects.Repos.Create(p, r).Do()
    if err != nil {
        panic(err)
    }
    fmt.Printf("success %s", op.Name)
}

generates a POST of

POST /v1/projects/my-project/repos?alt=json HTTP/1.1
Host: sourcerepo.googleapis.com
Content-Type: application/json
User-Agent: google-api-go-client/0.5

{"name":"projects/my-project/repos/my-repo"}

and errors out with

googleapi: Error 403: Cloud Source Repositories API has not been used in project 
764086051850 before or it is disabled. Enable it by visiting 
https://console.developers.google.com/apis/api/sourcerepo.googleapis.com/overview?project=764086051850 
then retry. If you enabled this API recently, wait a few minutes for the action to 
propagate to our systems and retry., accessNotConfigured

where 764086051850 is not the project number for my project, but replacing 764086051850 with the actual project number in the error url shows the Source Repositoies API is already enabled.

I do not have an update, but I have got a suspicion, based on my own struggles with this bug so far. :) Is 764086051850 the project number of the service account you're calling the API with?

764086051850 is not a project number for any project in my org

Well, that's very interesting. I've re-escalated the internal issue.

New question: are you using gcloud auth application-default login?

Yes, and my account shows as active under gcloud auth list

Gotcha. It's a bug on the Source Repos side, which is triggered by application default credentials. A workaround, until they fix it, will be to create a service account and use that instead. It's probably a good idea to do that, since I don't have a timeline for a fix yet, and I know this affects a few more resources than just Source Repos.

Oh, interesting. Thanks, @ndmckinley I'll give that a shot.

@ndmckinley I am also facing the same issue. Even I get the same project number (764086051850) in the error which @mathyourlife-fitbit is getting. And i do not have any project in the Org with this project number. Below is the error:

Error creating the Source Repo: googleapi: Error 403: Cloud Source Repositories API has not been used in project 764086051850 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/sourcerepo.googleapis.com/overview?project=764086051850 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry., accessNotConfigured

Are you also using gcloud auth application-default login?

No. I also used Terraform resource to create a source repository. API is enabled and I am able to create a repo from cloud console. I get the error when I run terraform script to provision repo.

This is surprising. Today again I ran my Terraform script to create a source_repo, in a VM. It worked fine. I did not touch the code or tried anything else to fix it, I just SSHed to the VM again and ran the script, it worked. I am able to create a source_repo without any issue.

Can you describe your authentication setup? The error that you are getting is the known issue related to using gcloud auth application-default login. When you run your script to create a source repo in a VM, you're authenticating using the service account, which does not have this issue.

Confirmed, works now for me too. I believe the API was enabled for that internal google project.

Ah, I see that the upstream fix was merged! That's great. I suppose based on your experience that it has been deployed, as well. I'll close this tracking issue.

I'm going to lock this issue because it has been closed for _30 days_ ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

Was this page helpful?
0 / 5 - 0 ratings