Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resource/alicloud_esa_rate_plan_instance: Support release instance. #8138

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 53 additions & 1 deletion alicloud/resource_alicloud_esa_rate_plan_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"log"
"time"

util "github.com/alibabacloud-go/tea-utils/service"
"github.com/aliyun/terraform-provider-alicloud/alicloud/connectivity"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
Expand Down Expand Up @@ -225,7 +226,58 @@ func resourceAliCloudEsaRatePlanInstanceUpdate(d *schema.ResourceData, meta inte
}

func resourceAliCloudEsaRatePlanInstanceDelete(d *schema.ResourceData, meta interface{}) error {
log.Printf("[WARN] Cannot destroy resource AliCloud Resource Rate Plan Instance. Terraform will remove this resource from the state file, however resources may remain.")

client := meta.(*connectivity.AliyunClient)
action := "RefundInstance"
var request map[string]interface{}
var response map[string]interface{}
query := make(map[string]interface{})
conn, err := client.NewBssopenapiClient()
if err != nil {
return WrapError(err)
}
request = make(map[string]interface{})
request["InstanceId"] = d.Id()

request["ClientToken"] = buildClientToken(action)

request["ProductCode"] = "dcdn"
request["ImmediatelyRelease"] = "0"
request["ProductType"] = "dcdn_dcdnserviceplan_public_cn"
if client.IsInternationalAccount() {
request["ProductType"] = "dcdn_dcdnserviceplan_public_intl"
}
runtime := util.RuntimeOptions{}
runtime.SetAutoretry(true)
wait := incrementalWait(3*time.Second, 5*time.Second)
err = resource.Retry(d.Timeout(schema.TimeoutDelete), func() *resource.RetryError {
response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2017-12-14"), StringPointer("AK"), query, request, &runtime)
request["ClientToken"] = buildClientToken(action)

if err != nil {
if NeedRetry(err) {
wait()
return resource.RetryableError(err)
}
if !client.IsInternationalAccount() && IsExpectedErrors(err, []string{"NotApplicable"}) {
request["ProductCode"] = "dcdn"
request["ProductType"] = "dcdn_dcdnserviceplan_public_intl"
conn.Endpoint = String(connectivity.BssOpenAPIEndpointInternational)
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
return nil
})
addDebug(action, response, request)

if err != nil {
if NotFoundError(err) {
return nil
}
return WrapErrorf(err, DefaultErrorMsg, d.Id(), action, AlibabaCloudSdkGoERROR)
}

return nil
}

Expand Down
12 changes: 12 additions & 0 deletions alicloud/service_alicloud_esa_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,11 @@ func (s *EsaServiceV2) DescribeEsaRatePlanInstance(id string) (object map[string
return object, WrapErrorf(Error(GetNotFoundMessage("RatePlanInstance", id)), NotFoundMsg, response)
}

currentStatus := v.([]interface{})[0].(map[string]interface{})["Status"]
if currentStatus == "offline" {
return object, WrapErrorf(Error(GetNotFoundMessage("RatePlanInstance", id)), NotFoundMsg, response)
}

return v.([]interface{})[0].(map[string]interface{}), nil
}
func (s *EsaServiceV2) DescribeDescribeRatePlanInstanceStatus(id string) (object map[string]interface{}, err error) {
Expand Down Expand Up @@ -358,6 +363,13 @@ func (s *EsaServiceV2) EsaRatePlanInstanceStateRefreshFunc(id string, field stri
v, err := jsonpath.Get(field, object)
currentStatus := fmt.Sprint(v)

if strings.HasPrefix(field, "#") {
v, _ := jsonpath.Get(strings.TrimPrefix(field, "#"), object)
if v != nil {
currentStatus = "#CHECKSET"
}
}

for _, failState := range failStates {
if currentStatus == failState {
return object, currentStatus, WrapError(Error(FailedToReachTargetStatus, currentStatus))
Expand Down
13 changes: 2 additions & 11 deletions website/docs/r/esa_rate_plan_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ For information about ESA Rate Plan Instance and how to use it, see [What is Rat

Basic Usage

<div style="display: block;margin-bottom: 40px;"><div class="oics-button" style="float: right;position: absolute;margin-bottom: 10px;">
<a href="https://api.aliyun.com/terraform?resource=alicloud_esa_rate_plan_instance&exampleId=8a610a35-0473-4250-1ee5-cec23e2ec9dad16ea3e5&activeTab=example&spm=docs.r.esa_rate_plan_instance.0.8a610a3504&intl_lang=EN_US" target="_blank">
<img alt="Open in AliCloud" src="https://img.alicdn.com/imgextra/i1/O1CN01hjjqXv1uYUlY56FyX_!!6000000006049-55-tps-254-36.svg" style="max-height: 44px; max-width: 100%;">
</a>
</div></div>

```terraform
variable "name" {
default = "terraform-example"
Expand All @@ -47,10 +41,6 @@ resource "alicloud_esa_rate_plan_instance" "default" {
}
```

### Deleting `alicloud_esa_rate_plan_instance` or removing it from your configuration

Terraform cannot destroy resource `alicloud_esa_rate_plan_instance`. Terraform will remove this resource from the state file, however resources may remain.

## Argument Reference

The following arguments are supported:
Expand All @@ -67,7 +57,7 @@ The following arguments are supported:
global: global.

overseas: Global (excluding Mainland China).
* `payment_type` - (Optional, ForceNew, Computed) The payment type of the resource, Valid vales: Subscription.
* `payment_type` - (Optional, ForceNew, Computed) The payment type of the resource
* `period` - (Optional, Int) Purchase cycle (in months).
* `plan_name` - (Optional) The plan name, which is obtained from the DescribeRatePlanPrice interface.
* `type` - (Optional) Site access type:
Expand Down Expand Up @@ -100,6 +90,7 @@ The following attributes are exported:

The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration-0-11/resources.html#timeouts) for certain actions:
* `create` - (Defaults to 5 mins) Used when create the Rate Plan Instance.
* `delete` - (Defaults to 5 mins) Used when delete the Rate Plan Instance.
* `update` - (Defaults to 5 mins) Used when update the Rate Plan Instance.

## Import
Expand Down
Loading