-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
<!-- This change is generated by MagicModules. --> /cc @danawillow
- Loading branch information
1 parent
cac3502
commit 488b9e8
Showing
6 changed files
with
838 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package google | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"time" | ||
|
||
"github.com/hashicorp/terraform/helper/resource" | ||
"google.golang.org/api/redis/v1beta1" | ||
) | ||
|
||
type RedisOperationWaiter struct { | ||
Service *redis.ProjectsLocationsService | ||
Op *redis.Operation | ||
} | ||
|
||
func (w *RedisOperationWaiter) RefreshFunc() resource.StateRefreshFunc { | ||
return func() (interface{}, string, error) { | ||
op, err := w.Service.Operations.Get(w.Op.Name).Do() | ||
|
||
if err != nil { | ||
return nil, "", err | ||
} | ||
|
||
log.Printf("[DEBUG] Got %v while polling for operation %s's 'done' status", op.Done, w.Op.Name) | ||
|
||
return op, fmt.Sprint(op.Done), nil | ||
} | ||
} | ||
|
||
func (w *RedisOperationWaiter) Conf() *resource.StateChangeConf { | ||
return &resource.StateChangeConf{ | ||
Pending: []string{"false"}, | ||
Target: []string{"true"}, | ||
Refresh: w.RefreshFunc(), | ||
} | ||
} | ||
|
||
func redisOperationWait(service *redis.Service, op *redis.Operation, project, activity string) error { | ||
return redisOperationWaitTime(service, op, project, activity, 4) | ||
} | ||
|
||
func redisOperationWaitTime(service *redis.Service, op *redis.Operation, project, activity string, timeoutMin int) error { | ||
w := &RedisOperationWaiter{ | ||
Service: service.Projects.Locations, | ||
Op: op, | ||
} | ||
|
||
state := w.Conf() | ||
state.Delay = 10 * time.Second | ||
state.Timeout = time.Duration(timeoutMin) * time.Minute | ||
state.MinTimeout = 2 * time.Second | ||
opRaw, err := state.WaitForState() | ||
if err != nil { | ||
return fmt.Errorf("Error waiting for %s: %s", activity, err) | ||
} | ||
|
||
op = opRaw.(*redis.Operation) | ||
if op.Error != nil { | ||
return fmt.Errorf("Error code %v, message: %s", op.Error.Code, op.Error.Message) | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.