From 0750141a7b1c4cb3e6ad275f1c4bbb5eb779c349 Mon Sep 17 00:00:00 2001 From: Ferran Rodenas Date: Mon, 9 Sep 2024 13:33:47 -0700 Subject: [PATCH] Upgrade golangci-lint to v1.60.3 and fix linter issues Signed-off-by: Ferran Rodenas --- .github/workflows/golangci-lint.yml | 2 +- .golangci.yml | 1 - vra/data_source_region_enumeration.go | 9 +++--- vra/data_source_region_enumeration_aws.go | 4 +-- vra/data_source_region_enumeration_azure.go | 4 +-- vra/data_source_region_enumeration_gcp.go | 4 +-- vra/data_source_region_enumeration_vmc.go | 4 +-- vra/data_source_region_enumeration_vsphere.go | 4 +-- vra/resource_block_device.go | 13 +++++---- vra/resource_block_device_snapshot.go | 11 ++++---- vra/resource_cloud_account_aws.go | 10 +++---- vra/resource_cloud_account_azure.go | 10 +++---- vra/resource_cloud_account_gcp.go | 10 +++---- vra/resource_cloud_account_nsxt.go | 11 ++++---- vra/resource_cloud_account_nsxv.go | 11 ++++---- vra/resource_cloud_account_vmc.go | 10 +++---- vra/resource_cloud_account_vsphere.go | 10 +++---- vra/resource_deployment.go | 28 +++++++++---------- vra/resource_integration.go | 10 +++---- vra/resource_load_balancer.go | 10 +++---- vra/resource_machine.go | 18 ++++++------ vra/resource_network.go | 10 +++---- 22 files changed, 104 insertions(+), 100 deletions(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index acd6ea0..13be108 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -19,6 +19,6 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v3 with: - version: v1.54.2 + version: v1.60.3 args: --issues-exit-code=1 only-new-issues: true diff --git a/.golangci.yml b/.golangci.yml index 7f21bb3..244639a 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -10,7 +10,6 @@ linters: enable: - durationcheck - errcheck - - exportloopref - gofmt - goimports - gosimple diff --git a/vra/data_source_region_enumeration.go b/vra/data_source_region_enumeration.go index b72caae..8b8b096 100644 --- a/vra/data_source_region_enumeration.go +++ b/vra/data_source_region_enumeration.go @@ -2,12 +2,13 @@ package vra import ( "context" + "errors" "fmt" "strings" "time" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/vmware/vra-sdk-go/pkg/client" "github.com/vmware/vra-sdk-go/pkg/client/cloud_account" @@ -77,7 +78,7 @@ func dataSourceRegionEnumerationRead(ctx context.Context, d *schema.ResourceData return diag.FromErr(err) } - stateChangeFunc := resource.StateChangeConf{ + stateChangeFunc := retry.StateChangeConf{ Delay: 5 * time.Second, Pending: []string{models.RequestTrackerStatusINPROGRESS}, Refresh: dataSourceRegionEnumerationReadRefreshFunc(*apiClient, *enumResp.Payload.ID), @@ -106,7 +107,7 @@ func dataSourceRegionEnumerationRead(ctx context.Context, d *schema.ResourceData return nil } -func dataSourceRegionEnumerationReadRefreshFunc(apiClient client.API, id string) resource.StateRefreshFunc { +func dataSourceRegionEnumerationReadRefreshFunc(apiClient client.API, id string) retry.StateRefreshFunc { return func() (interface{}, string, error) { reqResp, err := apiClient.Request.GetRequestTracker(request.NewGetRequestTrackerParams().WithID(id)) if err != nil { @@ -116,7 +117,7 @@ func dataSourceRegionEnumerationReadRefreshFunc(apiClient client.API, id string) status := reqResp.Payload.Status switch *status { case models.RequestTrackerStatusFAILED: - return []string{""}, *status, fmt.Errorf(reqResp.Payload.Message) + return []string{""}, *status, errors.New(reqResp.Payload.Message) case models.RequestTrackerStatusINPROGRESS: return [...]string{id}, *status, nil case models.RequestTrackerStatusFINISHED: diff --git a/vra/data_source_region_enumeration_aws.go b/vra/data_source_region_enumeration_aws.go index 4c10c1d..e0b53dc 100644 --- a/vra/data_source_region_enumeration_aws.go +++ b/vra/data_source_region_enumeration_aws.go @@ -5,7 +5,7 @@ import ( "time" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/vmware/vra-sdk-go/pkg/client/cloud_account" "github.com/vmware/vra-sdk-go/pkg/models" @@ -53,7 +53,7 @@ func dataSourceRegionEnumerationAWSRead(ctx context.Context, d *schema.ResourceD return diag.FromErr(err) } - stateChangeFunc := resource.StateChangeConf{ + stateChangeFunc := retry.StateChangeConf{ Delay: 5 * time.Second, Pending: []string{models.RequestTrackerStatusINPROGRESS}, Refresh: dataSourceRegionEnumerationReadRefreshFunc(*apiClient, *enumResp.Payload.ID), diff --git a/vra/data_source_region_enumeration_azure.go b/vra/data_source_region_enumeration_azure.go index f9937e3..c4f58dd 100644 --- a/vra/data_source_region_enumeration_azure.go +++ b/vra/data_source_region_enumeration_azure.go @@ -5,7 +5,7 @@ import ( "time" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/vmware/vra-sdk-go/pkg/client/cloud_account" "github.com/vmware/vra-sdk-go/pkg/models" @@ -65,7 +65,7 @@ func dataSourceRegionEnumerationAzureRead(ctx context.Context, d *schema.Resourc return diag.FromErr(err) } - stateChangeFunc := resource.StateChangeConf{ + stateChangeFunc := retry.StateChangeConf{ Delay: 5 * time.Second, Pending: []string{models.RequestTrackerStatusINPROGRESS}, Refresh: dataSourceRegionEnumerationReadRefreshFunc(*apiClient, *enumResp.Payload.ID), diff --git a/vra/data_source_region_enumeration_gcp.go b/vra/data_source_region_enumeration_gcp.go index 8c06231..b32d4fc 100644 --- a/vra/data_source_region_enumeration_gcp.go +++ b/vra/data_source_region_enumeration_gcp.go @@ -5,7 +5,7 @@ import ( "time" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/vmware/vra-sdk-go/pkg/client/cloud_account" "github.com/vmware/vra-sdk-go/pkg/models" @@ -65,7 +65,7 @@ func dataSourceRegionEnumerationGCPRead(ctx context.Context, d *schema.ResourceD return diag.FromErr(err) } - stateChangeFunc := resource.StateChangeConf{ + stateChangeFunc := retry.StateChangeConf{ Delay: 5 * time.Second, Pending: []string{models.RequestTrackerStatusINPROGRESS}, Refresh: dataSourceRegionEnumerationReadRefreshFunc(*apiClient, *enumResp.Payload.ID), diff --git a/vra/data_source_region_enumeration_vmc.go b/vra/data_source_region_enumeration_vmc.go index e3e2ca8..c90d671 100644 --- a/vra/data_source_region_enumeration_vmc.go +++ b/vra/data_source_region_enumeration_vmc.go @@ -5,7 +5,7 @@ import ( "time" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/vmware/vra-sdk-go/pkg/client/cloud_account" "github.com/vmware/vra-sdk-go/pkg/models" @@ -90,7 +90,7 @@ func dataSourceRegionEnumerationVMCRead(ctx context.Context, d *schema.ResourceD return diag.FromErr(err) } - stateChangeFunc := resource.StateChangeConf{ + stateChangeFunc := retry.StateChangeConf{ Delay: 5 * time.Second, Pending: []string{models.RequestTrackerStatusINPROGRESS}, Refresh: dataSourceRegionEnumerationReadRefreshFunc(*apiClient, *enumResp.Payload.ID), diff --git a/vra/data_source_region_enumeration_vsphere.go b/vra/data_source_region_enumeration_vsphere.go index 6e30dec..3ee5386 100644 --- a/vra/data_source_region_enumeration_vsphere.go +++ b/vra/data_source_region_enumeration_vsphere.go @@ -8,7 +8,7 @@ import ( "github.com/vmware/vra-sdk-go/pkg/models" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) @@ -73,7 +73,7 @@ func dataSourceRegionEnumerationVsphereRead(ctx context.Context, d *schema.Resou return diag.FromErr(err) } - stateChangeFunc := resource.StateChangeConf{ + stateChangeFunc := retry.StateChangeConf{ Delay: 5 * time.Second, Pending: []string{models.RequestTrackerStatusINPROGRESS}, Refresh: dataSourceRegionEnumerationReadRefreshFunc(*apiClient, *enumResp.Payload.ID), diff --git a/vra/resource_block_device.go b/vra/resource_block_device.go index ce48ac8..d9de61b 100644 --- a/vra/resource_block_device.go +++ b/vra/resource_block_device.go @@ -2,6 +2,7 @@ package vra import ( "context" + "errors" "fmt" "log" "strings" @@ -13,7 +14,7 @@ import ( "github.com/vmware/vra-sdk-go/pkg/models" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) @@ -202,7 +203,7 @@ func resourceBlockDeviceCreate(ctx context.Context, d *schema.ResourceData, m in return diag.FromErr(err) } - stateChangeFunc := resource.StateChangeConf{ + stateChangeFunc := retry.StateChangeConf{ Delay: 5 * time.Second, Pending: []string{models.RequestTrackerStatusINPROGRESS}, Refresh: blockDeviceStateRefreshFunc(*apiClient, *createBlockDeviceCreated.Payload.ID), @@ -225,7 +226,7 @@ func resourceBlockDeviceCreate(ctx context.Context, d *schema.ResourceData, m in return resourceBlockDeviceRead(ctx, d, m) } -func blockDeviceStateRefreshFunc(apiClient client.API, id string) resource.StateRefreshFunc { +func blockDeviceStateRefreshFunc(apiClient client.API, id string) retry.StateRefreshFunc { return func() (interface{}, string, error) { ret, err := apiClient.Request.GetRequestTracker(request.NewGetRequestTrackerParams().WithID(id)) if err != nil { @@ -235,7 +236,7 @@ func blockDeviceStateRefreshFunc(apiClient client.API, id string) resource.State status := ret.Payload.Status switch *status { case models.RequestTrackerStatusFAILED: - return []string{""}, *status, fmt.Errorf(ret.Payload.Message) + return []string{""}, *status, errors.New(ret.Payload.Message) case models.RequestTrackerStatusINPROGRESS: return [...]string{id}, *status, nil case models.RequestTrackerStatusFINISHED: @@ -337,7 +338,7 @@ func resizeDisk(ctx context.Context, d *schema.ResourceData, apiClient *client.A return nil } - stateChangeFunc := resource.StateChangeConf{ + stateChangeFunc := retry.StateChangeConf{ Delay: 5 * time.Second, Pending: []string{models.RequestTrackerStatusINPROGRESS}, Refresh: blockDeviceStateRefreshFunc(*apiClient, *resizeBlockDeviceAccepted.Payload.ID), @@ -386,7 +387,7 @@ func resourceBlockDeviceDelete(ctx context.Context, d *schema.ResourceData, m in return nil } - stateChangeFunc := resource.StateChangeConf{ + stateChangeFunc := retry.StateChangeConf{ Delay: 5 * time.Second, Pending: []string{models.RequestTrackerStatusINPROGRESS}, Refresh: blockDeviceStateRefreshFunc(*apiClient, *deleteBlockDeviceAccepted.Payload.ID), diff --git a/vra/resource_block_device_snapshot.go b/vra/resource_block_device_snapshot.go index 9f07665..b22d174 100644 --- a/vra/resource_block_device_snapshot.go +++ b/vra/resource_block_device_snapshot.go @@ -2,6 +2,7 @@ package vra import ( "context" + "errors" "fmt" "log" "time" @@ -12,7 +13,7 @@ import ( "github.com/vmware/vra-sdk-go/pkg/models" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) @@ -87,7 +88,7 @@ func resourceBlockDeviceSnapshotCreate(ctx context.Context, d *schema.ResourceDa return diag.FromErr(err) } - stateChangeFunc := resource.StateChangeConf{ + stateChangeFunc := retry.StateChangeConf{ Delay: 5 * time.Second, Pending: []string{models.RequestTrackerStatusINPROGRESS}, Refresh: BlockDeviceSnapshotStateRefreshFunc(*apiClient, *createDiskSnapshotCreated.Payload.ID), @@ -112,7 +113,7 @@ func resourceBlockDeviceSnapshotCreate(ctx context.Context, d *schema.ResourceDa return resourceBlockDeviceSnapshotRead(ctx, d, m) } -func BlockDeviceSnapshotStateRefreshFunc(apiClient client.API, id string) resource.StateRefreshFunc { +func BlockDeviceSnapshotStateRefreshFunc(apiClient client.API, id string) retry.StateRefreshFunc { return func() (interface{}, string, error) { ret, err := apiClient.Request.GetRequestTracker(request.NewGetRequestTrackerParams().WithID(id)) if err != nil { @@ -122,7 +123,7 @@ func BlockDeviceSnapshotStateRefreshFunc(apiClient client.API, id string) resour status := ret.Payload.Status switch *status { case models.RequestTrackerStatusFAILED: - return []string{""}, *status, fmt.Errorf(ret.Payload.Message) + return []string{""}, *status, errors.New(ret.Payload.Message) case models.RequestTrackerStatusINPROGRESS: return [...]string{id}, *status, nil case models.RequestTrackerStatusFINISHED: @@ -220,7 +221,7 @@ func resourceBlockDeviceSnapshotDelete(ctx context.Context, d *schema.ResourceDa return nil } - stateChangeFunc := resource.StateChangeConf{ + stateChangeFunc := retry.StateChangeConf{ Delay: 5 * time.Second, Pending: []string{models.RequestTrackerStatusINPROGRESS}, Refresh: BlockDeviceSnapshotStateRefreshFunc(*apiClient, *deleteDiskSnapshotAccepted.Payload.ID), diff --git a/vra/resource_cloud_account_aws.go b/vra/resource_cloud_account_aws.go index 7e44ba6..489f339 100644 --- a/vra/resource_cloud_account_aws.go +++ b/vra/resource_cloud_account_aws.go @@ -13,7 +13,7 @@ import ( "github.com/vmware/vra-sdk-go/pkg/models" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) @@ -116,7 +116,7 @@ func resourceCloudAccountAWSCreate(ctx context.Context, d *schema.ResourceData, return diag.FromErr(err) } - stateChangeFunc := resource.StateChangeConf{ + stateChangeFunc := retry.StateChangeConf{ Delay: 5 * time.Second, Pending: []string{models.RequestTrackerStatusINPROGRESS}, Refresh: resourceCloudAccountAWSStateRefreshFunc(*apiClient, *createResp.Payload.ID), @@ -201,7 +201,7 @@ func resourceCloudAccountAWSUpdate(ctx context.Context, d *schema.ResourceData, return diag.FromErr(err) } - stateChangeFunc := resource.StateChangeConf{ + stateChangeFunc := retry.StateChangeConf{ Delay: 5 * time.Second, Pending: []string{models.RequestTrackerStatusINPROGRESS}, Refresh: resourceCloudAccountAWSStateRefreshFunc(*apiClient, *updateResp.Payload.ID), @@ -230,7 +230,7 @@ func resourceCloudAccountAWSDelete(_ context.Context, d *schema.ResourceData, m return nil } -func resourceCloudAccountAWSStateRefreshFunc(apiClient client.API, id string) resource.StateRefreshFunc { +func resourceCloudAccountAWSStateRefreshFunc(apiClient client.API, id string) retry.StateRefreshFunc { return func() (interface{}, string, error) { ret, err := apiClient.Request.GetRequestTracker(request.NewGetRequestTrackerParams().WithID(id)) if err != nil { @@ -240,7 +240,7 @@ func resourceCloudAccountAWSStateRefreshFunc(apiClient client.API, id string) re status := ret.Payload.Status switch *status { case models.RequestTrackerStatusFAILED: - return []string{""}, *status, fmt.Errorf(ret.Payload.Message) + return []string{""}, *status, errors.New(ret.Payload.Message) case models.RequestTrackerStatusINPROGRESS: return [...]string{id}, *status, nil case models.RequestTrackerStatusFINISHED: diff --git a/vra/resource_cloud_account_azure.go b/vra/resource_cloud_account_azure.go index ec3e637..29992eb 100644 --- a/vra/resource_cloud_account_azure.go +++ b/vra/resource_cloud_account_azure.go @@ -13,7 +13,7 @@ import ( "github.com/vmware/vra-sdk-go/pkg/models" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) @@ -128,7 +128,7 @@ func resourceCloudAccountAzureCreate(ctx context.Context, d *schema.ResourceData return diag.FromErr(err) } - stateChangeFunc := resource.StateChangeConf{ + stateChangeFunc := retry.StateChangeConf{ Delay: 5 * time.Second, Pending: []string{models.RequestTrackerStatusINPROGRESS}, Refresh: resourceCloudAccountAzureStateRefreshFunc(*apiClient, *createResp.Payload.ID), @@ -215,7 +215,7 @@ func resourceCloudAccountAzureUpdate(ctx context.Context, d *schema.ResourceData return diag.FromErr(err) } - stateChangeFunc := resource.StateChangeConf{ + stateChangeFunc := retry.StateChangeConf{ Delay: 5 * time.Second, Pending: []string{models.RequestTrackerStatusINPROGRESS}, Refresh: resourceCloudAccountAzureStateRefreshFunc(*apiClient, *updateResp.Payload.ID), @@ -243,7 +243,7 @@ func resourceCloudAccountAzureDelete(_ context.Context, d *schema.ResourceData, return nil } -func resourceCloudAccountAzureStateRefreshFunc(apiClient client.API, id string) resource.StateRefreshFunc { +func resourceCloudAccountAzureStateRefreshFunc(apiClient client.API, id string) retry.StateRefreshFunc { return func() (interface{}, string, error) { ret, err := apiClient.Request.GetRequestTracker(request.NewGetRequestTrackerParams().WithID(id)) if err != nil { @@ -253,7 +253,7 @@ func resourceCloudAccountAzureStateRefreshFunc(apiClient client.API, id string) status := ret.Payload.Status switch *status { case models.RequestTrackerStatusFAILED: - return []string{""}, *status, fmt.Errorf(ret.Payload.Message) + return []string{""}, *status, errors.New(ret.Payload.Message) case models.RequestTrackerStatusINPROGRESS: return [...]string{id}, *status, nil case models.RequestTrackerStatusFINISHED: diff --git a/vra/resource_cloud_account_gcp.go b/vra/resource_cloud_account_gcp.go index c21ce54..4e5fa79 100644 --- a/vra/resource_cloud_account_gcp.go +++ b/vra/resource_cloud_account_gcp.go @@ -13,7 +13,7 @@ import ( "github.com/vmware/vra-sdk-go/pkg/models" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) @@ -128,7 +128,7 @@ func resourceCloudAccountGCPCreate(ctx context.Context, d *schema.ResourceData, return diag.FromErr(err) } - stateChangeFunc := resource.StateChangeConf{ + stateChangeFunc := retry.StateChangeConf{ Delay: 5 * time.Second, Pending: []string{models.RequestTrackerStatusINPROGRESS}, Refresh: resourceCloudAccountGCPStateRefreshFunc(*apiClient, *createResp.Payload.ID), @@ -215,7 +215,7 @@ func resourceCloudAccountGCPUpdate(ctx context.Context, d *schema.ResourceData, return diag.FromErr(err) } - stateChangeFunc := resource.StateChangeConf{ + stateChangeFunc := retry.StateChangeConf{ Delay: 5 * time.Second, Pending: []string{models.RequestTrackerStatusINPROGRESS}, Refresh: resourceCloudAccountGCPStateRefreshFunc(*apiClient, *updateResp.Payload.ID), @@ -243,7 +243,7 @@ func resourceCloudAccountGCPDelete(_ context.Context, d *schema.ResourceData, m return nil } -func resourceCloudAccountGCPStateRefreshFunc(apiClient client.API, id string) resource.StateRefreshFunc { +func resourceCloudAccountGCPStateRefreshFunc(apiClient client.API, id string) retry.StateRefreshFunc { return func() (interface{}, string, error) { ret, err := apiClient.Request.GetRequestTracker(request.NewGetRequestTrackerParams().WithID(id)) if err != nil { @@ -253,7 +253,7 @@ func resourceCloudAccountGCPStateRefreshFunc(apiClient client.API, id string) re status := ret.Payload.Status switch *status { case models.RequestTrackerStatusFAILED: - return []string{""}, *status, fmt.Errorf(ret.Payload.Message) + return []string{""}, *status, errors.New(ret.Payload.Message) case models.RequestTrackerStatusINPROGRESS: return [...]string{id}, *status, nil case models.RequestTrackerStatusFINISHED: diff --git a/vra/resource_cloud_account_nsxt.go b/vra/resource_cloud_account_nsxt.go index 614104b..845ff61 100644 --- a/vra/resource_cloud_account_nsxt.go +++ b/vra/resource_cloud_account_nsxt.go @@ -2,6 +2,7 @@ package vra import ( "context" + "errors" "fmt" "strings" "time" @@ -12,7 +13,7 @@ import ( "github.com/vmware/vra-sdk-go/pkg/models" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) @@ -126,7 +127,7 @@ func resourceCloudAccountNSXTCreate(ctx context.Context, d *schema.ResourceData, return diag.FromErr(err) } - stateChangeFunc := resource.StateChangeConf{ + stateChangeFunc := retry.StateChangeConf{ Delay: 5 * time.Second, Pending: []string{models.RequestTrackerStatusINPROGRESS}, Refresh: resourceCloudAccountNSXTStateRefreshFunc(*apiClient, *createResp.Payload.ID), @@ -204,7 +205,7 @@ func resourceCloudAccountNSXTUpdate(ctx context.Context, d *schema.ResourceData, return diag.FromErr(err) } - stateChangeFunc := resource.StateChangeConf{ + stateChangeFunc := retry.StateChangeConf{ Delay: 5 * time.Second, Pending: []string{models.RequestTrackerStatusINPROGRESS}, Refresh: resourceCloudAccountNSXTStateRefreshFunc(*apiClient, *updateResp.Payload.ID), @@ -232,7 +233,7 @@ func resourceCloudAccountNSXTDelete(_ context.Context, d *schema.ResourceData, m return nil } -func resourceCloudAccountNSXTStateRefreshFunc(apiClient client.API, id string) resource.StateRefreshFunc { +func resourceCloudAccountNSXTStateRefreshFunc(apiClient client.API, id string) retry.StateRefreshFunc { return func() (interface{}, string, error) { ret, err := apiClient.Request.GetRequestTracker(request.NewGetRequestTrackerParams().WithID(id)) if err != nil { @@ -242,7 +243,7 @@ func resourceCloudAccountNSXTStateRefreshFunc(apiClient client.API, id string) r status := ret.Payload.Status switch *status { case models.RequestTrackerStatusFAILED: - return []string{""}, *status, fmt.Errorf(ret.Payload.Message) + return []string{""}, *status, errors.New(ret.Payload.Message) case models.RequestTrackerStatusINPROGRESS: return [...]string{id}, *status, nil case models.RequestTrackerStatusFINISHED: diff --git a/vra/resource_cloud_account_nsxv.go b/vra/resource_cloud_account_nsxv.go index 6a8f507..344de9b 100644 --- a/vra/resource_cloud_account_nsxv.go +++ b/vra/resource_cloud_account_nsxv.go @@ -2,6 +2,7 @@ package vra import ( "context" + "errors" "fmt" "strings" "time" @@ -12,7 +13,7 @@ import ( "github.com/vmware/vra-sdk-go/pkg/models" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) @@ -109,7 +110,7 @@ func resourceCloudAccountNSXVCreate(ctx context.Context, d *schema.ResourceData, return diag.FromErr(err) } - stateChangeFunc := resource.StateChangeConf{ + stateChangeFunc := retry.StateChangeConf{ Delay: 5 * time.Second, Pending: []string{models.RequestTrackerStatusINPROGRESS}, Refresh: resourceCloudAccountNSXVStateRefreshFunc(*apiClient, *createResp.Payload.ID), @@ -184,7 +185,7 @@ func resourceCloudAccountNSXVUpdate(ctx context.Context, d *schema.ResourceData, return diag.FromErr(err) } - stateChangeFunc := resource.StateChangeConf{ + stateChangeFunc := retry.StateChangeConf{ Delay: 5 * time.Second, Pending: []string{models.RequestTrackerStatusINPROGRESS}, Refresh: resourceCloudAccountNSXVStateRefreshFunc(*apiClient, *updateResp.Payload.ID), @@ -212,7 +213,7 @@ func resourceCloudAccountNSXVDelete(_ context.Context, d *schema.ResourceData, m return nil } -func resourceCloudAccountNSXVStateRefreshFunc(apiClient client.API, id string) resource.StateRefreshFunc { +func resourceCloudAccountNSXVStateRefreshFunc(apiClient client.API, id string) retry.StateRefreshFunc { return func() (interface{}, string, error) { ret, err := apiClient.Request.GetRequestTracker(request.NewGetRequestTrackerParams().WithID(id)) if err != nil { @@ -222,7 +223,7 @@ func resourceCloudAccountNSXVStateRefreshFunc(apiClient client.API, id string) r status := ret.Payload.Status switch *status { case models.RequestTrackerStatusFAILED: - return []string{""}, *status, fmt.Errorf(ret.Payload.Message) + return []string{""}, *status, errors.New(ret.Payload.Message) case models.RequestTrackerStatusINPROGRESS: return [...]string{id}, *status, nil case models.RequestTrackerStatusFINISHED: diff --git a/vra/resource_cloud_account_vmc.go b/vra/resource_cloud_account_vmc.go index dc381d6..984bce2 100644 --- a/vra/resource_cloud_account_vmc.go +++ b/vra/resource_cloud_account_vmc.go @@ -13,7 +13,7 @@ import ( "github.com/vmware/vra-sdk-go/pkg/models" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) @@ -147,7 +147,7 @@ func resourceCloudAccountVMCCreate(ctx context.Context, d *schema.ResourceData, return diag.FromErr(err) } - stateChangeFunc := resource.StateChangeConf{ + stateChangeFunc := retry.StateChangeConf{ Delay: 5 * time.Second, Pending: []string{models.RequestTrackerStatusINPROGRESS}, Refresh: resourceCloudAccountVMCStateRefreshFunc(*apiClient, *createResp.Payload.ID), @@ -237,7 +237,7 @@ func resourceCloudAccountVMCUpdate(ctx context.Context, d *schema.ResourceData, return diag.FromErr(err) } - stateChangeFunc := resource.StateChangeConf{ + stateChangeFunc := retry.StateChangeConf{ Delay: 5 * time.Second, Pending: []string{models.RequestTrackerStatusINPROGRESS}, Refresh: resourceCloudAccountVMCStateRefreshFunc(*apiClient, *updateResp.Payload.ID), @@ -265,7 +265,7 @@ func resourceCloudAccountVMCDelete(_ context.Context, d *schema.ResourceData, m return nil } -func resourceCloudAccountVMCStateRefreshFunc(apiClient client.API, id string) resource.StateRefreshFunc { +func resourceCloudAccountVMCStateRefreshFunc(apiClient client.API, id string) retry.StateRefreshFunc { return func() (interface{}, string, error) { ret, err := apiClient.Request.GetRequestTracker(request.NewGetRequestTrackerParams().WithID(id)) if err != nil { @@ -275,7 +275,7 @@ func resourceCloudAccountVMCStateRefreshFunc(apiClient client.API, id string) re status := ret.Payload.Status switch *status { case models.RequestTrackerStatusFAILED: - return []string{""}, *status, fmt.Errorf(ret.Payload.Message) + return []string{""}, *status, errors.New(ret.Payload.Message) case models.RequestTrackerStatusINPROGRESS: return [...]string{id}, *status, nil case models.RequestTrackerStatusFINISHED: diff --git a/vra/resource_cloud_account_vsphere.go b/vra/resource_cloud_account_vsphere.go index afe2b23..a180053 100644 --- a/vra/resource_cloud_account_vsphere.go +++ b/vra/resource_cloud_account_vsphere.go @@ -13,7 +13,7 @@ import ( "github.com/vmware/vra-sdk-go/pkg/models" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) @@ -152,7 +152,7 @@ func resourceCloudAccountVsphereCreate(ctx context.Context, d *schema.ResourceDa return diag.FromErr(err) } - stateChangeFunc := resource.StateChangeConf{ + stateChangeFunc := retry.StateChangeConf{ Delay: 5 * time.Second, Pending: []string{models.RequestTrackerStatusINPROGRESS}, Refresh: resourceCloudAccountVsphereStateRefreshFunc(*apiClient, *createResp.Payload.ID), @@ -253,7 +253,7 @@ func resourceCloudAccountVsphereUpdate(ctx context.Context, d *schema.ResourceDa return diag.FromErr(err) } - stateChangeFunc := resource.StateChangeConf{ + stateChangeFunc := retry.StateChangeConf{ Delay: 5 * time.Second, Pending: []string{models.RequestTrackerStatusINPROGRESS}, Refresh: resourceCloudAccountVsphereStateRefreshFunc(*apiClient, *updateResp.Payload.ID), @@ -281,7 +281,7 @@ func resourceCloudAccountVsphereDelete(_ context.Context, d *schema.ResourceData return nil } -func resourceCloudAccountVsphereStateRefreshFunc(apiClient client.API, id string) resource.StateRefreshFunc { +func resourceCloudAccountVsphereStateRefreshFunc(apiClient client.API, id string) retry.StateRefreshFunc { return func() (interface{}, string, error) { ret, err := apiClient.Request.GetRequestTracker(request.NewGetRequestTrackerParams().WithID(id)) if err != nil { @@ -291,7 +291,7 @@ func resourceCloudAccountVsphereStateRefreshFunc(apiClient client.API, id string status := ret.Payload.Status switch *status { case models.RequestTrackerStatusFAILED: - return []string{""}, *status, fmt.Errorf(ret.Payload.Message) + return []string{""}, *status, errors.New(ret.Payload.Message) case models.RequestTrackerStatusINPROGRESS: return [...]string{id}, *status, nil case models.RequestTrackerStatusFINISHED: diff --git a/vra/resource_deployment.go b/vra/resource_deployment.go index 32cf18a..c9daf59 100644 --- a/vra/resource_deployment.go +++ b/vra/resource_deployment.go @@ -13,7 +13,7 @@ import ( "github.com/go-openapi/strfmt" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/vmware/vra-sdk-go/pkg/client" "github.com/vmware/vra-sdk-go/pkg/client/blueprint" @@ -342,7 +342,7 @@ func resourceDeploymentCreate(ctx context.Context, d *schema.ResourceData, m int log.Printf("Finished requesting vra_deployment '%s' from blueprint %s", d.Get("name"), blueprintID) } - stateChangeFunc := resource.StateChangeConf{ + stateChangeFunc := retry.StateChangeConf{ Delay: 5 * time.Second, Pending: []string{models.DeploymentStatusCREATEINPROGRESS, models.DeploymentStatusUPDATEINPROGRESS}, Refresh: deploymentStatusRefreshFunc(*apiClient, d.Id()), @@ -483,7 +483,7 @@ func resourceDeploymentUpdate(ctx context.Context, d *schema.ResourceData, m int } } - stateChangeFunc := resource.StateChangeConf{ + stateChangeFunc := retry.StateChangeConf{ Delay: 5 * time.Second, Pending: []string{models.DeploymentStatusCREATEINPROGRESS, models.DeploymentStatusUPDATEINPROGRESS}, Refresh: deploymentStatusRefreshFunc(*apiClient, d.Id()), @@ -525,7 +525,7 @@ func resourceDeploymentDelete(ctx context.Context, d *schema.ResourceData, m int log.Printf("Requested for deleting the vra_deployment resource with name %s", d.Get("name")) - stateChangeFunc := resource.StateChangeConf{ + stateChangeFunc := retry.StateChangeConf{ Delay: 5 * time.Second, Pending: []string{reflect.TypeOf((*deployments.GetDeploymentByIDV3UsingGETOK)(nil)).String()}, Refresh: deploymentDeleteStatusRefreshFunc(*apiClient, d.Id()), @@ -690,7 +690,7 @@ func getBlueprintSchema(apiClient *client.API, blueprintID string, blueprintVers return blueprintInputsSchema, nil } -func deploymentStatusRefreshFunc(apiClient client.API, id string) resource.StateRefreshFunc { +func deploymentStatusRefreshFunc(apiClient client.API, id string) retry.StateRefreshFunc { return func() (interface{}, string, error) { ret, err := apiClient.Deployments.GetDeploymentByIDV3UsingGET( deployments.NewGetDeploymentByIDV3UsingGETParams(). @@ -709,7 +709,7 @@ func deploymentStatusRefreshFunc(apiClient client.API, id string) resource.State deploymentID := ret.Payload.ID return deploymentID.String(), status, nil case models.DeploymentStatusCREATEFAILED, models.DeploymentStatusUPDATEFAILED: - return ret.Payload.ID.String(), status, fmt.Errorf(ret.Payload.LastRequest.Details) + return ret.Payload.ID.String(), status, errors.New(ret.Payload.LastRequest.Details) default: return [...]string{id}, ret.Error(), fmt.Errorf("deploymentStatusRefreshFunc: unknown status %v", status) } @@ -809,7 +809,7 @@ func updateDeploymentWithNewBlueprint(ctx context.Context, d *schema.ResourceDat return diag.Errorf("failed to request update to existing deployment. status: %v, message: %v", status, failureMessage) } - stateChangeFunc := resource.StateChangeConf{ + stateChangeFunc := retry.StateChangeConf{ Delay: 5 * time.Second, Pending: []string{models.DeploymentStatusCREATEINPROGRESS, models.DeploymentStatusUPDATEINPROGRESS}, Refresh: deploymentStatusRefreshFunc(*apiClient, deploymentID), @@ -1144,7 +1144,7 @@ func runAction(ctx context.Context, d *schema.ResourceData, apiClient *client.AP requestID := resp.GetPayload().ID - stateChangeFunc := resource.StateChangeConf{ + stateChangeFunc := retry.StateChangeConf{ Delay: 5 * time.Second, Pending: []string{models.RequestStatusPENDING, models.RequestStatusINITIALIZATION, models.RequestStatusCHECKINGAPPROVAL, models.RequestStatusAPPROVALPENDING, models.RequestStatusINPROGRESS}, Refresh: deploymentActionStatusRefreshFunc(*apiClient, deploymentUUID, requestID), @@ -1158,7 +1158,7 @@ func runAction(ctx context.Context, d *schema.ResourceData, apiClient *client.AP return nil } -func deploymentActionStatusRefreshFunc(apiClient client.API, deploymentUUID strfmt.UUID, _ strfmt.UUID) resource.StateRefreshFunc { +func deploymentActionStatusRefreshFunc(apiClient client.API, deploymentUUID strfmt.UUID, _ strfmt.UUID) retry.StateRefreshFunc { return func() (interface{}, string, error) { ret, err := apiClient.Deployments.GetDeploymentByIDV3UsingGET( deployments.NewGetDeploymentByIDV3UsingGETParams(). @@ -1174,9 +1174,9 @@ func deploymentActionStatusRefreshFunc(apiClient client.API, deploymentUUID strf case models.RequestStatusPENDING, models.RequestStatusINITIALIZATION, models.RequestStatusCHECKINGAPPROVAL, models.RequestStatusAPPROVALPENDING, models.RequestStatusINPROGRESS, models.RequestStatusCOMPLETION: return [...]string{deploymentUUID.String()}, status, nil case models.RequestStatusAPPROVALREJECTED, models.RequestStatusABORTED: - return []string{""}, status, fmt.Errorf(ret.Error()) + return []string{""}, status, errors.New(ret.Error()) case models.RequestStatusFAILED: - return [...]string{deploymentUUID.String()}, status, fmt.Errorf(ret.Payload.LastRequest.Details) + return [...]string{deploymentUUID.String()}, status, errors.New(ret.Payload.LastRequest.Details) case models.RequestStatusSUCCESSFUL: deploymentID := ret.Payload.ID return deploymentID.String(), status, nil @@ -1186,7 +1186,7 @@ func deploymentActionStatusRefreshFunc(apiClient client.API, deploymentUUID strf } } -func deploymentDeleteStatusRefreshFunc(apiClient client.API, id string) resource.StateRefreshFunc { +func deploymentDeleteStatusRefreshFunc(apiClient client.API, id string) retry.StateRefreshFunc { return func() (interface{}, string, error) { ret, err := apiClient.Deployments.GetDeploymentByIDV3UsingGET( deployments.NewGetDeploymentByIDV3UsingGETParams(). @@ -1198,7 +1198,7 @@ func deploymentDeleteStatusRefreshFunc(apiClient client.API, id string) resource case *deployments.GetDeploymentByIDV3UsingGETNotFound: return "", reflect.TypeOf(err).String(), nil default: - return [...]string{id}, reflect.TypeOf(err).String(), fmt.Errorf(ret.Error()) + return [...]string{id}, reflect.TypeOf(err).String(), errors.New(ret.Error()) } } @@ -1209,7 +1209,7 @@ func deploymentDeleteStatusRefreshFunc(apiClient client.API, id string) resource case models.DeploymentStatusDELETESUCCESSFUL: return [...]string{id}, reflect.TypeOf(ret).String(), nil case models.DeploymentStatusDELETEFAILED: - return [...]string{id}, reflect.TypeOf(ret).String(), fmt.Errorf(ret.Payload.LastRequest.Details) + return [...]string{id}, reflect.TypeOf(ret).String(), errors.New(ret.Payload.LastRequest.Details) default: return [...]string{id}, reflect.TypeOf(ret).String(), fmt.Errorf("deploymentStatusRefreshFunc: unknown status %v", status) } diff --git a/vra/resource_integration.go b/vra/resource_integration.go index ffbe5f3..129ec05 100644 --- a/vra/resource_integration.go +++ b/vra/resource_integration.go @@ -13,7 +13,7 @@ import ( "github.com/vmware/vra-sdk-go/pkg/models" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) @@ -148,7 +148,7 @@ func resourceIntegrationCreate(ctx context.Context, d *schema.ResourceData, m in return diag.FromErr(err) } - stateChangeFunc := resource.StateChangeConf{ + stateChangeFunc := retry.StateChangeConf{ Delay: 5 * time.Second, Pending: []string{models.RequestTrackerStatusINPROGRESS}, Refresh: resourceIntegrationStateRefreshFunc(*apiClient, *createResp.Payload.ID), @@ -243,7 +243,7 @@ func resourceIntegrationUpdate(ctx context.Context, d *schema.ResourceData, m in return diag.FromErr(err) } - stateChangeFunc := resource.StateChangeConf{ + stateChangeFunc := retry.StateChangeConf{ Delay: 5 * time.Second, Pending: []string{models.RequestTrackerStatusINPROGRESS}, Refresh: resourceIntegrationStateRefreshFunc(*apiClient, *updateResp.Payload.ID), @@ -271,7 +271,7 @@ func resourceIntegrationDelete(_ context.Context, d *schema.ResourceData, m inte return nil } -func resourceIntegrationStateRefreshFunc(apiClient client.API, id string) resource.StateRefreshFunc { +func resourceIntegrationStateRefreshFunc(apiClient client.API, id string) retry.StateRefreshFunc { return func() (interface{}, string, error) { ret, err := apiClient.Request.GetRequestTracker(request.NewGetRequestTrackerParams().WithID(id)) if err != nil { @@ -281,7 +281,7 @@ func resourceIntegrationStateRefreshFunc(apiClient client.API, id string) resour status := ret.Payload.Status switch *status { case models.RequestTrackerStatusFAILED: - return []string{""}, *status, fmt.Errorf(ret.Payload.Message) + return []string{""}, *status, errors.New(ret.Payload.Message) case models.RequestTrackerStatusINPROGRESS: return [...]string{id}, *status, nil case models.RequestTrackerStatusFINISHED: diff --git a/vra/resource_load_balancer.go b/vra/resource_load_balancer.go index 63ae07f..d7ab951 100644 --- a/vra/resource_load_balancer.go +++ b/vra/resource_load_balancer.go @@ -14,7 +14,7 @@ import ( "github.com/vmware/vra-sdk-go/pkg/models" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) @@ -141,7 +141,7 @@ func resourceLoadBalancerCreate(ctx context.Context, d *schema.ResourceData, m i return diag.FromErr(err) } - stateChangeFunc := resource.StateChangeConf{ + stateChangeFunc := retry.StateChangeConf{ Delay: 5 * time.Second, Pending: []string{models.RequestTrackerStatusINPROGRESS}, Refresh: loadBalancerStateRefreshFunc(*apiClient, *createLoadBalancerCreated.Payload.ID), @@ -164,7 +164,7 @@ func resourceLoadBalancerCreate(ctx context.Context, d *schema.ResourceData, m i return resourceLoadBalancerRead(ctx, d, m) } -func loadBalancerStateRefreshFunc(apiClient client.API, id string) resource.StateRefreshFunc { +func loadBalancerStateRefreshFunc(apiClient client.API, id string) retry.StateRefreshFunc { return func() (interface{}, string, error) { ret, err := apiClient.Request.GetRequestTracker(request.NewGetRequestTrackerParams().WithID(id)) if err != nil { @@ -174,7 +174,7 @@ func loadBalancerStateRefreshFunc(apiClient client.API, id string) resource.Stat status := ret.Payload.Status switch *status { case models.RequestTrackerStatusFAILED: - return []string{""}, *status, fmt.Errorf(ret.Payload.Message) + return []string{""}, *status, errors.New(ret.Payload.Message) case models.RequestTrackerStatusINPROGRESS: return [...]string{id}, *status, nil case models.RequestTrackerStatusFINISHED: @@ -247,7 +247,7 @@ func resourceLoadBalancerDelete(ctx context.Context, d *schema.ResourceData, m i if err != nil { return diag.FromErr(err) } - stateChangeFunc := resource.StateChangeConf{ + stateChangeFunc := retry.StateChangeConf{ Delay: 5 * time.Second, Pending: []string{models.RequestTrackerStatusINPROGRESS}, Refresh: loadBalancerStateRefreshFunc(*apiClient, *deleteLoadBalancer.Payload.ID), diff --git a/vra/resource_machine.go b/vra/resource_machine.go index 8b30ae5..9425e7a 100644 --- a/vra/resource_machine.go +++ b/vra/resource_machine.go @@ -9,7 +9,7 @@ import ( "time" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/vmware/vra-sdk-go/pkg/client" "github.com/vmware/vra-sdk-go/pkg/client/compute" "github.com/vmware/vra-sdk-go/pkg/client/disk" @@ -251,7 +251,7 @@ func resourceMachineCreate(ctx context.Context, d *schema.ResourceData, m interf return diag.FromErr(err) } - stateChangeFunc := resource.StateChangeConf{ + stateChangeFunc := retry.StateChangeConf{ Delay: 5 * time.Second, Pending: []string{models.RequestTrackerStatusINPROGRESS}, Refresh: machineStateRefreshFunc(*apiClient, *createMachineCreated.Payload.ID), @@ -280,7 +280,7 @@ func resourceMachineCreate(ctx context.Context, d *schema.ResourceData, m interf return diag.FromErr(err) } - stateChangeFunc := resource.StateChangeConf{ + stateChangeFunc := retry.StateChangeConf{ Delay: 5 * time.Second, Pending: []string{models.RequestTrackerStatusINPROGRESS}, Refresh: machineStateRefreshFunc(*apiClient, *attachMachineDiskOk.Payload.ID), @@ -297,7 +297,7 @@ func resourceMachineCreate(ctx context.Context, d *schema.ResourceData, m interf return resourceMachineRead(ctx, d, m) } -func machineStateRefreshFunc(apiClient client.API, id string) resource.StateRefreshFunc { +func machineStateRefreshFunc(apiClient client.API, id string) retry.StateRefreshFunc { return func() (interface{}, string, error) { ret, err := apiClient.Request.GetRequestTracker(request.NewGetRequestTrackerParams().WithID(id)) if err != nil { @@ -307,7 +307,7 @@ func machineStateRefreshFunc(apiClient client.API, id string) resource.StateRefr status := ret.Payload.Status switch *status { case models.RequestTrackerStatusFAILED: - return []string{""}, *status, fmt.Errorf(ret.Payload.Message) + return []string{""}, *status, errors.New(ret.Payload.Message) case models.RequestTrackerStatusINPROGRESS: return [...]string{id}, *status, nil case models.RequestTrackerStatusFINISHED: @@ -444,7 +444,7 @@ func attachAndDetachDisks(ctx context.Context, d *schema.ResourceData, apiClient return err } - stateChangeFunc := resource.StateChangeConf{ + stateChangeFunc := retry.StateChangeConf{ Delay: 5 * time.Second, Pending: []string{models.RequestTrackerStatusINPROGRESS}, Refresh: machineStateRefreshFunc(*apiClient, *deleteMachineDiskAccepted.Payload.ID), @@ -491,7 +491,7 @@ func attachAndDetachDisks(ctx context.Context, d *schema.ResourceData, apiClient return err } - stateChangeFunc := resource.StateChangeConf{ + stateChangeFunc := retry.StateChangeConf{ Delay: 5 * time.Second, Pending: []string{models.RequestTrackerStatusINPROGRESS}, Refresh: machineStateRefreshFunc(*apiClient, *attachMachineDiskOk.Payload.ID), @@ -562,7 +562,7 @@ func resizeMachine(ctx context.Context, d *schema.ResourceData, apiClient *clien if err != nil { return err } - stateChangeFunc := resource.StateChangeConf{ + stateChangeFunc := retry.StateChangeConf{ Delay: 5 * time.Second, Pending: []string{models.RequestTrackerStatusINPROGRESS}, Refresh: machineStateRefreshFunc(*apiClient, *resizeMachine.Payload.ID), @@ -590,7 +590,7 @@ func resourceMachineDelete(ctx context.Context, d *schema.ResourceData, m interf return diag.FromErr(err) } - stateChangeFunc := resource.StateChangeConf{ + stateChangeFunc := retry.StateChangeConf{ Delay: 5 * time.Second, Pending: []string{models.RequestTrackerStatusINPROGRESS}, Refresh: machineStateRefreshFunc(*apiClient, *deleteMachine.Payload.ID), diff --git a/vra/resource_network.go b/vra/resource_network.go index 39140c1..5b92721 100644 --- a/vra/resource_network.go +++ b/vra/resource_network.go @@ -11,7 +11,7 @@ import ( "github.com/vmware/vra-sdk-go/pkg/client/network" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/vmware/vra-sdk-go/pkg/client" "github.com/vmware/vra-sdk-go/pkg/client/request" @@ -133,7 +133,7 @@ func resourceNetworkCreate(ctx context.Context, d *schema.ResourceData, m interf if err != nil { return diag.FromErr(err) } - stateChangeFunc := resource.StateChangeConf{ + stateChangeFunc := retry.StateChangeConf{ Delay: 5 * time.Second, Pending: []string{models.RequestTrackerStatusINPROGRESS}, Refresh: networkStateRefreshFunc(*apiClient, *createNetworkCreated.Payload.ID), @@ -155,7 +155,7 @@ func resourceNetworkCreate(ctx context.Context, d *schema.ResourceData, m interf return resourceNetworkRead(ctx, d, m) } -func networkStateRefreshFunc(apiClient client.API, id string) resource.StateRefreshFunc { +func networkStateRefreshFunc(apiClient client.API, id string) retry.StateRefreshFunc { return func() (interface{}, string, error) { ret, err := apiClient.Request.GetRequestTracker(request.NewGetRequestTrackerParams().WithID(id)) if err != nil { @@ -165,7 +165,7 @@ func networkStateRefreshFunc(apiClient client.API, id string) resource.StateRefr status := ret.Payload.Status switch *status { case models.RequestTrackerStatusFAILED: - return []string{""}, *status, fmt.Errorf(ret.Payload.Message) + return []string{""}, *status, errors.New(ret.Payload.Message) case models.RequestTrackerStatusINPROGRESS: return [...]string{id}, *status, nil case models.RequestTrackerStatusFINISHED: @@ -233,7 +233,7 @@ func resourceNetworkDelete(ctx context.Context, d *schema.ResourceData, m interf if err != nil { return diag.FromErr(err) } - stateChangeFunc := resource.StateChangeConf{ + stateChangeFunc := retry.StateChangeConf{ Delay: 5 * time.Second, Pending: []string{models.RequestTrackerStatusINPROGRESS}, Refresh: networkStateRefreshFunc(*apiClient, *deleteNetworkAccepted.Payload.ID),