Skip to content

Commit

Permalink
Merge pull request #64 from volcengine/feat/volume
Browse files Browse the repository at this point in the history
Feat/volume
  • Loading branch information
xuyaming0800 authored Feb 20, 2023
2 parents 4be9675 + 3597093 commit 209200b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 14 deletions.
2 changes: 1 addition & 1 deletion common/common_volcengine_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package common

const (
TerraformProviderName = "terraform-provider-volcengine"
TerraformProviderVersion = "0.0.53"
TerraformProviderVersion = "0.0.54"
)
10 changes: 0 additions & 10 deletions volcengine/ebs/volume/resource_volcengine_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
36 changes: 35 additions & 1 deletion volcengine/ebs/volume/service_volcengine_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -244,7 +245,40 @@ 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")
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
}
// 按量实例下挂载的云盘不支持按量转包年操作
if strings.Contains(callErr.Error(), "ErrorInvalidEcsChargeType") {
return re.NonRetryableError(callErr)
}
return re.RetryableError(callErr)
})
},
},
})
Expand Down
2 changes: 0 additions & 2 deletions website/docs/r/volume.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down

0 comments on commit 209200b

Please sign in to comment.