无法在区域中创建Google云存储桶[terraform]

时间:2017-08-20 11:52:14

标签: google-cloud-platform google-cloud-storage terraform

我正在尝试使用us-west1-a区域中的terraform创建一个gcs存储桶,storage-classREGIONAL。但是这样做时我得到了这个错误

* 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

以下是我现在拥有的.tf文件

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

文档

2 个答案:

答案 0 :(得分:1)

CreateBucket请求中指定的位置是区域,而不是区域(请参阅https://cloud.google.com/compute/docs/regions-zones/regions-zones处的定义)。 “us-west1-a”是一个区域。请尝试使用“us-west1”(这是包含us-west1-a区域的区域)的请求。

答案 1 :(得分:0)

看起来你实际上没有在资源中指定一个位置,因此它默认为“us”,这是无效的,因为它不是一个区域。尝试:

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

请注意,我已将“location”添加到资源,并将location变量设置为所需的实际GCS位置。