terraform/gcp - how to enable iam.googleapis.com with TF

Viewed 457

Please help understand how to enable GCP IAM API using Terraform.

Environment

$ terraform --version
Terraform v1.0.4
on linux_amd64
+ provider registry.terraform.io/hashicorp/google v4.6.0
+ provider registry.terraform.io/hashicorp/time v0.7.2

Resource

resource "google_project_service" "iam" {
  project = data.google_project.project.project_id
  service = "iam.googleapis.com"
  timeouts {
    create = "20m"
    update = "20m"
  }
  disable_dependent_services = false
  disable_on_destroy         = false
}

Error

Run terraform apply but it keeps repeating the error message.

Error: Error creating service account: googleapi: Error 403: Identity and Access Management (IAM) API has not been used in project 450605631931 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/iam.googleapis.com/overview?project=450605631931 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.
│ Details:
│ [
│   {
│     "@type": "type.googleapis.com/google.rpc.Help",
│     "links": [
│       {
│         "description": "Google developers console API activation",
│         "url": "https://console.developers.google.com/apis/api/iam.googleapis.com/overview?project=450605631931"
│       }
│     ]
│   },
│   {
│     "@type": "type.googleapis.com/google.rpc.ErrorInfo",
│     "domain": "googleapis.com",
│     "metadata": {
│       "consumer": "projects/450605631931",
│       "service": "iam.googleapis.com"
│     },
│     "reason": "SERVICE_DISABLED"
│   }
│ ]
│ , accessNotConfigured
│ 
│   with google_service_account.gke,
│   on sa.tf line 14, in resource "google_service_account" "gke":
│   14: resource "google_service_account" "gke" {

The GCP console says it is enabled.

enter image description here

0 Answers
Related