mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-10-15 07:27:15 +00:00
96ac8fc8a4
* Add google_dataproc_cluster resource * Add google_dataproc_cluster tests * Add google_dataproc_cluster docs * Removed google_dataproc_job ref (to be added in separate PR) * Added delete_autogen_bucket attribute * Refactored / simplified wait mechanism * Changes based on review * go fmt * Add cluster_config enclosing config block * Review updates - primarily re restructuring hierarchy * Removed rogue import * docs - alignment * Changes for review * Refactoring into expandXXX methods * Refactoring of flattenXXX methods to be explicit
60 lines
1.5 KiB
Go
60 lines
1.5 KiB
Go
package google
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"time"
|
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
"google.golang.org/api/dataproc/v1"
|
|
)
|
|
|
|
type DataprocClusterOperationWaiter struct {
|
|
Service *dataproc.Service
|
|
Op *dataproc.Operation
|
|
}
|
|
|
|
func (w *DataprocClusterOperationWaiter) Conf() *resource.StateChangeConf {
|
|
return &resource.StateChangeConf{
|
|
Pending: []string{"false"},
|
|
Target: []string{"true"},
|
|
Refresh: w.RefreshFunc(),
|
|
}
|
|
}
|
|
|
|
func (w *DataprocClusterOperationWaiter) RefreshFunc() resource.StateRefreshFunc {
|
|
return func() (interface{}, string, error) {
|
|
op, err := w.Service.Projects.Regions.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 dataprocClusterOperationWait(config *Config, op *dataproc.Operation, activity string, timeoutMinutes, minTimeoutSeconds int) error {
|
|
w := &DataprocClusterOperationWaiter{
|
|
Service: config.clientDataproc,
|
|
Op: op,
|
|
}
|
|
|
|
state := w.Conf()
|
|
state.Timeout = time.Duration(timeoutMinutes) * time.Minute
|
|
state.MinTimeout = time.Duration(minTimeoutSeconds) * time.Second
|
|
opRaw, err := state.WaitForState()
|
|
if err != nil {
|
|
return fmt.Errorf("Error waiting for %s: %s", activity, err)
|
|
}
|
|
|
|
op = opRaw.(*dataproc.Operation)
|
|
if op.Error != nil {
|
|
return fmt.Errorf("Error code %v, message: %s", op.Error.Code, op.Error.Message)
|
|
}
|
|
|
|
return nil
|
|
}
|