forked from aiven/terraform-provider-aiven
-
Notifications
You must be signed in to change notification settings - Fork 0
/
service_change.go
44 lines (36 loc) · 926 Bytes
/
service_change.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
package main
import (
"github.com/hashicorp/terraform/helper/resource"
"github.com/jelmersnoeck/aiven"
"log"
"time"
)
type ServiceChangeWaiter struct {
Client *aiven.Client
Project string
ServiceName string
}
func (w *ServiceChangeWaiter) RefreshFunc() resource.StateRefreshFunc {
return func() (interface{}, string, error) {
service, err := w.Client.Services.Get(
w.Project,
w.ServiceName,
)
log.Printf("[DEBUG] Got %s state while waiting for service to be running.", service.State)
if err != nil {
return nil, "", err
}
return service, service.State, nil
}
}
func (w *ServiceChangeWaiter) Conf() *resource.StateChangeConf {
state := &resource.StateChangeConf{
Pending: []string{"REBUILDING"},
Target: []string{"RUNNING"},
Refresh: w.RefreshFunc(),
}
state.Delay = 10 * time.Second
state.Timeout = 10 * time.Minute
state.MinTimeout = 2 * time.Second
return state
}