Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Filestore Instance. #2088

Merged
merged 3 commits into from
Sep 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions google/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ type Config struct {
clientDataflow *dataflow.Service
clientDns *dns.Service
clientDnsBeta *dnsBeta.Service
clientFile *file.Service
clientFilestore *file.Service
clientKms *cloudkms.Service
clientLogging *cloudlogging.Service
clientPubsub *pubsub.Service
Expand Down Expand Up @@ -350,11 +350,11 @@ func (c *Config) loadAndValidate() error {
}
c.clientDataproc.UserAgent = userAgent

c.clientFile, err = file.New(client)
c.clientFilestore, err = file.New(client)
if err != nil {
return err
}
c.clientFile.UserAgent = userAgent
c.clientFilestore.UserAgent = userAgent

log.Printf("[INFO] Instantiating Google Cloud IoT Core Client...")
c.clientCloudIoT, err = cloudiot.New(client)
Expand Down
71 changes: 71 additions & 0 deletions google/filestore_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"
file "google.golang.org/api/file/v1beta1"
)

type FilestoreOperationWaiter struct {
Service *file.ProjectsLocationsService
Op *file.Operation
}

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

func filestoreOperationWait(service *file.Service, op *file.Operation, project, activity string) error {
return filestoreOperationWaitTime(service, op, project, activity, 4)
}

func filestoreOperationWaitTime(service *file.Service, op *file.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 := &FilestoreOperationWaiter{
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.(*file.Operation)
if op.Error != nil {
return fmt.Errorf("Error code %v, message: %s", op.Error.Code, op.Error.Message)
}

return nil
}
1 change: 1 addition & 0 deletions google/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func Provider() terraform.ResourceProvider {
GeneratedBinaryAuthorizationResourcesMap,
GeneratedComputeResourcesMap,
GeneratedContainerAnalysisResourcesMap,
GeneratedFilestoreResourcesMap,
GeneratedRedisResourcesMap,
GeneratedResourceManagerResourcesMap,
map[string]*schema.Resource{
Expand Down
21 changes: 21 additions & 0 deletions google/provider_filestore_gen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// ----------------------------------------------------------------------------
//
// *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
//
// ----------------------------------------------------------------------------
//
// This file is automatically generated by Magic Modules and manual
// changes will be clobbered when the file is regenerated.
//
// Please read more about how to change this file in
// .github/CONTRIBUTING.md.
//
// ----------------------------------------------------------------------------

package google

import "github.com/hashicorp/terraform/helper/schema"

var GeneratedFilestoreResourcesMap = map[string]*schema.Resource{
"google_filestore_instance": resourceFilestoreInstance(),
}
Loading