Compatibility fixes for 0.12.0

This commit is contained in:
Mars Hall 2018-11-13 17:09:43 -08:00
parent e5319d39c2
commit c8b8227967
3 changed files with 23 additions and 23 deletions

View File

@ -7,10 +7,10 @@ import (
"github.com/hashicorp/terraform/backend" "github.com/hashicorp/terraform/backend"
"github.com/hashicorp/terraform/state" "github.com/hashicorp/terraform/state"
"github.com/hashicorp/terraform/state/remote" "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` query := `SELECT name FROM %s.%s ORDER BY name`
rows, err := b.db.Query(fmt.Sprintf(query, b.schemaName, statesTableName)) rows, err := b.db.Query(fmt.Sprintf(query, b.schemaName, statesTableName))
if err != nil { if err != nil {
@ -34,7 +34,7 @@ func (b *Backend) States() ([]string, error) {
return result, nil return result, nil
} }
func (b *Backend) DeleteState(name string) error { func (b *Backend) DeleteWorkspace(name string) error {
if name == backend.DefaultStateName || name == "" { if name == backend.DefaultStateName || name == "" {
return fmt.Errorf("can't delete default state") return fmt.Errorf("can't delete default state")
} }
@ -48,7 +48,7 @@ func (b *Backend) DeleteState(name string) error {
return nil return nil
} }
func (b *Backend) State(name string) (state.State, error) { func (b *Backend) StateMgr(name string) (state.State, error) {
// Build the state client // Build the state client
var stateMgr state.State = &remote.State{ var stateMgr state.State = &remote.State{
Client: &RemoteClient{ 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 // 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 // exists, the user will have to use the `psql` tool to manually fix the
// situation. // situation.
existing, err := b.States() existing, err := b.Workspaces()
if err != nil { if err != nil {
return nil, err 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 // 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 // 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 { if !exists {
lockInfo := state.NewLockInfo() lockInfo := state.NewLockInfo()
lockInfo.Operation = "init" 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 we have no state, we have to create an empty state
if v := stateMgr.State(); v == nil { 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) err = lockUnlock(err)
return nil, err return nil, err
} }

View File

@ -40,10 +40,10 @@ func TestBackendConfig(t *testing.T) {
} }
defer dbCleaner.Query(fmt.Sprintf("DROP SCHEMA IF EXISTS %s CASCADE", schemaName)) 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, "conn_str": connStr,
"schema_name": schemaName, "schema_name": schemaName,
} })
b := backend.TestBackendConfig(t, New(), config).(*Backend) b := backend.TestBackendConfig(t, New(), config).(*Backend)
if b == nil { if b == nil {
@ -60,12 +60,12 @@ func TestBackendConfig(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
_, err = b.State(backend.DefaultStateName) _, err = b.StateMgr(backend.DefaultStateName)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
s, err := b.State(backend.DefaultStateName) s, err := b.StateMgr(backend.DefaultStateName)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -85,10 +85,10 @@ func TestBackendStates(t *testing.T) {
} }
defer dbCleaner.Query(fmt.Sprintf("DROP SCHEMA IF EXISTS %s CASCADE", schemaName)) 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, "conn_str": connStr,
"schema_name": schemaName, "schema_name": schemaName,
} })
b := backend.TestBackendConfig(t, New(), config).(*Backend) b := backend.TestBackendConfig(t, New(), config).(*Backend)
if b == nil { if b == nil {
@ -108,10 +108,10 @@ func TestBackendStateLocks(t *testing.T) {
} }
defer dbCleaner.Query(fmt.Sprintf("DROP SCHEMA IF EXISTS %s CASCADE", schemaName)) 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, "conn_str": connStr,
"schema_name": schemaName, "schema_name": schemaName,
} })
b := backend.TestBackendConfig(t, New(), config).(*Backend) b := backend.TestBackendConfig(t, New(), config).(*Backend)
if b == nil { if b == nil {
@ -138,11 +138,11 @@ func TestBackendStateLocksDisabled(t *testing.T) {
} }
defer dbCleaner.Query(fmt.Sprintf("DROP SCHEMA IF EXISTS %s CASCADE", schemaName)) 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, "conn_str": connStr,
"schema_name": schemaName, "schema_name": schemaName,
"lock": false, "lock": false,
} })
b := backend.TestBackendConfig(t, New(), config).(*Backend) b := backend.TestBackendConfig(t, New(), config).(*Backend)
if b == nil { if b == nil {

View File

@ -23,17 +23,17 @@ func TestRemoteClient(t *testing.T) {
} }
defer dbCleaner.Query(fmt.Sprintf("DROP SCHEMA IF EXISTS %s CASCADE", schemaName)) 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, "conn_str": connStr,
"schema_name": schemaName, "schema_name": schemaName,
} })
b := backend.TestBackendConfig(t, New(), config).(*Backend) b := backend.TestBackendConfig(t, New(), config).(*Backend)
if b == nil { if b == nil {
t.Fatal("Backend could not be configured") t.Fatal("Backend could not be configured")
} }
s, err := b.State(backend.DefaultStateName) s, err := b.StateMgr(backend.DefaultStateName)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -50,13 +50,13 @@ func TestRemoteLocks(t *testing.T) {
} }
defer dbCleaner.Query(fmt.Sprintf("DROP SCHEMA IF EXISTS %s CASCADE", schemaName)) 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, "conn_str": connStr,
"schema_name": schemaName, "schema_name": schemaName,
} })
b := backend.TestBackendConfig(t, New(), config).(*Backend) b := backend.TestBackendConfig(t, New(), config).(*Backend)
s, err := b.State(backend.DefaultStateName) s, err := b.StateMgr(backend.DefaultStateName)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }