From ead2863b4e7f1c49d14262eb0601650bf3928faa Mon Sep 17 00:00:00 2001 From: Omar Ibrahim Date: Tue, 10 Dec 2024 08:50:31 -0500 Subject: [PATCH 1/2] fixed read replica issue --- ibm/service/database/resource_ibm_database.go | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/ibm/service/database/resource_ibm_database.go b/ibm/service/database/resource_ibm_database.go index 150b5b3ce2..6471325451 100644 --- a/ibm/service/database/resource_ibm_database.go +++ b/ibm/service/database/resource_ibm_database.go @@ -141,7 +141,6 @@ func ResourceIBMDatabaseInstance() *schema.Resource { resourceIBMDatabaseInstanceDiff, validateGroupsDiff, validateUsersDiff, - validateVersionDiff, validateRemoteLeaderIDDiff), Importer: &schema.ResourceImporter{}, @@ -1187,6 +1186,7 @@ func resourceIBMDatabaseInstanceCreate(context context.Context, d *schema.Resour if group, ok := d.GetOk("group"); ok { groups := expandGroups(group.(*schema.Set).List()) var memberGroup *Group + var nodeCount = initialNodeCount for _, g := range groups { if g.ID == "member" { memberGroup = g @@ -1194,17 +1194,35 @@ func resourceIBMDatabaseInstanceCreate(context context.Context, d *schema.Resour } } + if remoteLeader, ok := d.GetOk("remote_leader_id"); ok { + if remoteLeaderStr, ok := remoteLeader.(string); ok { + groupsResponse, _ := getGroups(remoteLeaderStr, meta) + currentGroups := normalizeGroups(groupsResponse) + + for _, g := range groups { + var currentGroup *Group + + for _, cg := range currentGroups { + if cg.ID == g.ID { + currentGroup = &cg + nodeCount = currentGroup.Members.Allocation + } + } + } + } + } + if memberGroup != nil { if memberGroup.Memory != nil { - params.Memory = memberGroup.Memory.Allocation * initialNodeCount + params.Memory = memberGroup.Memory.Allocation * nodeCount } if memberGroup.Disk != nil { - params.Disk = memberGroup.Disk.Allocation * initialNodeCount + params.Disk = memberGroup.Disk.Allocation * nodeCount } if memberGroup.CPU != nil { - params.CPU = memberGroup.CPU.Allocation * initialNodeCount + params.CPU = memberGroup.CPU.Allocation * nodeCount } if memberGroup.HostFlavor != nil { From 915c4c28d3c8e030708c445c6879d103b6a6673c Mon Sep 17 00:00:00 2001 From: Omar Ibrahim Date: Tue, 10 Dec 2024 15:11:51 -0500 Subject: [PATCH 2/2] added fix for PITR --- ibm/service/database/resource_ibm_database.go | 36 ++++++++++++------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/ibm/service/database/resource_ibm_database.go b/ibm/service/database/resource_ibm_database.go index 64f59d4b6e..7c4bda7a1b 100644 --- a/ibm/service/database/resource_ibm_database.go +++ b/ibm/service/database/resource_ibm_database.go @@ -1196,19 +1196,13 @@ func resourceIBMDatabaseInstanceCreate(context context.Context, d *schema.Resour if remoteLeader, ok := d.GetOk("remote_leader_id"); ok { if remoteLeaderStr, ok := remoteLeader.(string); ok { - groupsResponse, _ := getGroups(remoteLeaderStr, meta) - currentGroups := normalizeGroups(groupsResponse) - - for _, g := range groups { - var currentGroup *Group + nodeCount = sourceFormationNodeCount(remoteLeaderStr, initialNodeCount, groups, meta) + } + } + if pitrLeader, ok := d.GetOk("point_in_time_recovery_deployment_id"); ok { + if pitrLeaderStr, ok := pitrLeader.(string); ok { + nodeCount = sourceFormationNodeCount(pitrLeaderStr, initialNodeCount, groups, meta) - for _, cg := range currentGroups { - if cg.ID == g.ID { - currentGroup = &cg - nodeCount = currentGroup.Members.Allocation - } - } - } } } @@ -2983,6 +2977,24 @@ func getCpuEnforcementRatios(service string, plan string, hostFlavor string, met return nil, 0, 0 } +func sourceFormationNodeCount(leaderStr string, initNodeCount int, groups []*Group, meta interface{}) (members int) { + groupsResponse, _ := getGroups(leaderStr, meta) + currentGroups := normalizeGroups(groupsResponse) + + for _, g := range groups { + var currentGroup *Group + + for _, cg := range currentGroups { + if cg.ID == g.ID { + currentGroup = &cg + return currentGroup.Members.Allocation + } + } + } + + return initNodeCount +} + func validateUsersDiff(_ context.Context, diff *schema.ResourceDiff, meta interface{}) (err error) { service := diff.Get("service").(string)