Skip to content

Commit 66b0ee9

Browse files
committed
refactor: Make NewPluggable return a Pluggable concrete type, instead of an instance of the backend.Backend interface.
1 parent 6f3e3ff commit 66b0ee9

File tree

3 files changed

+4
-15
lines changed

3 files changed

+4
-15
lines changed

internal/backend/pluggable/pluggable.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
//
2929
// By wrapping a configured provider in a Pluggable we allow calling code
3030
// to use the provider's gRPC methods when interacting with state.
31-
func NewPluggable(p providers.Interface, typeName string) (backend.Backend, error) {
31+
func NewPluggable(p providers.Interface, typeName string) (*Pluggable, error) {
3232
if p == nil {
3333
return nil, errors.New("Attempted to initialize pluggable state with a nil provider interface. This is a bug in Terraform and should be reported")
3434
}

internal/backend/pluggable/pluggable_test.go

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -417,12 +417,7 @@ func TestPluggable_ProviderSchema(t *testing.T) {
417417
t.Fatalf("unexpected error: %s", err)
418418
}
419419

420-
// Calling code will need to case to Pluggable after using NewPluggable,
421-
// so we do something similar in this test
422-
var providerSchema *configschema.Block
423-
if pluggable, ok := p.(*Pluggable); ok {
424-
providerSchema = pluggable.ProviderSchema()
425-
}
420+
providerSchema := p.ProviderSchema()
426421

427422
if !mock.GetProviderSchemaCalled {
428423
t.Fatal("expected ProviderSchema to call the GetProviderSchema RPC")
@@ -450,12 +445,7 @@ func TestPluggable_ProviderSchema(t *testing.T) {
450445
t.Fatalf("unexpected error: %s", err)
451446
}
452447

453-
// Calling code will need to case to Pluggable after using NewPluggable,
454-
// so we do something similar in this test
455-
var providerSchema *configschema.Block
456-
if pluggable, ok := p.(*Pluggable); ok {
457-
providerSchema = pluggable.ProviderSchema()
458-
}
448+
providerSchema := p.ProviderSchema()
459449

460450
if !mock.GetProviderSchemaCalled {
461451
t.Fatal("expected ProviderSchema to call the GetProviderSchema RPC")

internal/command/meta_backend.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1946,7 +1946,6 @@ func (m *Meta) savedStateStore(sMgr *clistate.LocalState, factory providers.Fact
19461946
// The provider and state store will be configured using the backend state file.
19471947

19481948
var diags tfdiags.Diagnostics
1949-
var b backend.Backend
19501949

19511950
if factory == nil {
19521951
diags = diags.Append(&hcl.Diagnostic{
@@ -2099,7 +2098,7 @@ func (m *Meta) savedStateStore(sMgr *clistate.LocalState, factory providers.Fact
20992098

21002099
// Now we have a fully configured state store, ready to be used.
21012100
// To make it usable we need to return it in a backend.Backend interface.
2102-
b, err = backendPluggable.NewPluggable(provider, s.StateStore.Type)
2101+
b, err := backendPluggable.NewPluggable(provider, s.StateStore.Type)
21032102
if err != nil {
21042103
diags = diags.Append(err)
21052104
}

0 commit comments

Comments
 (0)