This repository has been archived by the owner on Jul 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
service_lb.go
47 lines (43 loc) · 1.45 KB
/
service_lb.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
package tencentcloud
import (
"fmt"
"time"
"github.com/hashicorp/terraform/helper/resource"
lb "github.com/zqfan/tencentcloud-sdk-go/services/lb/unversioned"
)
func waitForLBReady(client *lb.Client, lbid *string) error {
return resource.Retry(5*time.Minute, func() *resource.RetryError {
req := lb.NewDescribeLoadBalancersRequest()
req.LoadBalancerIds = []*string{lbid}
resp, err := client.DescribeLoadBalancers(req)
if err != nil {
return resource.RetryableError(err)
}
if *resp.LoadBalancerSet[0].Status == lb.LBStatusCreating {
return resource.RetryableError(fmt.Errorf("LB %s is still creating...", *lbid))
} else if *resp.LoadBalancerSet[0].Status == lb.LBStatusReady {
return nil
} else {
return resource.NonRetryableError(fmt.Errorf("LB %s status unknown...", *lbid))
}
return nil
})
}
func waitForLBTaskFinish(client *lb.Client, taskid *int) error {
return resource.Retry(5*time.Minute, func() *resource.RetryError {
req := lb.NewDescribeLoadBalancersTaskResultRequest()
req.RequestId = taskid
resp, err := client.DescribeLoadBalancersTaskResult(req)
if err != nil {
return resource.RetryableError(err)
}
if *resp.Data.Status == lb.LBTaskSuccess {
return nil
} else if *resp.Data.Status == lb.LBTaskFail {
return resource.NonRetryableError(fmt.Errorf("LB task %d fail...", *taskid))
} else {
return resource.RetryableError(fmt.Errorf("LB task %d is still waiting...", *taskid))
}
return nil
})
}