Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Nov 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions backend/remote-state/gcs/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ type Backend struct {
storageClient *storage.Client
storageContext context.Context

bucketName string
prefix string
defaultStateFile string
bucketName string
prefix string

encryptionKey []byte
}
Expand All @@ -45,13 +44,6 @@ func New() backend.Backend {
Description: "The name of the Google Cloud Storage bucket",
},

"path": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Watch out for line 117, where this is still in use: data.Get("path")

It appears the defaultStateFile value is also no longer relevant, since that was the sole thing that set it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying it now, getting some fun errors when i remove defaultStateFile from the struct and clean up references to it

Copy link
Contributor Author

@upodroid upodroid Nov 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is working now, not sure what the context for the legacy test is.

REDACTED  MCW0CDP3YY  ~  Desktop  Git  terraform   remove-path-gcs-be  3✎  ERROR  $   TF_ACC=1 go test -v ./backend/remote-state/gcs/
=== RUN   TestStateFile
=== PAUSE TestStateFile
=== RUN   TestRemoteClient
=== PAUSE TestRemoteClient
=== RUN   TestRemoteClientWithEncryption
=== PAUSE TestRemoteClientWithEncryption
=== RUN   TestRemoteLocks
=== PAUSE TestRemoteLocks
=== RUN   TestBackend
=== PAUSE TestBackend
=== RUN   TestBackendWithPrefix
=== PAUSE TestBackendWithPrefix
=== RUN   TestBackendWithEncryption
=== PAUSE TestBackendWithEncryption
=== CONT  TestStateFile
=== CONT  TestBackend
--- PASS: TestStateFile (0.00s)
=== CONT  TestRemoteClient
=== CONT  TestBackendWithEncryption
=== CONT  TestBackendWithPrefix
=== CONT  TestRemoteLocks
    TestRemoteLocks: backend_test.go:96: TestBackendConfig on *gcs.Backend with configs.synthBody{Filename:"<TestWrapConfig>", Values:map[string]cty.Value{"bucket":cty.StringVal("tf-1645030c4adee3b0-testremotelocks"), "encryption_key":cty.StringVal(""), "prefix":cty.StringVal("")}}
=== CONT  TestRemoteClientWithEncryption
    TestBackendWithPrefix: backend_test.go:146: TestBackendConfig on *gcs.Backend with configs.synthBody{Filename:"<TestWrapConfig>", Values:map[string]cty.Value{"bucket":cty.StringVal("tf-1645030c4ade0508-testbackendwithprefix"), "encryption_key":cty.StringVal(""), "prefix":cty.StringVal("test/prefix")}}
    TestBackendWithEncryption: backend_test.go:159: TestBackendConfig on *gcs.Backend with configs.synthBody{Filename:"<TestWrapConfig>", Values:map[string]cty.Value{"bucket":cty.StringVal("tf-1645030c4addd628-testbackendwithencryption"), "encryption_key":cty.StringVal("yRyCOikXi1ZDNE0xN3yiFsJjg7LGimoLrGFcLZgQoVk="), "prefix":cty.StringVal("")}}
    TestBackend: backend_test.go:130: TestBackendConfig on *gcs.Backend with configs.synthBody{Filename:"<TestWrapConfig>", Values:map[string]cty.Value{"bucket":cty.StringVal("tf-1645030c4adc14f0-testbackend"), "encryption_key":cty.StringVal(""), "prefix":cty.StringVal("")}}
    TestRemoteClient: backend_test.go:57: TestBackendConfig on *gcs.Backend with configs.synthBody{Filename:"<TestWrapConfig>", Values:map[string]cty.Value{"bucket":cty.StringVal("tf-1645030c4add39e8-testremoteclient"), "encryption_key":cty.StringVal(""), "prefix":cty.StringVal("")}}
    TestRemoteClientWithEncryption: backend_test.go:76: TestBackendConfig on *gcs.Backend with configs.synthBody{Filename:"<TestWrapConfig>", Values:map[string]cty.Value{"bucket":cty.StringVal("tf-1645030c4ae5cd38-testremoteclientwithencryption"), "encryption_key":cty.StringVal("yRyCOikXi1ZDNE0xN3yiFsJjg7LGimoLrGFcLZgQoVk="), "prefix":cty.StringVal("")}}
    TestBackendWithPrefix: backend_test.go:149: TestBackendConfig on *gcs.Backend with configs.synthBody{Filename:"<TestWrapConfig>", Values:map[string]cty.Value{"bucket":cty.StringVal("tf-1645030c4ade0508-testbackendwithprefix"), "encryption_key":cty.StringVal(""), "prefix":cty.StringVal("test/prefix/")}}
    TestBackendWithEncryption: backend_test.go:162: TestBackendConfig on *gcs.Backend with configs.synthBody{Filename:"<TestWrapConfig>", Values:map[string]cty.Value{"bucket":cty.StringVal("tf-1645030c4addd628-testbackendwithencryption"), "encryption_key":cty.StringVal("yRyCOikXi1ZDNE0xN3yiFsJjg7LGimoLrGFcLZgQoVk="), "prefix":cty.StringVal("")}}
    TestBackend: backend_test.go:133: TestBackendConfig on *gcs.Backend with configs.synthBody{Filename:"<TestWrapConfig>", Values:map[string]cty.Value{"bucket":cty.StringVal("tf-1645030c4adc14f0-testbackend"), "encryption_key":cty.StringVal(""), "prefix":cty.StringVal("")}}
