Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Cloud-Databases): RR & PITR Groups Attribute for Source Formations with Multiple Members #5862

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 34 additions & 3 deletions ibm/service/database/resource_ibm_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -1186,24 +1186,37 @@ 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
break
}
}

if remoteLeader, ok := d.GetOk("remote_leader_id"); ok {
if remoteLeaderStr, ok := remoteLeader.(string); ok {
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)

}
}

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 {
Expand Down Expand Up @@ -2964,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)

Expand Down
Loading