Skip to content

Commit

Permalink
Support Delayed Deletion for Vmwareengine Private Cloud (#10764)
Browse files Browse the repository at this point in the history
[upstream:b8a463edcd5a423613ca5aa1adf95f59095c2d73]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician committed Jul 10, 2024
1 parent 0b1956b commit fd32b59
Showing 1 changed file with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package vmwareengine

import (
"log"
"reflect"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand All @@ -24,10 +25,37 @@ import (
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
)

func vmwareenginePrivateCloudStandardTypeDiffSuppressFunc(_, old, new string, _ *schema.ResourceData) bool {
func vmwareenginePrivateCloudStandardTypeDiffSuppressFunc(_, old, new string, d *schema.ResourceData) bool {
if (old == "STANDARD" && new == "") || (old == "" && new == "STANDARD") {
return true
}
if isMultiNodePrivateCloud(d) && old == "TIME_LIMITED" && new == "STANDARD" {
log.Printf("[DEBUG] Multinode Private Cloud found, facilitating TYPE change to STANDARD")
return true
}
return false
}

func isMultiNodePrivateCloud(d *schema.ResourceData) bool {
nodeConfigMap := d.Get("management_cluster.0.node_type_configs").(*schema.Set).List()
totalNodeCount := 0
for _, nodeConfig := range nodeConfigMap {
configMap, ok := nodeConfig.(map[string]interface{})
if !ok {
log.Printf("[DEBUG] Invalid node configuration format for private cloud.")
continue
}
nodeCount, ok := configMap["node_count"].(int)
if !ok {
log.Printf("[DEBUG] Invalid node_count format for private cloud.")
continue
}
totalNodeCount += nodeCount
}
log.Printf("[DEBUG] The node count of the private cloud is found to be %v nodes.", totalNodeCount)
if totalNodeCount > 2 {
return true
}
return false
}

Expand Down

0 comments on commit fd32b59

Please sign in to comment.