From 5a4e2076e903d02d886d161943f02b51a8b34e35 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Fri, 8 Sep 2017 14:32:00 +0200 Subject: [PATCH] backend/remote-state/gcloud: Add the "path" config option. This config option was used by the legacy "gcs" client. If set, we're using it for the default state -- all other states still use the "state_dir" setting. --- backend/remote-state/gcloud/backend.go | 13 +++++++++++-- backend/remote-state/gcloud/backend_state.go | 18 ++++++++++++++++-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/backend/remote-state/gcloud/backend.go b/backend/remote-state/gcloud/backend.go index 4f61ba1948..ecfad13a33 100644 --- a/backend/remote-state/gcloud/backend.go +++ b/backend/remote-state/gcloud/backend.go @@ -24,8 +24,9 @@ type gcsBackend struct { storageClient *storage.Client storageContext context.Context - bucketName string - stateDir string + bucketName string + stateDir string + defaultStateFile string } func New() backend.Backend { @@ -39,6 +40,12 @@ func New() backend.Backend { Description: "The name of the Google Cloud Storage bucket", }, + "path": { + Type: schema.TypeString, + Optional: true, + Description: "(Legacy) Path of the default state file; use state_dir instead", + }, + "state_dir": { Type: schema.TypeString, Optional: true, @@ -73,6 +80,8 @@ func (b *gcsBackend) configure(ctx context.Context) error { b.bucketName = data.Get("bucket").(string) b.stateDir = strings.TrimLeft(data.Get("state_dir").(string), "/") + b.defaultStateFile = strings.TrimLeft(data.Get("path").(string), "/") + var tokenSource oauth2.TokenSource if credentials := data.Get("credentials").(string); credentials != "" { diff --git a/backend/remote-state/gcloud/backend_state.go b/backend/remote-state/gcloud/backend_state.go index 5bd02580a7..38ec7e2d6d 100644 --- a/backend/remote-state/gcloud/backend_state.go +++ b/backend/remote-state/gcloud/backend_state.go @@ -77,8 +77,8 @@ func (b *gcsBackend) client(name string) (*remoteClient, error) { storageContext: b.storageContext, storageClient: b.storageClient, bucketName: b.bucketName, - stateFilePath: path.Join(b.stateDir, name+stateFileSuffix), - lockFilePath: path.Join(b.stateDir, name+lockFileSuffix), + stateFilePath: b.stateFile(name), + lockFilePath: b.lockFile(name), }, nil } @@ -139,3 +139,17 @@ the initial state file is created.` return st, nil } + +func (b *gcsBackend) stateFile(name string) string { + if name == backend.DefaultStateName && b.defaultStateFile != "" { + return b.defaultStateFile + } + return path.Join(b.stateDir, name+stateFileSuffix) +} + +func (b *gcsBackend) lockFile(name string) string { + if name == backend.DefaultStateName && b.defaultStateFile != "" { + return strings.TrimSuffix(b.defaultStateFile, stateFileSuffix) + lockFileSuffix + } + return path.Join(b.stateDir, name+lockFileSuffix) +}