Skip to content

Commit

Permalink
fix: Add workaround to ignore groups config when provisioning instanc…
Browse files Browse the repository at this point in the history
…e using backup CRN (#166)

* feat: add workaround for groups

* fix: if condition

---------

Co-authored-by: Jordan-Williams2 <[email protected]>
  • Loading branch information
jor2 and Jordan-Williams2 authored Nov 29, 2024
1 parent 7113b30 commit fd96468
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ locals {
# Determine if host_flavor is used
host_flavor_set = var.member_host_flavor != null ? true : false

# Determine if restore, from backup or point in time recovery
recovery_mode = var.backup_crn != null || var.pitr_id != null

# Determine what KMS service is being used for database encryption
kms_service = var.kms_key_crn != null ? (
can(regex(".*kms.*", var.kms_key_crn)) ? "kms" : (
Expand Down Expand Up @@ -82,11 +85,15 @@ resource "ibm_database" "mysql_db" {
}
}

# Workaround for https://github.ibm.com/GoldenEye/issues/issues/11359
# means that no `group` block is added when restoring from backup
# or point in time recovery

## This for_each block is NOT a loop to attach to multiple group blocks.
## This is used to conditionally add one, OR, the other group block depending on var.local.host_flavor_set
## This block is for if host_flavor IS set to specific pre-defined host sizes and not set to "multitenant"
dynamic "group" {
for_each = local.host_flavor_set && var.member_host_flavor != "multitenant" ? [1] : []
for_each = local.host_flavor_set && var.member_host_flavor != "multitenant" && !local.recovery_mode ? [1] : []
content {
group_id = "member" # Only member type is allowed for IBM Cloud Databases
host_flavor {
Expand All @@ -106,7 +113,7 @@ resource "ibm_database" "mysql_db" {

## This block is for if host_flavor IS set to "multitenant"
dynamic "group" {
for_each = local.host_flavor_set && var.member_host_flavor == "multitenant" ? [1] : []
for_each = local.host_flavor_set && var.member_host_flavor == "multitenant" && !local.recovery_mode ? [1] : []
content {
group_id = "member" # Only member type is allowed for IBM Cloud Databases
host_flavor {
Expand All @@ -132,7 +139,7 @@ resource "ibm_database" "mysql_db" {

## This block is for if host_flavor IS NOT set
dynamic "group" {
for_each = local.host_flavor_set ? [] : [1]
for_each = !local.host_flavor_set && !local.recovery_mode ? [1] : []
content {
group_id = "member" # Only member type is allowed for IBM Cloud Databases
memory {
Expand Down Expand Up @@ -192,6 +199,8 @@ resource "ibm_database" "mysql_db" {

timeouts {
create = "120m" # Extending provisioning time to 120 minutes
update = "120m"
delete = "15m"
}
}

Expand Down

0 comments on commit fd96468

Please sign in to comment.