【问题标题】:Unable to create google cloud storage bucket in a zone [terraform]无法在区域中创建谷歌云存储桶 [terraform]
【发布时间】:2018-01-28 15:03:12
【问题描述】:

我正在尝试使用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"
}

文档

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

    • 我遇到了同样的问题,但出现了不同的错误消息(几年后):google_storage_bucket.tf-bucket: Creating... Error: googleapi: Error 400: Invalid Value, invalid。我希望这更具描述性...
    【解决方案2】:

    看起来您实际上并未在资源中指定位置,因此它默认为“我们”,这是无效的,因为它不是区域。试试:

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

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

    【讨论】:

      猜你喜欢
      • 2020-02-15
      • 1970-01-01
      • 2016-01-31
      • 2019-09-20
      • 1970-01-01
      • 1970-01-01
      • 2020-06-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多