--- PASS: TestRemoteClient (5.46s)
--- PASS: TestRemoteClientWithEncryption (5.79s)
--- PASS: TestRemoteLocks (6.37s)
    TestBackendWithPrefix: backend_test.go:152: TestBackend: testing state locking for *gcs.Backend
    TestBackend: backend_test.go:136: TestBackend: testing state locking for *gcs.Backend
    TestBackendWithEncryption: backend_test.go:165: TestBackend: testing state locking for *gcs.Backend
--- PASS: TestBackendWithPrefix (15.32s)
    TestBackend: backend_test.go:137: TestBackend: testing state locking for *gcs.Backend
--- PASS: TestBackendWithEncryption (15.87s)
--- PASS: TestBackend (19.85s)
PASS
ok      github.com/hashicorp/terraform/backend/remote-state/gcs 22.278s

Type: schema.TypeString,
Optional: true,
Description: "Path of the default state file",
Deprecated: "Use the \"prefix\" option instead",
},

"prefix": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -121,8 +113,6 @@ func (b *Backend) configure(ctx context.Context) error {
b.prefix = b.prefix + "/"
}

b.defaultStateFile = strings.TrimLeft(data.Get("path").(string), "/")

var opts []option.ClientOption

// Add credential source
Expand Down
6 changes: 0 additions & 6 deletions backend/remote-state/gcs/backend_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,9 @@ func (b *Backend) StateMgr(name string) (statemgr.Full, error) {
}

func (b *Backend) stateFile(name string) string {
if name == backend.DefaultStateName && b.defaultStateFile != "" {
return b.defaultStateFile
}
return path.Join(b.prefix, name+stateFileSuffix)
}

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)
}
22 changes: 9 additions & 13 deletions backend/remote-state/gcs/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,19 @@ func TestStateFile(t *testing.T) {
t.Parallel()

cases := []struct {
prefix string
defaultStateFile string
name string
wantStateFile string
wantLockFile string
prefix string
name string
wantStateFile string
wantLockFile string
}{
{"state", "", "default", "state/default.tfstate", "state/default.tflock"},
{"state", "", "test", "state/test.tfstate", "state/test.tflock"},
{"state", "legacy.tfstate", "default", "legacy.tfstate", "legacy.tflock"},
{"state", "legacy.tfstate", "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"},
{"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", "test", "state/test.tfstate", "state/test.tflock"},
}
for _, c := range cases {
b := &Backend{
prefix: c.prefix,
defaultStateFile: c.defaultStateFile,
prefix: c.prefix,
}

if got := b.stateFile(c.name); got != c.wantStateFile {
Expand Down
2 changes: 0 additions & 2 deletions website/docs/backends/types/gcs.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ The following configuration options are supported:
`credentials` field.
* `prefix` - (Optional) GCS prefix inside the bucket. Named states for
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
encoded 'customer supplied encryption key' used to encrypt all state. For
more information see [Customer Supplied Encryption
Expand Down