Skip to content

Commit f588b54

Browse files
committed
fixing unnecessary diff with auto_backup_enabled in databases
1 parent 61d122e commit f588b54

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

examples/database/db_systems/resources.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,6 @@ resource "oci_database_db_home" "test_db_home" {
7777

7878
resource "oci_database_backup" "test_backup" {
7979
depends_on = ["oci_database_db_system.test_db_system"]
80-
database_id = "${data.oci_database_databases.databases.databases.0.id}"
80+
database_id = "${oci_database_db_system.test_db_system.db_home.0.database.0.id}"
8181
display_name = "FirstBackup"
8282
}

oci/database_db_home_resource.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ func (s *DatabaseDbHomeResourceCrud) mapToUpdateDatabaseDetails(fieldKeyFormat s
661661
if dbBackupConfig, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "db_backup_config")); ok {
662662
if tmpList := dbBackupConfig.([]interface{}); len(tmpList) > 0 {
663663
fieldKeyFormatNextLevel := fmt.Sprintf("%s.%d.%%s", fmt.Sprintf(fieldKeyFormat, "db_backup_config"), 0)
664-
tmp, err := s.mapToDbBackupConfig(fieldKeyFormatNextLevel)
664+
tmp, err := s.mapToUpdateDbBackupConfig(fieldKeyFormatNextLevel)
665665
if err != nil {
666666
return result, err
667667
}
@@ -706,7 +706,8 @@ func (s *DatabaseDbHomeResourceCrud) CreateDatabaseFromBackupDetailsToMap(obj *o
706706
return result
707707
}
708708

709-
func (s *DatabaseDbHomeResourceCrud) mapToDbBackupConfig(fieldKeyFormat string) (oci_database.DbBackupConfig, error) {
709+
// We cannot use the same function we use in create because the HasChanged check needed for the update to succeed interferes with the Create functionality
710+
func (s *DatabaseDbHomeResourceCrud) mapToUpdateDbBackupConfig(fieldKeyFormat string) (oci_database.DbBackupConfig, error) {
710711
result := oci_database.DbBackupConfig{}
711712

712713
// Service does not allow to update auto_backup_enabled and recovery_window_in_days at the same time so we must have the HasChanged check
@@ -723,6 +724,22 @@ func (s *DatabaseDbHomeResourceCrud) mapToDbBackupConfig(fieldKeyFormat string)
723724
return result, nil
724725
}
725726

727+
func (s *DatabaseDbHomeResourceCrud) mapToDbBackupConfig(fieldKeyFormat string) (oci_database.DbBackupConfig, error) {
728+
result := oci_database.DbBackupConfig{}
729+
730+
if autoBackupEnabled, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "auto_backup_enabled")); ok {
731+
tmp := autoBackupEnabled.(bool)
732+
result.AutoBackupEnabled = &tmp
733+
}
734+
735+
if recoveryWindowInDays, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "recovery_window_in_days")); ok {
736+
tmp := recoveryWindowInDays.(int)
737+
result.RecoveryWindowInDays = &tmp
738+
}
739+
740+
return result, nil
741+
}
742+
726743
func (s *DatabaseDbHomeResourceCrud) DbBackupConfigToMap(obj *oci_database.DbBackupConfig) map[string]interface{} {
727744
result := map[string]interface{}{}
728745

oci/database_db_system_resource.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,7 @@ func (s *DatabaseDbSystemResourceCrud) mapToUpdateDatabaseDetails(fieldKeyFormat
991991
if dbBackupConfig, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "db_backup_config")); ok {
992992
if tmpList := dbBackupConfig.([]interface{}); len(tmpList) > 0 {
993993
fieldKeyFormatNextLevel := fmt.Sprintf("%s.%d.%%s", fmt.Sprintf(fieldKeyFormat, "db_backup_config"), 0)
994-
tmp, err := s.mapToDbBackupConfig(fieldKeyFormatNextLevel)
994+
tmp, err := s.mapToUpdateDbBackupConfig(fieldKeyFormatNextLevel)
995995
if err != nil {
996996
return result, err
997997
}
@@ -1362,7 +1362,8 @@ func CreateDbHomeFromBackupDetailsToMap(obj *oci_database.CreateDbHomeFromBackup
13621362
return result
13631363
}
13641364

1365-
func (s *DatabaseDbSystemResourceCrud) mapToDbBackupConfig(fieldKeyFormat string) (oci_database.DbBackupConfig, error) {
1365+
// We cannot use the same function we use in create because the HasChanged check needed for the update to succeed interferes with the Create functionality
1366+
func (s *DatabaseDbSystemResourceCrud) mapToUpdateDbBackupConfig(fieldKeyFormat string) (oci_database.DbBackupConfig, error) {
13661367
result := oci_database.DbBackupConfig{}
13671368

13681369
// Service does not allow to update auto_backup_enabled and recovery_window_in_days at the same time so we must have the HasChanged check
@@ -1379,6 +1380,22 @@ func (s *DatabaseDbSystemResourceCrud) mapToDbBackupConfig(fieldKeyFormat string
13791380
return result, nil
13801381
}
13811382

1383+
func (s *DatabaseDbSystemResourceCrud) mapToDbBackupConfig(fieldKeyFormat string) (oci_database.DbBackupConfig, error) {
1384+
result := oci_database.DbBackupConfig{}
1385+
1386+
if autoBackupEnabled, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "auto_backup_enabled")); ok {
1387+
tmp := autoBackupEnabled.(bool)
1388+
result.AutoBackupEnabled = &tmp
1389+
}
1390+
1391+
if recoveryWindowInDays, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "recovery_window_in_days")); ok {
1392+
tmp := recoveryWindowInDays.(int)
1393+
result.RecoveryWindowInDays = &tmp
1394+
}
1395+
1396+
return result, nil
1397+
}
1398+
13821399
func DbBackupConfigToMap(obj *oci_database.DbBackupConfig) map[string]interface{} {
13831400
result := map[string]interface{}{}
13841401

0 commit comments

Comments
 (0)