Skip to content

Commit cfd40cb

Browse files
sivaram-govindasamysagarp337
authored andcommitted
Bug Fix - Fix update call for password change and apply config type while moving from fixed to flex database
1 parent eba85b3 commit cfd40cb

File tree

2 files changed

+33
-10
lines changed

2 files changed

+33
-10
lines changed

internal/integrationtest/psql_db_system_test.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,8 @@ func TestPsqlDbSystemResource_basic(t *testing.T) {
267267
),
268268
},
269269

270-
// verify updates to updatable parameters
271270
/*
271+
// verify updates to updatable parameters
272272
{
273273
Config: config + compartmentIdVariableStr + flexConfigIdUVariableStr + subnetIdVariableStr + flexConfigIdVariableStr + PsqlDbSystemResourceDependencies + backupIdVariableStr + nsgIdUVariableStr +
274274
acctest.GenerateResourceFromRepresentationMap("oci_psql_db_system", "test_flex_db_system", acctest.Optional, acctest.Update, PsqlDbSystemRepresentationFlexShape),
@@ -284,8 +284,8 @@ func TestPsqlDbSystemResource_basic(t *testing.T) {
284284
},
285285
),
286286
},
287-
*/
288287
288+
*/
289289
// delete before next Create
290290
{
291291
Config: config + compartmentIdVariableStr + subnetIdVariableStr + PsqlDbSystemResourceDependencies + flexConfigIdVariableStr + backupIdVariableStr + nsgIdVariableStr,
@@ -321,6 +321,20 @@ func TestPsqlDbSystemResource_basic(t *testing.T) {
321321
),
322322
},
323323

324+
// verify update
325+
{
326+
Config: config + compartmentIdVariableStr + subnetIdVariableStr + PsqlDbSystemResourceDependencies + nsgIdVariableStr +
327+
acctest.GenerateResourceFromRepresentationMap("oci_psql_db_system", "test_db_system", acctest.Optional, acctest.Update, PsqlDbSystemRepresentation),
328+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
329+
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId),
330+
331+
func(s *terraform.State) (err error) {
332+
resId, err = acctest.FromInstanceState(s, resourceName, "id")
333+
return err
334+
},
335+
),
336+
},
337+
324338
// delete before next Create
325339
{
326340
Config: config + compartmentIdVariableStr + subnetIdVariableStr + nsgIdVariableStr + PsqlDbSystemResourceDependencies,

internal/service/psql/psql_db_system_resource.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,7 @@ func (s *PsqlDbSystemResourceCrud) Get() error {
923923

924924
func (s *PsqlDbSystemResourceCrud) Update() error {
925925

926-
if _, ok := s.D.GetOkExists("passwordDetails"); ok && s.D.HasChange("passwordDetails") {
926+
if _, ok := s.D.GetOkExists("credentials"); ok && s.D.HasChange("credentials") {
927927
err := s.ResetMasterUserPassword()
928928
if err != nil {
929929
return err
@@ -1035,6 +1035,12 @@ func (s *PsqlDbSystemResourceCrud) Update() error {
10351035

10361036
tmp := configId.(string)
10371037
configRequest.ConfigId = &tmp
1038+
1039+
if applyConfig, ok := s.D.GetOkExists("apply_config"); ok {
1040+
configRequest.ApplyConfig = oci_psql.UpdateDbConfigParamsApplyConfigEnum(applyConfig.(string))
1041+
} else {
1042+
configRequest.ApplyConfig = oci_psql.UpdateDbConfigParamsApplyConfigReload
1043+
}
10381044
request.DbConfigurationParams = &configRequest
10391045
}
10401046
}
@@ -1213,14 +1219,17 @@ func (s *PsqlDbSystemResourceCrud) ResetMasterUserPassword() error {
12131219
idTmp := s.D.Id()
12141220
request.DbSystemId = &idTmp
12151221

1216-
if passwordDetails, ok := s.D.GetOkExists("password_details"); ok {
1217-
if tmpList := passwordDetails.([]interface{}); len(tmpList) > 0 {
1218-
fieldKeyFormat := fmt.Sprintf("%s.%d.%%s", "password_details", 0)
1219-
tmp, err := s.mapToPasswordDetails(fieldKeyFormat)
1220-
if err != nil {
1221-
return err
1222+
if credentials, ok := s.D.GetOkExists("credentials"); ok && s.D.HasChange("credentials") {
1223+
if tmpList := credentials.([]interface{}); len(tmpList) > 0 {
1224+
fieldKeyFormat := fmt.Sprintf("%s.%d.%%s", "credentials", 0)
1225+
if _, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "password_details")); ok && s.D.HasChange(fmt.Sprintf(fieldKeyFormat, "password_details")) {
1226+
fieldKeyFormatNextLevel := fmt.Sprintf("%s.%d.%%s", fmt.Sprintf(fieldKeyFormat, "password_details"), 0)
1227+
tmp, err := s.mapToPasswordDetails(fieldKeyFormatNextLevel)
1228+
if err != nil {
1229+
return err
1230+
}
1231+
request.PasswordDetails = tmp
12221232
}
1223-
request.PasswordDetails = tmp
12241233
}
12251234
}
12261235

0 commit comments

Comments
 (0)