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.
This commit is contained in:
Florian Forster 2017-09-08 14:32:00 +02:00 committed by James Bardin
parent f80b872bc3
commit 5a4e2076e9
2 changed files with 27 additions and 4 deletions

View File

@ -24,8 +24,9 @@ type gcsBackend struct {
storageClient *storage.Client storageClient *storage.Client
storageContext context.Context storageContext context.Context
bucketName string bucketName string
stateDir string stateDir string
defaultStateFile string
} }
func New() backend.Backend { func New() backend.Backend {
@ -39,6 +40,12 @@ func New() backend.Backend {
Description: "The name of the Google Cloud Storage bucket", 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": { "state_dir": {
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
@ -73,6 +80,8 @@ func (b *gcsBackend) configure(ctx context.Context) error {
b.bucketName = data.Get("bucket").(string) b.bucketName = data.Get("bucket").(string)
b.stateDir = strings.TrimLeft(data.Get("state_dir").(string), "/") b.stateDir = strings.TrimLeft(data.Get("state_dir").(string), "/")
b.defaultStateFile = strings.TrimLeft(data.Get("path").(string), "/")
var tokenSource oauth2.TokenSource var tokenSource oauth2.TokenSource
if credentials := data.Get("credentials").(string); credentials != "" { if credentials := data.Get("credentials").(string); credentials != "" {

View File

@ -77,8 +77,8 @@ func (b *gcsBackend) client(name string) (*remoteClient, error) {
storageContext: b.storageContext, storageContext: b.storageContext,
storageClient: b.storageClient, storageClient: b.storageClient,
bucketName: b.bucketName, bucketName: b.bucketName,
stateFilePath: path.Join(b.stateDir, name+stateFileSuffix), stateFilePath: b.stateFile(name),
lockFilePath: path.Join(b.stateDir, name+lockFileSuffix), lockFilePath: b.lockFile(name),
}, nil }, nil
} }
@ -139,3 +139,17 @@ the initial state file is created.`
return st, nil 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)
}