Skip to content

Commit

Permalink
Compatibility fixes for 0.12.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mars committed Nov 14, 2018
1 parent 6088b7d commit bad189e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 29 deletions.
14 changes: 7 additions & 7 deletions backend/remote-state/pg/backend_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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")
}
Expand All @@ -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{
Expand All @@ -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
}
Expand All @@ -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"
Expand All @@ -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
}
Expand Down
20 changes: 10 additions & 10 deletions backend/remote-state/pg/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions backend/remote-state/pg/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
15 changes: 9 additions & 6 deletions terraform/valuesourcetype_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bad189e

Please sign in to comment.