Skip to content

Commit

Permalink
feat: add volume pre check
Browse files Browse the repository at this point in the history
  • Loading branch information
zpp12354321 committed Feb 20, 2023
1 parent 9152f74 commit de6aee4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
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"
)
27 changes: 27 additions & 0 deletions 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 @@ -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)
})
},
},
})
}
Expand Down

0 comments on commit de6aee4

Please sign in to comment.