Skip to content

Commit

Permalink
Support Undelete for Vmwareengine Private Cloud (#11480) (#2690)
Browse files Browse the repository at this point in the history
[upstream:c52857ebf0dbeff8d8894e7e30a0a2072b7eb492]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Aug 20, 2024
1 parent 468d3ba commit f30a141
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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.20240820132713-12d957e5d57d
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20240820201731-09793e35d776
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.9.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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.20240820132713-12d957e5d57d h1:1MkbYoYGmbevKYAvlDT0HCBgIJNsjgaSjgh8T4bauUk=
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20240820132713-12d957e5d57d/go.mod h1:IkI2dOHongwQ2RIUyitBH4rDJvYBuClAoFCheApCTpY=
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20240820201731-09793e35d776 h1:V7pTMH93s/IWfTUDOgmJW13b9l6CPL8Hrk8AcSv6V2w=
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20240820201731-09793e35d776/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=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit f30a141

Please sign in to comment.