2
votes

I am trying to create a gcs bucket using terraform in the region us-west1-a with the storage-class as REGIONAL. But I am getting this error when doing so

* google_storage_bucket.terraform-state: 1 error(s) occurred:

* google_storage_bucket.terraform-state: googleapi: Error 400: The combination of locationConstraint and storageClass you provided is not supported for your project, invalid

Here is the .tf file I have right now

resource "google_storage_bucket" "terraform-state" {
  name          = "terraform-state"
  storage_class = "${var.storage-class}"
}

provider "google" {
  credentials = "${file("${path.module}/../credentials/account.json")}"
  project     = "${var.project-name}"
  region      = "${var.region}"
}

variable "region" {
  default = "us-west1" # Oregon
}

variable "project-name" {
  default = "my-project"
}

variable "location" {
  default = "US"
}

variable "storage-class" {
  default = "REGIONAL"
}

Docs

2

2 Answers

3
votes

The location specified in the CreateBucket request is a region, not a zone (see definitions at https://cloud.google.com/compute/docs/regions-zones/regions-zones). "us-west1-a" is a zone. Please try the request with "us-west1" (which is the region that contains the us-west1-a zone) instead.

0
votes

It looks like you haven't actually specified a location in the resource, so it is defaulting to "us" which is invalid as that is not a region. Try:

resource "google_storage_bucket" "terraform-state" {
  name          = "terraform-state"
  storage_class = "${var.storage-class}"
  location      = "${var.location}"
}

variable "location" {
  default = "us-west1"
}

variable "storage-class" {
  default = "REGIONAL"
}

Notice that I have added "location" to the resource and set the location variable to the actual GCS location desired.