Skip to content

Commit

Permalink
Add Cloud Composer Environments resource (#2001)
Browse files Browse the repository at this point in the history
Adds Cloud Composer Environment resource and test sweeper
  • Loading branch information
emilymye authored Sep 11, 2018
1 parent afcbb85 commit 017f2f9
Show file tree
Hide file tree
Showing 6 changed files with 1,763 additions and 20 deletions.
71 changes: 71 additions & 0 deletions google/composer_operation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package google

import (
"fmt"
"log"
"time"

"github.com/hashicorp/terraform/helper/resource"
composer "google.golang.org/api/composer/v1"
)

type ComposerOperationWaiter struct {
Service *composer.ProjectsLocationsService
Op *composer.Operation
}

func (w *ComposerOperationWaiter) 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 *ComposerOperationWaiter) Conf() *resource.StateChangeConf {
return &resource.StateChangeConf{
Pending: []string{"false"},
Target: []string{"true"},
Refresh: w.RefreshFunc(),
}
}

func composerOperationWait(service *composer.Service, op *composer.Operation, project, activity string) error {
return composerOperationWaitTime(service, op, project, activity, 10)
}

func composerOperationWaitTime(service *composer.Service, op *composer.Operation, project, activity string, timeoutMin int) error {
if op.Done {
if op.Error != nil {
return fmt.Errorf("Error code %v, message: %s", op.Error.Code, op.Error.Message)
}
return nil
}

w := &ComposerOperationWaiter{
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.(*composer.Operation)
if op.Error != nil {
return fmt.Errorf("Error code %v, message: %s", op.Error.Code, op.Error.Message)
}

return nil
}
2 changes: 1 addition & 1 deletion google/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ func Provider() terraform.ResourceProvider {
GeneratedComputeResourcesMap,
GeneratedContainerAnalysisResourcesMap,
GeneratedRedisResourcesMap,
GeneratedComposerResourcesMap,
GeneratedResourceManagerResourcesMap,
map[string]*schema.Resource{
"google_bigquery_dataset": resourceBigQueryDataset(),
Expand All @@ -113,6 +112,7 @@ func Provider() terraform.ResourceProvider {
"google_cloudbuild_trigger": resourceCloudBuildTrigger(),
"google_cloudfunctions_function": resourceCloudFunctionsFunction(),
"google_cloudiot_registry": resourceCloudIoTRegistry(),
"google_composer_environment": resourceComposerEnvironment(),
"google_compute_autoscaler": resourceComputeAutoscaler(),
"google_compute_address": resourceComputeAddress(),
"google_compute_attached_disk": resourceComputeAttachedDisk(),
Expand Down
19 changes: 0 additions & 19 deletions google/provider_composer_gen.go

This file was deleted.

Loading

0 comments on commit 017f2f9

Please sign in to comment.