Skip to content

Commit

Permalink
modify username and roles for postgres flex
Browse files Browse the repository at this point in the history
  • Loading branch information
Dean Oren committed Feb 15, 2023
1 parent e26ff9c commit 58379ea
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
10 changes: 3 additions & 7 deletions stackit/internal/resources/postgres-flex/instance/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down

0 comments on commit 58379ea

Please sign in to comment.