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(ibm_database resource): Fix cpuEnforcement multitenant bug #5271

Merged
merged 4 commits into from
Apr 16, 2024

Conversation

omaraibrahim
Copy link
Collaborator

@omaraibrahim omaraibrahim commented Apr 11, 2024

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for pull request followers and do not help prioritize the request

Relates OR Closes #0000

Description

We were making calls to get the multitenant cpu_enforcement_ratios for databases that do not support multitenant. The API would reply with an error. This fix makes sure that we don't try to get the cpu_enforcement_ratios in the event that a databases is NOT multitenant.

It also enhances the way we report errors for databases that do not support multitenant.

Displays error messages if an invalid host_flavor is passed.

Examples of Fix Working

Mongodb Enterprise

data "ibm_resource_group" "group" {
  name = "default"
}

resource "ibm_database" "test_acc" {
  name              = "coolguy-mongodb-two"
  plan              = "enterprise"
  location          = "eu-gb"
  service           = "databases-for-mongodb"
  resource_group_id = data.ibm_resource_group.group.id
   group {
    group_id = "member"
  } 
}

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

EnterpriseDB

data "ibm_resource_group" "group" {
  name = "default"
}

resource "ibm_database" "test_acc" {
  name              = "coolguy-edb-two"
  plan              = "standard"
  location          = "eu-gb"
  service           = "databases-for-enterprisedb"
  resource_group_id = data.ibm_resource_group.group.id
   group {
    group_id = "member"
  } 
}

New Error Messaging

resource "ibm_database" "mongdb" {
  name              = "coolguy-mongo"
  plan              = "enterprise"
  location          = "us-south"
  service           = "databases-for-mongodb"
  resource_group_id = data.ibm_resource_group.group.id

  group {
    group_id = "member"

    host_flavor {
      id = "multitenant"      
    }
  }
}
Planning failed. Terraform encountered an error while generating this plan.

╷
│ Error: 1 error occurred:
│ 	* mongodbee is not available on multitenant

Host Flavor Validation

resource "ibm_database" "test_acc" {
  name              = "coolguy-mongodb-two"
  plan              = "enterprise"
  location          = "eu-gb"
  service           = "databases-for-mongodb"
  resource_group_id = data.ibm_resource_group.group.id
   group {
    group_id = "member"
    host_flavor {
      id = "notValid"      
    }
  } 
}
│ Error: expected group.0.host_flavor.0.id to be one of ["multitenant" "b3c.4x16.encrypted" "b3c.8x32.encrypted" "m3c.8x64.encrypted" "b3c.16x64.encrypted" "b3c.32x128.encrypted" "m3c.30x240.encrypted"], got notValid

Output from acceptance testing:

$ make testacc TEST=./ibm/service/database TESTARGS='-run=TestAccIBMDatabaseInstance_Redis_Basic'
--- PASS: TestAccIBMDatabaseInstance_Redis_Basic (1427.93s)
PASS
ok  	github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/database	1429.586s
make testacc TEST=./ibm/service/database TESTARGS='-run=TestAccIBMMongoDBEnterpriseDatabaseInstanceBasic'
--- PASS: TestAccIBMMongoDBEnterpriseDatabaseInstanceBasic (8161.14s)
PASS
ok  	github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/database	8162.930s

@@ -2926,10 +2926,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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean 0, 1 ?

@omaraibrahim omaraibrahim marked this pull request as ready for review April 14, 2024 19:34
@omaraibrahim omaraibrahim changed the title Bug: Fixed cpuEnforcement multitenant bug fix(ibm_database resource): Fix cpuEnforcement multitenant bug Apr 14, 2024
Copy link
Collaborator

@alexhemard alexhemard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@obai-1 obai-1 merged commit 1c24698 into IBM-Cloud:master Apr 16, 2024
1 check passed
hkantare pushed a commit that referenced this pull request Apr 17, 2024
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants