-
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.
Implement Filestore Instance. (#2088)
- Loading branch information
1 parent
042a2f5
commit 0790c96
Showing
9 changed files
with
1,012 additions
and
46 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,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 | ||
} |
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,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(), | ||
} |
Oops, something went wrong.