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

feat(Cloud Databases): suppress group diff if no change to allocation #5286

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
44 changes: 44 additions & 0 deletions ibm/service/database/resource_ibm_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ func ResourceIBMDatabaseInstance() *schema.Resource {
"group": {
Type: schema.TypeSet,
Optional: true,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"group_id": {
Expand Down Expand Up @@ -2961,6 +2962,8 @@ func validateGroupsDiff(_ context.Context, diff *schema.ResourceDiff, meta inter
}
}

suppressChange := true

// Get default or current group scaling values
for _, group := range tfGroups {
if group == nil {
Expand All @@ -2975,6 +2978,8 @@ func validateGroupsDiff(_ context.Context, diff *schema.ResourceDiff, meta inter
}
}

suppressChange = suppressChange && suppressGroupDiff(group, groupDefaults)

// set current nodeCount
nodeCount := groupDefaults.Members.Allocation

Expand Down Expand Up @@ -3020,11 +3025,50 @@ func validateGroupsDiff(_ context.Context, diff *schema.ResourceDiff, meta inter
}
}
}

if suppressChange {
oldGroup, _ := diff.GetChange("group")

log.Printf(
"suppressing change (%v)", oldGroup)

diff.SetNew("group", oldGroup)
}
}

return nil
}

func suppressGroupDiff(proposed *Group, current *Group) bool {
var currentMemberCount, proposedMemberCount int

currentMemberCount = current.Members.Allocation

if proposed.Members != nil {
proposedMemberCount = proposed.Members.Allocation
} else {
proposedMemberCount = currentMemberCount
}

if currentMemberCount != proposedMemberCount {
return false
}

if proposed.Memory != nil && current.Memory.Allocation != proposed.Memory.Allocation*proposedMemberCount {
return false
}

if proposed.Disk != nil && current.Disk.Allocation != proposed.Disk.Allocation*proposedMemberCount {
return false
}

if proposed.CPU != nil && current.CPU.Allocation != proposed.CPU.Allocation*proposedMemberCount {
return false
}

return true
}

func getCpuEnforcementRatios(service string, plan string, hostFlavor string, meta interface{}, group interface{}) (err error, cpuEnforcementRatioCeiling int, cpuEnforcementRatioMb int) {
var currentGroups []Group
defaultList, err := getDefaultScalingGroups(service, plan, hostFlavor, meta)
Expand Down
Loading