From 58379eabe1231702dae26dbfe161ee2973f551b3 Mon Sep 17 00:00:00 2001 From: Dean Oren Date: Wed, 15 Feb 2023 17:40:38 +0100 Subject: [PATCH] modify username and roles for postgres flex --- .../resources/postgres-flex/instance/actions.go | 10 +++------- .../resources/postgres-flex/instance/resource_test.go | 3 +-- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/stackit/internal/resources/postgres-flex/instance/actions.go b/stackit/internal/resources/postgres-flex/instance/actions.go index df947d1d..2c2505a6 100644 --- a/stackit/internal/resources/postgres-flex/instance/actions.go +++ b/stackit/internal/resources/postgres-flex/instance/actions.go @@ -142,14 +142,13 @@ func (r Resource) createUser(ctx context.Context, plan *Instance, d *diag.Diagno // the current API doesn't read them yet, but in later releases // this will be the way to get the default user and database credentials // the default user credentials won't change - username := "stackit" - database := "stackit" - + username := "psqluser" + roles := []string{"login", "createdb"} for maxTries := 10; maxTries >= 0; maxTries-- { c := r.client.PostgresFlex body := users.CreateUserJSONRequestBody{ - Database: &database, Username: &username, + Roles: &roles, } res, err := c.Users.CreateUserWithResponse(ctx, plan.ProjectID.ValueString(), plan.ID.ValueString(), body) if err != nil { @@ -211,9 +210,6 @@ func (r Resource) createUser(ctx context.Context, plan *Instance, d *diag.Diagno if item.Database != nil { db = *item.Database } - if db == "" { - db = database // bypass API issue - } pw := "" if item.Password != nil { pw = *item.Password diff --git a/stackit/internal/resources/postgres-flex/instance/resource_test.go b/stackit/internal/resources/postgres-flex/instance/resource_test.go index 24b6a07f..9148f452 100644 --- a/stackit/internal/resources/postgres-flex/instance/resource_test.go +++ b/stackit/internal/resources/postgres-flex/instance/resource_test.go @@ -43,8 +43,7 @@ func TestAcc_PostgresFlexInstance(t *testing.T) { resource.TestCheckResourceAttr("stackit_postgres_flex_instance.example", "storage.size", "20"), resource.TestCheckResourceAttrSet("stackit_postgres_flex_instance.example", "id"), resource.TestCheckResourceAttrSet("stackit_postgres_flex_instance.example", "user.id"), - resource.TestCheckResourceAttr("stackit_postgres_flex_instance.example", "user.username", "stackit"), - resource.TestCheckResourceAttr("stackit_postgres_flex_instance.example", "user.database", "stackit"), + resource.TestCheckResourceAttr("stackit_postgres_flex_instance.example", "user.username", "psqluser"), resource.TestCheckResourceAttrSet("stackit_postgres_flex_instance.example", "user.password"), resource.TestCheckResourceAttrSet("stackit_postgres_flex_instance.example", "user.hostname"), resource.TestCheckResourceAttrSet("stackit_postgres_flex_instance.example", "user.port"),