From de6aee4d18b36375ce37c24a59a23c8ee359ec71 Mon Sep 17 00:00:00 2001 From: zhangpeihua Date: Mon, 20 Feb 2023 10:29:41 +0800 Subject: [PATCH 1/2] feat: add volume pre check --- common/common_volcengine_version.go | 2 +- .../ebs/volume/service_volcengine_volume.go | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/common/common_volcengine_version.go b/common/common_volcengine_version.go index 1d640689..a3092591 100644 --- a/common/common_volcengine_version.go +++ b/common/common_volcengine_version.go @@ -2,5 +2,5 @@ package common const ( TerraformProviderName = "terraform-provider-volcengine" - TerraformProviderVersion = "0.0.53" + TerraformProviderVersion = "0.0.54" ) diff --git a/volcengine/ebs/volume/service_volcengine_volume.go b/volcengine/ebs/volume/service_volcengine_volume.go index af8206de..61b6fd8e 100644 --- a/volcengine/ebs/volume/service_volcengine_volume.go +++ b/volcengine/ebs/volume/service_volcengine_volume.go @@ -8,6 +8,7 @@ import ( "time" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + re "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ve "github.com/volcengine/terraform-provider-volcengine/common" "github.com/volcengine/terraform-provider-volcengine/logger" @@ -246,6 +247,32 @@ func (s *VolcengineVolumeService) ModifyResource(resourceData *schema.ResourceDa logger.Debug(logger.ReqFormat, call.Action, call.SdkParam) return s.Client.UniversalClient.DoCall(getUniversalInfo(call.Action), call.SdkParam) }, + CallError: func(d *schema.ResourceData, client *ve.SdkClient, call ve.SdkCall, baseErr error) error { + oldV, newV := resourceData.GetChange("volume_charge_type") + if oldV == "PrePaid" && newV == "PostPaid" { + return errors.New("cannot convert PrePaid volume to PostPaid") + } + if d.Get("instance_id").(string) == "" { + return errors.New("instance id cannot be empty") + } + // retry modifyVolumeChargeType + return re.Retry(15*time.Minute, func() *re.RetryError { + data, callErr := s.ReadResource(d, d.Id()) + if callErr != nil { + return re.NonRetryableError(fmt.Errorf("error on reading volume %q: %w", d.Id(), callErr)) + } + // 计费方式已经转变成功 + if data["PayType"] == "Pre" { + return nil + } + // 计费方式还没有转换成功,尝试重新转换 + _, callErr = call.ExecuteCall(d, client, call) + if callErr == nil { + return nil + } + return re.RetryableError(callErr) + }) + }, }, }) } From 3597093e0ab48258aad611b52bb30b5a9fbd60b2 Mon Sep 17 00:00:00 2001 From: zhangpeihua Date: Mon, 20 Feb 2023 10:57:01 +0800 Subject: [PATCH 2/2] feat: remove unused field --- volcengine/ebs/volume/resource_volcengine_volume.go | 10 ---------- volcengine/ebs/volume/service_volcengine_volume.go | 9 ++++++++- website/docs/r/volume.html.markdown | 2 -- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/volcengine/ebs/volume/resource_volcengine_volume.go b/volcengine/ebs/volume/resource_volcengine_volume.go index dfaca5de..b8b3081c 100644 --- a/volcengine/ebs/volume/resource_volcengine_volume.go +++ b/volcengine/ebs/volume/resource_volcengine_volume.go @@ -102,16 +102,6 @@ func ResourceVolcengineVolume() *schema.Resource { Computed: true, Description: "Creation time of Volume.", }, - "billing_type": { - Type: schema.TypeInt, - Computed: true, - Description: "Billing type of Volume.", - }, - "pay_type": { - Type: schema.TypeString, - Computed: true, - Description: "Pay type of Volume.", - }, "delete_with_instance": { Type: schema.TypeBool, Optional: true, diff --git a/volcengine/ebs/volume/service_volcengine_volume.go b/volcengine/ebs/volume/service_volcengine_volume.go index 61b6fd8e..82b7e75b 100644 --- a/volcengine/ebs/volume/service_volcengine_volume.go +++ b/volcengine/ebs/volume/service_volcengine_volume.go @@ -245,7 +245,10 @@ func (s *VolcengineVolumeService) ModifyResource(resourceData *schema.ResourceDa }, ExecuteCall: func(d *schema.ResourceData, client *ve.SdkClient, call ve.SdkCall) (*map[string]interface{}, error) { logger.Debug(logger.ReqFormat, call.Action, call.SdkParam) - return s.Client.UniversalClient.DoCall(getUniversalInfo(call.Action), call.SdkParam) + resp, err := s.Client.UniversalClient.DoCall(getUniversalInfo(call.Action), call.SdkParam) + logger.Debug(logger.RespFormat, call.Action, resp) + logger.Debug(logger.RespFormat, call.Action, err) + return resp, err }, CallError: func(d *schema.ResourceData, client *ve.SdkClient, call ve.SdkCall, baseErr error) error { oldV, newV := resourceData.GetChange("volume_charge_type") @@ -270,6 +273,10 @@ func (s *VolcengineVolumeService) ModifyResource(resourceData *schema.ResourceDa if callErr == nil { return nil } + // 按量实例下挂载的云盘不支持按量转包年操作 + if strings.Contains(callErr.Error(), "ErrorInvalidEcsChargeType") { + return re.NonRetryableError(callErr) + } return re.RetryableError(callErr) }) }, diff --git a/website/docs/r/volume.html.markdown b/website/docs/r/volume.html.markdown index f93bd0a6..bf9756ae 100644 --- a/website/docs/r/volume.html.markdown +++ b/website/docs/r/volume.html.markdown @@ -49,9 +49,7 @@ The following arguments are supported: ## Attributes Reference In addition to all arguments above, the following attributes are exported: * `id` - ID of the resource. -* `billing_type` - Billing type of Volume. * `created_at` - Creation time of Volume. -* `pay_type` - Pay type of Volume. * `status` - Status of Volume. * `trade_status` - Status of Trade.