From 9acfe30ca6b3e8dc76822fa30a55d20da5f0eaea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Lapeyre?= Date: Tue, 29 Sep 2020 23:18:34 +0200 Subject: [PATCH] Always have the default workspace in the pg backend Closes https://github.com/hashicorp/terraform/issues/23121 --- backend/remote-state/pg/backend_state.go | 6 ++++-- backend/remote-state/pg/backend_test.go | 2 ++ backend/testing.go | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/backend/remote-state/pg/backend_state.go b/backend/remote-state/pg/backend_state.go index 1cbdc5b6c..fcf3d9795 100644 --- a/backend/remote-state/pg/backend_state.go +++ b/backend/remote-state/pg/backend_state.go @@ -10,14 +10,16 @@ import ( ) func (b *Backend) Workspaces() ([]string, error) { - query := `SELECT name FROM %s.%s ORDER BY name` + query := `SELECT name FROM %s.%s WHERE name != 'default' ORDER BY name` rows, err := b.db.Query(fmt.Sprintf(query, b.schemaName, statesTableName)) if err != nil { return nil, err } defer rows.Close() - var result []string + result := []string{ + backend.DefaultStateName, + } for rows.Next() { var name string diff --git a/backend/remote-state/pg/backend_test.go b/backend/remote-state/pg/backend_test.go index 19544cf57..b6a672634 100644 --- a/backend/remote-state/pg/backend_test.go +++ b/backend/remote-state/pg/backend_test.go @@ -71,6 +71,8 @@ func TestBackendConfig(t *testing.T) { if c.Name != backend.DefaultStateName { t.Fatal("RemoteClient name is not configured") } + + backend.TestBackendStates(t, b) } func TestBackendConfigSkipSchema(t *testing.T) { diff --git a/backend/testing.go b/backend/testing.go index aea2508c4..88499b59e 100644 --- a/backend/testing.go +++ b/backend/testing.go @@ -94,7 +94,7 @@ func TestBackendStates(t *testing.T, b Backend) { // Test it starts with only the default if !noDefault && (len(workspaces) != 1 || workspaces[0] != DefaultStateName) { - t.Fatalf("should only default to start: %#v", workspaces) + t.Fatalf("should only have the default workspace to start: %#v", workspaces) } // Create a couple states