From 24f6fe6947b06f662dd4406358cc562866af2552 Mon Sep 17 00:00:00 2001 From: Modular Magician Date: Wed, 21 Aug 2024 20:15:48 +0000 Subject: [PATCH] Merge pull request #11513 from c2thorn/sync-main-FEATURE-BRANCH-6.0.0 Sync main feature branch 6.0.0 - 8/21 [upstream:5041f537b74e607bc605f1fc5cb1b89f428f2a6f] Signed-off-by: Modular Magician --- go.mod | 2 +- go.sum | 4 +- .../vmwareengine_private_cloud.go | 47 +++++++++++++++++++ 3 files changed, 50 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 952817130..7f3efdafb 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/hashicorp/hcl/v2 v2.20.1 github.com/hashicorp/terraform-json v0.22.1 github.com/hashicorp/terraform-plugin-sdk/v2 v2.33.0 - github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20240821173553-e3761478592e + github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20240821201254-3e09a697a4c2 github.com/mitchellh/go-homedir v1.1.0 // indirect github.com/pkg/errors v0.9.1 github.com/stretchr/testify v1.9.0 diff --git a/go.sum b/go.sum index 7d20f2454..85e6059f4 100644 --- a/go.sum +++ b/go.sum @@ -190,8 +190,8 @@ github.com/hashicorp/terraform-plugin-sdk/v2 v2.33.0 h1:qHprzXy/As0rxedphECBEQAh github.com/hashicorp/terraform-plugin-sdk/v2 v2.33.0/go.mod h1:H+8tjs9TjV2w57QFVSMBQacf8k/E1XwLXGCARgViC6A= github.com/hashicorp/terraform-plugin-testing v1.5.1 h1:T4aQh9JAhmWo4+t1A7x+rnxAJHCDIYW9kXyo4sVO92c= github.com/hashicorp/terraform-plugin-testing v1.5.1/go.mod h1:dg8clO6K59rZ8w9EshBmDp1CxTIPu3yA4iaDpX1h5u0= -github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20240821173553-e3761478592e h1:Y1geCtACMUmKUH6FXc9hn25kB/C+B0yJOLEzUjHPmDY= -github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20240821173553-e3761478592e/go.mod h1:IkI2dOHongwQ2RIUyitBH4rDJvYBuClAoFCheApCTpY= +github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20240821201254-3e09a697a4c2 h1:+1U7hnwUKjwCqNF7VWWiGR4sAcWp6pYjGTPRTyAHY7M= +github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20240821201254-3e09a697a4c2/go.mod h1:IkI2dOHongwQ2RIUyitBH4rDJvYBuClAoFCheApCTpY= github.com/hashicorp/terraform-registry-address v0.2.3 h1:2TAiKJ1A3MAkZlH1YI/aTVcLZRu7JseiXNRHbOAyoTI= github.com/hashicorp/terraform-registry-address v0.2.3/go.mod h1:lFHA76T8jfQteVfT7caREqguFrW3c4MFSPhZB7HHgUM= github.com/hashicorp/terraform-svchost v0.1.1 h1:EZZimZ1GxdqFRinZ1tpJwVxxt49xc/S52uzrw4x0jKQ= diff --git a/tfplan2cai/converters/google/resources/services/vmwareengine/vmwareengine_private_cloud.go b/tfplan2cai/converters/google/resources/services/vmwareengine/vmwareengine_private_cloud.go index af9868e4c..e3b4c1b25 100644 --- a/tfplan2cai/converters/google/resources/services/vmwareengine/vmwareengine_private_cloud.go +++ b/tfplan2cai/converters/google/resources/services/vmwareengine/vmwareengine_private_cloud.go @@ -19,6 +19,7 @@ import ( "reflect" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "google.golang.org/api/googleapi" "github.com/GoogleCloudPlatform/terraform-google-conversion/v5/tfplan2cai/converters/google/resources/cai" "github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource" @@ -59,6 +60,52 @@ func isMultiNodePrivateCloud(d *schema.ResourceData) bool { return false } +func isPrivateCloudInDeletedState(config *transport_tpg.Config, d *schema.ResourceData, billingProject string, userAgent string) (bool, error) { + baseurl, err := tpgresource.ReplaceVars(d, config, "{{VmwareengineBasePath}}projects/{{project}}/locations/{{location}}/privateClouds/{{name}}") + if err != nil { + return false, err + } + res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ + Config: config, + Method: "GET", + Project: billingProject, + RawURL: baseurl, + UserAgent: userAgent, + }) + if err != nil { + if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 { + log.Printf("[DEBUG] No existing private cloud found") + return false, nil + } + return false, err + } + // if resource exists but is marked for deletion + v, ok := res["state"] + if ok && v.(string) == "DELETED" { + log.Printf("[DEBUG] The Private cloud exists and is marked for deletion.") + return true, nil + } + return false, nil +} + +// Check if private cloud is absent or if it exists in a deleted state. +func pollCheckForPrivateCloudAbsence(resp map[string]interface{}, respErr error) transport_tpg.PollResult { + if respErr != nil { + if transport_tpg.IsGoogleApiErrorWithCode(respErr, 404) { + return transport_tpg.SuccessPollResult() + } + return transport_tpg.ErrorPollResult(respErr) + } + // if resource exists but is marked for deletion + log.Printf("[DEBUG] Fetching state of the private cloud.") + v, ok := resp["state"] + if ok && v.(string) == "DELETED" { + log.Printf("[DEBUG] The Private cloud has been successfully marked for delayed deletion.") + return transport_tpg.SuccessPollResult() + } + return transport_tpg.PendingStatusPollResult("found") +} + const VmwareenginePrivateCloudAssetType string = "vmwareengine.googleapis.com/PrivateCloud" func ResourceConverterVmwareenginePrivateCloud() cai.ResourceConverter {