CodexBloom - Programming Q&A Platform

Terraform: Getting 'Invalid API Key' scenarios When Configuring Google Cloud Storage with Service Account

👀 Views: 3 💬 Answers: 1 📅 Created: 2025-06-11
terraform google-cloud gcs HCL

I'm writing unit tests and I'm sure I'm missing something obvious here, but I'm working with a frustrating scenario when trying to set up Google Cloud Storage (GCS) buckets using Terraform... I have a service account with the necessary permissions, but every time I run `terraform apply`, I get the behavior: `behavior: Invalid API key`. I've double-checked my Terraform code and the service account JSON key, but I'm still exploring. Here's a snippet of my Terraform configuration: ```hcl provider "google" { credentials = file("/path/to/service-account.json") project = "my-gcp-project" region = "us-central1" } resource "google_storage_bucket" "my_bucket" { name = "my-unique-bucket-name" location = "US" storage_class = "STANDARD" } ``` I've verified that the service account has the `Storage Admin` role assigned in the GCP console, and I’m using Terraform version 1.1.6 with the Google provider version 3.5.0. The credentials file is correctly specified, and I even attempted running `gcloud auth application-default login`, but it didn’t help. Additionally, I tried re-creating the service account and re-generating the JSON key, but the question continues. Can anyone suggest what might be going wrong with my configuration or steps to diagnose this scenario further? My development environment is Windows. What am I doing wrong?