Skip to content

Commit

Permalink
fix(ibm_database resource): Fix cpuEnforcement multitenant bug (IBM-C…
Browse files Browse the repository at this point in the history
…loud#5271)

* fixed cpuEnforcement multitenant bug
* added code to display error message in the event multitenant is not available for a particular db
* added validation for host_flavor
  • Loading branch information
omaraibrahim authored Apr 16, 2024
1 parent a5201f3 commit 1c24698
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
27 changes: 21 additions & 6 deletions ibm/service/database/resource_ibm_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,14 @@ func ResourceIBMDatabaseInstance() *schema.Resource {
"id": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{
"multitenant",
"b3c.4x16.encrypted",
"b3c.8x32.encrypted",
"m3c.8x64.encrypted",
"b3c.16x64.encrypted",
"b3c.32x128.encrypted",
"m3c.30x240.encrypted"}, false),
},
},
},
Expand Down Expand Up @@ -1054,8 +1062,11 @@ func getDefaultScalingGroups(_service string, _plan string, _hostFlavor string,
getDefaultScalingGroupsOptions.SetHostFlavor(_hostFlavor)
}

getDefaultScalingGroupsResponse, _, err := cloudDatabasesClient.GetDefaultScalingGroups(getDefaultScalingGroupsOptions)
getDefaultScalingGroupsResponse, response, err := cloudDatabasesClient.GetDefaultScalingGroups(getDefaultScalingGroupsOptions)
if err != nil {
if response.StatusCode == 422 {
return groups, fmt.Errorf("%s is not available on multitenant", service)
}
return groups, err
}

Expand Down Expand Up @@ -2926,10 +2937,14 @@ func validateGroupsDiff(_ context.Context, diff *schema.ResourceDiff, meta inter

tfGroups := expandGroups(group.(*schema.Set).List())

err, cpuEnforcementRatioCeiling, cpuEnforcementRatioMb := getCpuEnforcementRatios(service, plan, meta, group)
cpuEnforcementRatioCeiling, cpuEnforcementRatioMb := 0, 0

if err != nil {
return err
if memberGroup.HostFlavor != nil && memberGroup.HostFlavor.ID == "multitenant" {
err, cpuEnforcementRatioCeiling, cpuEnforcementRatioMb = getCpuEnforcementRatios(service, plan, memberGroup.HostFlavor.ID, meta, group)

if err != nil {
return err
}
}

// validate group_ids are unique
Expand Down Expand Up @@ -3010,9 +3025,9 @@ func validateGroupsDiff(_ context.Context, diff *schema.ResourceDiff, meta inter
return nil
}

func getCpuEnforcementRatios(service string, plan string, meta interface{}, group interface{}) (err error, cpuEnforcementRatioCeiling int, cpuEnforcementRatioMb int) {
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, "multitenant", meta)
defaultList, err := getDefaultScalingGroups(service, plan, hostFlavor, meta)

if err != nil {
return err, 0, 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ func testAccCheckIBMDatabaseInstanceMongoDBEnterpriseBasic(databaseResourceGroup
location = "%[3]s"
adminpassword = "password12345678"
tags = ["one:two"]
service_endpoints = "public"
group {
group_id = "member"
host_flavor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ func testAccCheckIBMDatabaseInstancePostgresBasic(databaseResourceGroup string,
plan = "standard"
location = "%[3]s"
adminpassword = "password12345678"
service_endpoints = "public"
group {
group_id = "member"
memory {
Expand Down

0 comments on commit 1c24698

Please sign in to comment.