diff --git a/backend/remote-state/pg/backend_state.go b/backend/remote-state/pg/backend_state.go index cc15b75cc0..dbcd08ec18 100644 --- a/backend/remote-state/pg/backend_state.go +++ b/backend/remote-state/pg/backend_state.go @@ -7,10 +7,10 @@ import ( "github.com/hashicorp/terraform/backend" "github.com/hashicorp/terraform/state" "github.com/hashicorp/terraform/state/remote" - "github.com/hashicorp/terraform/terraform" + "github.com/hashicorp/terraform/states" ) -func (b *Backend) States() ([]string, error) { +func (b *Backend) Workspaces() ([]string, error) { query := `SELECT name FROM %s.%s ORDER BY name` rows, err := b.db.Query(fmt.Sprintf(query, b.schemaName, statesTableName)) if err != nil { @@ -34,7 +34,7 @@ func (b *Backend) States() ([]string, error) { return result, nil } -func (b *Backend) DeleteState(name string) error { +func (b *Backend) DeleteWorkspace(name string) error { if name == backend.DefaultStateName || name == "" { return fmt.Errorf("can't delete default state") } @@ -48,7 +48,7 @@ func (b *Backend) DeleteState(name string) error { return nil } -func (b *Backend) State(name string) (state.State, error) { +func (b *Backend) StateMgr(name string) (state.State, error) { // Build the state client var stateMgr state.State = &remote.State{ Client: &RemoteClient{ @@ -72,7 +72,7 @@ func (b *Backend) State(name string) (state.State, error) { // If we need to force-unlock, but for some reason the state no longer // exists, the user will have to use the `psql` tool to manually fix the // situation. - existing, err := b.States() + existing, err := b.Workspaces() if err != nil { return nil, err } @@ -87,7 +87,7 @@ func (b *Backend) State(name string) (state.State, error) { // Grab a lock, we use this to write an empty state if one doesn't // exist already. We have to write an empty state as a sentinel value - // so States() knows it exists. + // so Workspaces() knows it exists. if !exists { lockInfo := state.NewLockInfo() lockInfo.Operation = "init" @@ -107,7 +107,7 @@ func (b *Backend) State(name string) (state.State, error) { // If we have no state, we have to create an empty state if v := stateMgr.State(); v == nil { - if err := stateMgr.WriteState(terraform.NewState()); err != nil { + if err := stateMgr.WriteState(states.NewState()); err != nil { err = lockUnlock(err) return nil, err } diff --git a/backend/remote-state/pg/backend_test.go b/backend/remote-state/pg/backend_test.go index a7c5f9792f..60b496c264 100644 --- a/backend/remote-state/pg/backend_test.go +++ b/backend/remote-state/pg/backend_test.go @@ -40,10 +40,10 @@ func TestBackendConfig(t *testing.T) { } defer dbCleaner.Query(fmt.Sprintf("DROP SCHEMA IF EXISTS %s CASCADE", schemaName)) - config := map[string]interface{}{ + config := backend.TestWrapConfig(map[string]interface{}{ "conn_str": connStr, "schema_name": schemaName, - } + }) b := backend.TestBackendConfig(t, New(), config).(*Backend) if b == nil { @@ -60,12 +60,12 @@ func TestBackendConfig(t *testing.T) { t.Fatal(err) } - _, err = b.State(backend.DefaultStateName) + _, err = b.StateMgr(backend.DefaultStateName) if err != nil { t.Fatal(err) } - s, err := b.State(backend.DefaultStateName) + s, err := b.StateMgr(backend.DefaultStateName) if err != nil { t.Fatal(err) } @@ -85,10 +85,10 @@ func TestBackendStates(t *testing.T) { } defer dbCleaner.Query(fmt.Sprintf("DROP SCHEMA IF EXISTS %s CASCADE", schemaName)) - config := map[string]interface{}{ + config := backend.TestWrapConfig(map[string]interface{}{ "conn_str": connStr, "schema_name": schemaName, - } + }) b := backend.TestBackendConfig(t, New(), config).(*Backend) if b == nil { @@ -108,10 +108,10 @@ func TestBackendStateLocks(t *testing.T) { } defer dbCleaner.Query(fmt.Sprintf("DROP SCHEMA IF EXISTS %s CASCADE", schemaName)) - config := map[string]interface{}{ + config := backend.TestWrapConfig(map[string]interface{}{ "conn_str": connStr, "schema_name": schemaName, - } + }) b := backend.TestBackendConfig(t, New(), config).(*Backend) if b == nil { @@ -138,11 +138,11 @@ func TestBackendStateLocksDisabled(t *testing.T) { } defer dbCleaner.Query(fmt.Sprintf("DROP SCHEMA IF EXISTS %s CASCADE", schemaName)) - config := map[string]interface{}{ + config := backend.TestWrapConfig(map[string]interface{}{ "conn_str": connStr, "schema_name": schemaName, "lock": false, - } + }) b := backend.TestBackendConfig(t, New(), config).(*Backend) if b == nil { diff --git a/backend/remote-state/pg/client_test.go b/backend/remote-state/pg/client_test.go index 8f16162b76..40e81ddf25 100644 --- a/backend/remote-state/pg/client_test.go +++ b/backend/remote-state/pg/client_test.go @@ -23,17 +23,17 @@ func TestRemoteClient(t *testing.T) { } defer dbCleaner.Query(fmt.Sprintf("DROP SCHEMA IF EXISTS %s CASCADE", schemaName)) - config := map[string]interface{}{ + config := backend.TestWrapConfig(map[string]interface{}{ "conn_str": connStr, "schema_name": schemaName, - } + }) b := backend.TestBackendConfig(t, New(), config).(*Backend) if b == nil { t.Fatal("Backend could not be configured") } - s, err := b.State(backend.DefaultStateName) + s, err := b.StateMgr(backend.DefaultStateName) if err != nil { t.Fatal(err) } @@ -50,13 +50,13 @@ func TestRemoteLocks(t *testing.T) { } defer dbCleaner.Query(fmt.Sprintf("DROP SCHEMA IF EXISTS %s CASCADE", schemaName)) - config := map[string]interface{}{ + config := backend.TestWrapConfig(map[string]interface{}{ "conn_str": connStr, "schema_name": schemaName, - } + }) b := backend.TestBackendConfig(t, New(), config).(*Backend) - s, err := b.State(backend.DefaultStateName) + s, err := b.StateMgr(backend.DefaultStateName) if err != nil { t.Fatal(err) }