From 3ca1253796c35a34ebf684a8202d512455e97cdf Mon Sep 17 00:00:00 2001 From: Stefan Schmidt Date: Mon, 5 Nov 2018 13:49:33 +0100 Subject: [PATCH] backend/gcs: Mark the unused attributes project and region as removed. These two attributes are not used since https://github.com/hashicorp/terraform/commit/aec45e696701b4aa09958b5e683831b293d6a85e. --- backend/remote-state/gcs/backend.go | 14 ++------------ backend/remote-state/gcs/backend_test.go | 5 ++--- website/docs/backends/types/gcs.html.md | 11 ++++++----- 3 files changed, 10 insertions(+), 20 deletions(-) diff --git a/backend/remote-state/gcs/backend.go b/backend/remote-state/gcs/backend.go index 26b430b41..f1e6b372a 100644 --- a/backend/remote-state/gcs/backend.go +++ b/backend/remote-state/gcs/backend.go @@ -32,9 +32,6 @@ type Backend struct { defaultStateFile string encryptionKey []byte - - projectID string - region string } func New() backend.Backend { @@ -80,6 +77,7 @@ func New() backend.Backend { Optional: true, Description: "Google Cloud Project ID", Default: "", + Removed: "Please remove this attribute. It is not used since the backend no longer creates the bucket if it does not yet exist.", }, "region": { @@ -87,6 +85,7 @@ func New() backend.Backend { Optional: true, Description: "Region / location in which to create the bucket", Default: "", + Removed: "Please remove this attribute. It is not used since the backend no longer creates the bucket if it does not yet exist.", }, }, } @@ -115,15 +114,6 @@ func (b *Backend) configure(ctx context.Context) error { b.defaultStateFile = strings.TrimLeft(data.Get("path").(string), "/") - b.projectID = data.Get("project").(string) - if id := os.Getenv("GOOGLE_PROJECT"); b.projectID == "" && id != "" { - b.projectID = id - } - b.region = data.Get("region").(string) - if r := os.Getenv("GOOGLE_REGION"); b.projectID == "" && r != "" { - b.region = r - } - var opts []option.ClientOption creds := data.Get("credentials").(string) diff --git a/backend/remote-state/gcs/backend_test.go b/backend/remote-state/gcs/backend_test.go index dd44d919a..6944d9388 100644 --- a/backend/remote-state/gcs/backend_test.go +++ b/backend/remote-state/gcs/backend_test.go @@ -181,7 +181,6 @@ func setupBackend(t *testing.T, bucket, prefix, key string) backend.Backend { } config := map[string]interface{}{ - "project": projectID, "bucket": bucket, "prefix": prefix, "encryption_key": key, @@ -199,9 +198,9 @@ func setupBackend(t *testing.T, bucket, prefix, key string) backend.Backend { } attrs := &storage.BucketAttrs{ - Location: be.region, + Location: os.Getenv("GOOGLE_REGION"), } - err := bkt.Create(be.storageContext, be.projectID, attrs) + err := bkt.Create(be.storageContext, projectID, attrs) if err != nil { t.Fatal(err) } diff --git a/website/docs/backends/types/gcs.html.md b/website/docs/backends/types/gcs.html.md index 3349c304e..25d5b34c9 100644 --- a/website/docs/backends/types/gcs.html.md +++ b/website/docs/backends/types/gcs.html.md @@ -10,7 +10,12 @@ description: |- **Kind: Standard (with locking)** -Stores the state as an object in a configurable prefix and bucket on [Google Cloud Storage](https://cloud.google.com/storage/) (GCS). +Stores the state as an object in a configurable prefix in a given bucket on [Google Cloud Storage](https://cloud.google.com/storage/) (GCS). +This backend also supports [state locking](/docs/state/locking.html). + +~> **Warning!** It is highly recommended that you enable +[Object Versioning](https://cloud.google.com/storage/docs/object-versioning) +on the GCS bucket to allow for state recovery in the case of accidental deletions and human error. ## Example Configuration @@ -55,8 +60,4 @@ The following configuration options are supported: The provided credentials need to have the `devstorage.read_write` scope and `WRITER` permissions on the bucket. * `prefix` - (Optional) GCS prefix inside the bucket. Named states for workspaces are stored in an object called `/.tfstate`. * `path` - (Deprecated) GCS path to the state file of the default state. For backwards compatibility only, use `prefix` instead. - * `project` / `GOOGLE_PROJECT` - (Optional) The project ID to which the bucket belongs. This is only used when creating a new bucket during initialization. - Since buckets have globally unique names, the project ID is not required to access the bucket during normal operation. - * `region` / `GOOGLE_REGION` - (Optional) The region in which a new bucket is created. - For more information, see [Bucket Locations](https://cloud.google.com/storage/docs/bucket-locations). * `encryption_key` / `GOOGLE_ENCRYPTION_KEY` - (Optional) A 32 byte base64 encoded 'customer supplied encryption key' used to encrypt all state. For more information see [Customer Supplied Encryption Keys](https://cloud.google.com/storage/docs/encryption#customer-supplied).