backend/gcs: remove deprecated "path" config argument (#26841)

This commit is contained in:
Upo 2020-11-06 21:35:40 +00:00 committed by GitHub
parent 4b58d62c54
commit 3b9c5e5bbb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 33 deletions

View File

@ -29,7 +29,6 @@ type Backend struct {
bucketName string bucketName string
prefix string prefix string
defaultStateFile string
encryptionKey []byte encryptionKey []byte
} }
@ -45,13 +44,6 @@ 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: "Path of the default state file",
Deprecated: "Use the \"prefix\" option instead",
},
"prefix": { "prefix": {
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
@ -137,8 +129,6 @@ func (b *Backend) configure(ctx context.Context) error {
b.prefix = b.prefix + "/" b.prefix = b.prefix + "/"
} }
b.defaultStateFile = strings.TrimLeft(data.Get("path").(string), "/")
var opts []option.ClientOption var opts []option.ClientOption
// Add credential source // Add credential source

View File

@ -146,15 +146,9 @@ func (b *Backend) StateMgr(name string) (statemgr.Full, error) {
} }
func (b *Backend) stateFile(name string) string { func (b *Backend) stateFile(name string) string {
if name == backend.DefaultStateName && b.defaultStateFile != "" {
return b.defaultStateFile
}
return path.Join(b.prefix, name+stateFileSuffix) return path.Join(b.prefix, name+stateFileSuffix)
} }
func (b *Backend) lockFile(name string) string { func (b *Backend) lockFile(name string) string {
if name == backend.DefaultStateName && b.defaultStateFile != "" {
return strings.TrimSuffix(b.defaultStateFile, stateFileSuffix) + lockFileSuffix
}
return path.Join(b.prefix, name+lockFileSuffix) return path.Join(b.prefix, name+lockFileSuffix)
} }

View File

@ -26,22 +26,18 @@ func TestStateFile(t *testing.T) {
cases := []struct { cases := []struct {
prefix string prefix string
defaultStateFile string
name string name string
wantStateFile string wantStateFile string
wantLockFile string wantLockFile string
}{ }{
{"state", "", "default", "state/default.tfstate", "state/default.tflock"}, {"state", "default", "state/default.tfstate", "state/default.tflock"},
{"state", "", "test", "state/test.tfstate", "state/test.tflock"}, {"state", "test", "state/test.tfstate", "state/test.tflock"},
{"state", "legacy.tfstate", "default", "legacy.tfstate", "legacy.tflock"}, {"state", "test", "state/test.tfstate", "state/test.tflock"},
{"state", "legacy.tfstate", "test", "state/test.tfstate", "state/test.tflock"}, {"state", "test", "state/test.tfstate", "state/test.tflock"},
{"state", "legacy.state", "default", "legacy.state", "legacy.state.tflock"},
{"state", "legacy.state", "test", "state/test.tfstate", "state/test.tflock"},
} }
for _, c := range cases { for _, c := range cases {
b := &Backend{ b := &Backend{
prefix: c.prefix, prefix: c.prefix,
defaultStateFile: c.defaultStateFile,
} }
if got := b.stateFile(c.name); got != c.wantStateFile { if got := b.stateFile(c.name); got != c.wantStateFile {

View File

@ -101,8 +101,6 @@ The following configuration options are supported:
`credentials` field. `credentials` field.
* `prefix` - (Optional) GCS prefix inside the bucket. Named states for * `prefix` - (Optional) GCS prefix inside the bucket. Named states for
workspaces are stored in an object called `<prefix>/<name>.tfstate`. workspaces are stored in an object called `<prefix>/<name>.tfstate`.
* `path` - (Deprecated) GCS path to the state file of the default state. For
backwards compatibility only, use `prefix` instead.
* `encryption_key` / `GOOGLE_ENCRYPTION_KEY` - (Optional) A 32 byte base64 * `encryption_key` / `GOOGLE_ENCRYPTION_KEY` - (Optional) A 32 byte base64
encoded 'customer supplied encryption key' used to encrypt all state. For encoded 'customer supplied encryption key' used to encrypt all state. For
more information see [Customer Supplied Encryption more information see [Customer Supplied Encryption