forked from aliyun/terraform-provider-alicloud
/
service_alicloud_maxcompute.go
73 lines (67 loc) · 2.45 KB
/
service_alicloud_maxcompute.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package alicloud
import (
"fmt"
"time"
"github.com/PaesslerAG/jsonpath"
util "github.com/alibabacloud-go/tea-utils/service"
"github.com/gunnerliu/terraform-provider-alicloud/alicloud/connectivity"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)
type MaxComputeService struct {
client *connectivity.AliyunClient
}
func (s *MaxComputeService) DescribeMaxcomputeProject(id string) (object map[string]interface{}, err error) {
conn, err := s.client.NewOdpsClient()
if err != nil {
return object, WrapError(err)
}
var response map[string]interface{}
action := "/api/v1/projects/" + id
runtime := util.RuntimeOptions{}
runtime.SetAutoretry(true)
err = resource.Retry(5*time.Minute, func() *resource.RetryError {
resp, err := conn.DoRequest(StringPointer("2022-01-04"), nil, StringPointer("GET"), StringPointer("AK"), StringPointer(action), nil, nil, nil, &util.RuntimeOptions{})
if err != nil {
return resource.NonRetryableError(err)
}
response = resp
addDebug(action, response)
return nil
})
if err != nil {
if IsExpectedErrors(err, []string{"INTERNAL_SERVER_ERROR", "OBJECT_NOT_EXIST"}) {
return object, WrapErrorf(Error(GetNotFoundMessage("MaxCompute", id)), NotFoundWithResponse, response)
}
return object, WrapErrorf(err, DefaultErrorMsg, id, action, AlibabaCloudSdkGoERROR)
}
v, err := jsonpath.Get("$.body.data", response)
if err != nil {
return object, WrapErrorf(err, FailedGetAttributeMsg, id, "$.data", response)
}
status, err := jsonpath.Get("$.status", v)
if err != nil {
return object, WrapErrorf(err, FailedGetAttributeMsg, id, "$.status", response)
}
if status == "DELETING" {
return object, WrapErrorf(Error(GetNotFoundMessage("MaxCompute:Project", id)), NotFoundWithResponse, response)
}
return v.(map[string]interface{}), nil
}
func (s *MaxComputeService) MaxcomputeProjectStateRefreshFunc(d *schema.ResourceData, failStates []string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
object, err := s.DescribeMaxcomputeProject(d.Id())
if err != nil {
if NotFoundError(err) {
return nil, "", nil
}
return nil, "", WrapError(err)
}
for _, failState := range failStates {
if fmt.Sprint(object["status"]) == failState {
return object, fmt.Sprint(object["status"]), WrapError(Error(FailedToReachTargetStatus, fmt.Sprint(object["status"])))
}
}
return object, fmt.Sprint(object["status"]), nil
}
}