简体   繁体   中英

(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

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:

在此处输入图像描述

Then, enabled Cloud Run API :

在此处输入图像描述

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" :

在此处输入图像描述

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

在此处输入图像描述

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?

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 :

在此处输入图像描述

You are redirected to this page:

在此处输入图像描述

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

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM