(Terraform) Error 403: Cloud Run Admin API has not been used in project 905986752003 before or it is disabled. Enable it by visiting https://console.d

Viewed 628

On GCP, I applied this Terraform code below to run the Cloud Run service "renderer":

resource "google_cloud_run_service" "renderer" {
  name     = "renderer"
  location = "asia-northeast1"

  template {
    spec {
      containers {
        image = "gcr.io/${var.project_id}/renderer:latest"
      }
    }
  }
}

But I got this error:

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

So, I went to the url https://console.developers.google.com/apis/api/run.googleapis.com/overview?project=905986752003 shown in this error above:

enter image description here

Then, enabled Cloud Run API:

enter image description here

Then, applied this Terraform code again:

resource "google_cloud_run_service" "renderer" {
  name     = "renderer"
  location = "asia-northeast1"

  template {
    spec {
      containers {
        image = "gcr.io/${var.project_id}/renderer:latest"
      }
    }
  }
}

Finally, I could run the Cloud Run service "renderer":

enter image description here

Now, I want to enable Cloud Run API with Terraform code:

enter image description here

Is it possible to enable Cloud Run API with Terraform code and if it's possible, how do I enable Cloud Run API with Terraform code?

1 Answers

Yes, it's possible to enable Cloud Run API with Terraform code. So, you need to add this Terraform code:

resource "google_project_service" "cloud_run_api" {
  service = "run.googleapis.com"
}

Then, you also need to add "depends_on" block with "google_project_service.cloud_run_api" to wait for Cloud Run API to be enabled:

resource "google_cloud_run_service" "renderer" {
  name     = "renderer"
  location = "asia-northeast1"

  template {
    spec {
      containers {
        image = "gcr.io/${var.project_id}/renderer:latest"
      }
    }
  }
  depends_on = [ // Here
    google_project_service.cloud_run_api
  ]
}

Otherwise, you will get the same error:

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

This is the full Terrafrom code:

resource "google_project_service" "cloud_run_api" {
  service = "run.googleapis.com"
}

resource "google_cloud_run_service" "renderer" {
  name     = "renderer"
  location = "asia-northeast1"

  template {
    spec {
      containers {
        image = "gcr.io/${var.project_id}/renderer:latest"
      }
    }
  }
  depends_on = [
    google_project_service.cloud_run_api
  ]
}

In addition, you can find the Service name "run.googleapis.com" in the page redirected to after you enable Cloud Run API:

resource "google_project_service" "cloud_run_api" {
  service = "run.googleapis.com" // Service name
}

So, after you enable Cloud Run API:

enter image description here

You are redirected to this page:

enter image description here

Then, you can find the Service name "run.googleapis.com" in Details section:

enter image description here

Related