From 1c24698e53a9041f45e49d4a9cbd930d63736741 Mon Sep 17 00:00:00 2001 From: Omar Ibrahim <97538078+omaraibrahim@users.noreply.github.com> Date: Tue, 16 Apr 2024 15:00:01 -0400 Subject: [PATCH] fix(ibm_database resource): Fix cpuEnforcement multitenant bug (#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 --- ibm/service/database/resource_ibm_database.go | 27 ++++++++++++++----- ...ce_ibm_database_mongodb_enterprise_test.go | 1 + .../resource_ibm_database_postgresql_test.go | 1 + 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/ibm/service/database/resource_ibm_database.go b/ibm/service/database/resource_ibm_database.go index 6d255c9524..b5fb8e7500 100644 --- a/ibm/service/database/resource_ibm_database.go +++ b/ibm/service/database/resource_ibm_database.go @@ -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), }, }, }, @@ -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 } @@ -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 @@ -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 diff --git a/ibm/service/database/resource_ibm_database_mongodb_enterprise_test.go b/ibm/service/database/resource_ibm_database_mongodb_enterprise_test.go index b9642cb1b1..c54a2e11d4 100644 --- a/ibm/service/database/resource_ibm_database_mongodb_enterprise_test.go +++ b/ibm/service/database/resource_ibm_database_mongodb_enterprise_test.go @@ -208,6 +208,7 @@ func testAccCheckIBMDatabaseInstanceMongoDBEnterpriseBasic(databaseResourceGroup location = "%[3]s" adminpassword = "password12345678" tags = ["one:two"] + service_endpoints = "public" group { group_id = "member" host_flavor { diff --git a/ibm/service/database/resource_ibm_database_postgresql_test.go b/ibm/service/database/resource_ibm_database_postgresql_test.go index 2dd639ff58..7d11ef0837 100644 --- a/ibm/service/database/resource_ibm_database_postgresql_test.go +++ b/ibm/service/database/resource_ibm_database_postgresql_test.go @@ -416,6 +416,7 @@ func testAccCheckIBMDatabaseInstancePostgresBasic(databaseResourceGroup string, plan = "standard" location = "%[3]s" adminpassword = "password12345678" + service_endpoints = "public" group { group_id = "member" memory {