Answers: <p>Terraform talks to the cloudkms api endpoint in the calling project, so the API must be enabled in both projects.</p>
  
Answers: CC BY-SA 4.0
Answers: 2024-09-10T20:09:07.687Z
Answers: 2024-09-10T20:09:07.687Z
Answers: jrobdawiz
Body: <p>I'm trying to create a <code>google_kms_key_ring</code> in project <code>b89d</code>. When I run <code>terraform apply</code>, I can see the <code>google_kms_key_ring</code> <code>project</code> field is set to the project I want:</p>
  <pre class="lang-bash prettyprint-override"><code> + resource &quot;google_kms_key_ring&quot; &quot;main_key_ring&quot; {
        + id       = (known after apply)
        + location = &quot;northamerica-northeast1&quot;
        + name     = &quot;key-ring-test&quot;
        + project  = &quot;b89d&quot;
      }
  </code></pre>
  <p>However when I execute this plan, I get the error &quot;Cloud Key Management Service (KMS) API has not been used in project XXXXXXXXX before or it is disabled&quot;.</p>
  <p>Project <code>XXXXXXXXX</code> is a completely different project. It seems that project <code>b89d</code> that I specified is being ignored. I verified via the GCP console that the KMS API <strong>is</strong> enabled in the project I want (<code>b89d</code>), but terraform / GCP complains it is not enabled in a different project. How can I fix this?</p>
  <p>I can see in the terraform logs, it submits the correct url:</p>
  <pre><code>POST /v1/projects/b89d/locations/northamerica-northeast1/keyRings?alt=json&amp;keyRingId=key-ring-test HTTP/1.1
  </code></pre>
  <p>I don't know why it's complaining about the API being enabled in a different project.</p>
  
Comments: CC BY-SA 4.0
Comments: 2023-05-06T00:56:21.263Z
Comments: Seems related to https://github.com/hashicorp/terraform-provider-google/issues/10066
Comments: Brad
Comments: CC BY-SA 4.0
Comments: 2023-05-06T02:25:39.927Z
Comments: Post a minimal example that reproduces the problem. Fragments do not help in this case.
Comments: John Hanley
Tags: <terraform><google-cloud-platform>
Title: Terraform GCP "API has not been used in project" for the wrong project
UserDisplayName: Brad
ThreadText: # Terraform GCP "API has not been used in project" for the wrong project
  
  (Asked by: username_0 on 2023-05-06)
  
  I'm trying to create a `google_kms_key_ring` in project `b89d`. When I run `terraform apply`, I can see the `google_kms_key_ring` `project` field is set to the project I want:
  
  ```bash
   + resource "google_kms_key_ring" "main_key_ring" {
        + id       = (known after apply)
        + location = "northamerica-northeast1"
        + name     = "key-ring-test"
        + project  = "b89d"
      }
  
  ```
  
  However when I execute this plan, I get the error "Cloud Key Management Service (KMS) API has not been used in project XXXXXXXXX before or it is disabled".
  
  Project `XXXXXXXXX` is a completely different project. It seems that project `b89d` that I specified is being ignored. I verified via the GCP console that the KMS API **is** enabled in the project I want (`b89d`), but terraform / GCP complains it is not enabled in a different project. How can I fix this?
  
  I can see in the terraform logs, it submits the correct url:
  
  ```
  POST /v1/projects/b89d/locations/northamerica-northeast1/keyRings?alt=json&keyRingId=key-ring-test HTTP/1.1
  
  ```
  
  I don't know why it's complaining about the API being enabled in a different project.
  
  **Tags:** terraform, google-cloud-platform
  
  > **Comments:**
  > **username_0**: Seems related to https://github.com/hashicorp/terraform-provider-google/issues/10066  
  > **username_1**: Post a minimal example that reproduces the problem. Fragments do not help in this case.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2024-09-10. Score: 0
  
  Terraform talks to the cloudkms api endpoint in the calling project, so the API must be enabled in both projects.
  
  
  ---
  
  