Skip to content

Commit

Permalink
Build datastore index resource. (#3085) (#5655)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Feb 12, 2020
1 parent f31b0fc commit 28a091a
Show file tree
Hide file tree
Showing 28 changed files with 1,016 additions and 40 deletions.
4 changes: 4 additions & 0 deletions .changelog/3085.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
```release-note:new-resource
google_datastore_index

```
27 changes: 25 additions & 2 deletions google/access_context_manager_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package google

import (
"encoding/json"
"fmt"
)

Expand All @@ -31,15 +32,37 @@ func (w *AccessContextManagerOperationWaiter) QueryOp() (interface{}, error) {
return sendRequest(w.Config, "GET", "", url, nil)
}

func accessContextManagerOperationWaitTime(config *Config, op map[string]interface{}, activity string, timeoutMinutes int) error {
func createAccessContextManagerWaiter(config *Config, op map[string]interface{}, activity string) (*AccessContextManagerOperationWaiter, error) {
if val, ok := op["name"]; !ok || val == "" {
// This was a synchronous call - there is no operation to wait for.
return nil
return nil, nil
}
w := &AccessContextManagerOperationWaiter{
Config: config,
}
if err := w.CommonOperationWaiter.SetOp(op); err != nil {
return nil, err
}
return w, nil
}

// nolint: deadcode,unused
func accessContextManagerOperationWaitTimeWithResponse(config *Config, op map[string]interface{}, response *map[string]interface{}, activity string, timeoutMinutes int) error {
w, err := createAccessContextManagerWaiter(config, op, activity)
if err != nil || w == nil {
// If w is nil, the op was synchronous.
return err
}
if err := OperationWait(w, activity, timeoutMinutes); err != nil {
return err
}
return json.Unmarshal([]byte(w.CommonOperationWaiter.Op.Response), response)
}

func accessContextManagerOperationWaitTime(config *Config, op map[string]interface{}, activity string, timeoutMinutes int) error {
w, err := createAccessContextManagerWaiter(config, op, activity)
if err != nil || w == nil {
// If w is nil, the op was synchronous.
return err
}
return OperationWait(w, activity, timeoutMinutes)
Expand Down
22 changes: 22 additions & 0 deletions google/appengine_operation.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package google

import (
"encoding/json"
"fmt"
"regexp"

Expand Down Expand Up @@ -32,6 +33,27 @@ func appEngineOperationWait(config *Config, res interface{}, appId, activity str
return appEngineOperationWaitTime(config, res, appId, activity, 4)
}

func appEngineOperationWaitTimeWithResponse(config *Config, res interface{}, response *map[string]interface{}, appId, activity string, timeoutMinutes int) error {
op := &appengine.Operation{}
err := Convert(res, op)
if err != nil {
return err
}

w := &AppEngineOperationWaiter{
Service: config.clientAppEngine,
AppId: appId,
}

if err := w.SetOp(op); err != nil {
return err
}
if err := OperationWait(w, activity, timeoutMinutes); err != nil {
return err
}
return json.Unmarshal([]byte(w.CommonOperationWaiter.Op.Response), response)
}

func appEngineOperationWaitTime(config *Config, res interface{}, appId, activity string, timeoutMinutes int) error {
op := &appengine.Operation{}
err := Convert(res, op)
Expand Down
3 changes: 3 additions & 0 deletions google/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ type Config struct {
ComputeBasePath string
ContainerAnalysisBasePath string
DataprocBasePath string
DatastoreBasePath string
DeploymentManagerBasePath string
DialogflowBasePath string
DNSBasePath string
Expand Down Expand Up @@ -218,6 +219,7 @@ var CloudTasksDefaultBasePath = "https://cloudtasks.googleapis.com/v2/"
var ComputeDefaultBasePath = "https://www.googleapis.com/compute/v1/"
var ContainerAnalysisDefaultBasePath = "https://containeranalysis.googleapis.com/v1/"
var DataprocDefaultBasePath = "https://dataproc.googleapis.com/v1/"
var DatastoreDefaultBasePath = "https://datastore.googleapis.com/v1/"
var DeploymentManagerDefaultBasePath = "https://www.googleapis.com/deploymentmanager/v2/"
var DialogflowDefaultBasePath = "https://dialogflow.googleapis.com/v2/"
var DNSDefaultBasePath = "https://www.googleapis.com/dns/v1/"
Expand Down Expand Up @@ -694,6 +696,7 @@ func ConfigureBasePaths(c *Config) {
c.ComputeBasePath = ComputeDefaultBasePath
c.ContainerAnalysisBasePath = ContainerAnalysisDefaultBasePath
c.DataprocBasePath = DataprocDefaultBasePath
c.DatastoreBasePath = DatastoreDefaultBasePath
c.DeploymentManagerBasePath = DeploymentManagerDefaultBasePath
c.DialogflowBasePath = DialogflowDefaultBasePath
c.DNSBasePath = DNSDefaultBasePath
Expand Down
71 changes: 71 additions & 0 deletions google/datastore_operation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// ----------------------------------------------------------------------------
//
// *** 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 (
"encoding/json"
"fmt"
)

type DatastoreOperationWaiter struct {
Config *Config
Project string
CommonOperationWaiter
}

func (w *DatastoreOperationWaiter) QueryOp() (interface{}, error) {
if w == nil {
return nil, fmt.Errorf("Cannot query operation, it's unset or nil.")
}
// Returns the proper get.
url := fmt.Sprintf("https://datastore.googleapis.com/v1/%s", w.CommonOperationWaiter.Op.Name)
return sendRequest(w.Config, "GET", w.Project, url, nil)
}

func createDatastoreWaiter(config *Config, op map[string]interface{}, project, activity string) (*DatastoreOperationWaiter, error) {
if val, ok := op["name"]; !ok || val == "" {
// This was a synchronous call - there is no operation to wait for.
return nil, nil
}
w := &DatastoreOperationWaiter{
Config: config,
Project: project,
}
if err := w.CommonOperationWaiter.SetOp(op); err != nil {
return nil, err
}
return w, nil
}

// nolint: deadcode,unused
func datastoreOperationWaitTimeWithResponse(config *Config, op map[string]interface{}, response *map[string]interface{}, project, activity string, timeoutMinutes int) error {
w, err := createDatastoreWaiter(config, op, project, activity)
if err != nil || w == nil {
// If w is nil, the op was synchronous.
return err
}
if err := OperationWait(w, activity, timeoutMinutes); err != nil {
return err
}
return json.Unmarshal([]byte(w.CommonOperationWaiter.Op.Response), response)
}

func datastoreOperationWaitTime(config *Config, op map[string]interface{}, project, activity string, timeoutMinutes int) error {
w, err := createDatastoreWaiter(config, op, project, activity)
if err != nil || w == nil {
// If w is nil, the op was synchronous.
return err
}
return OperationWait(w, activity, timeoutMinutes)
}
27 changes: 25 additions & 2 deletions google/filestore_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package google

import (
"encoding/json"
"fmt"
)

Expand All @@ -32,16 +33,38 @@ func (w *FilestoreOperationWaiter) QueryOp() (interface{}, error) {
return sendRequest(w.Config, "GET", w.Project, url, nil)
}

func filestoreOperationWaitTime(config *Config, op map[string]interface{}, project, activity string, timeoutMinutes int) error {
func createFilestoreWaiter(config *Config, op map[string]interface{}, project, activity string) (*FilestoreOperationWaiter, error) {
if val, ok := op["name"]; !ok || val == "" {
// This was a synchronous call - there is no operation to wait for.
return nil
return nil, nil
}
w := &FilestoreOperationWaiter{
Config: config,
Project: project,
}
if err := w.CommonOperationWaiter.SetOp(op); err != nil {
return nil, err
}
return w, nil
}

// nolint: deadcode,unused
func filestoreOperationWaitTimeWithResponse(config *Config, op map[string]interface{}, response *map[string]interface{}, project, activity string, timeoutMinutes int) error {
w, err := createFilestoreWaiter(config, op, project, activity)
if err != nil || w == nil {
// If w is nil, the op was synchronous.
return err
}
if err := OperationWait(w, activity, timeoutMinutes); err != nil {
return err
}
return json.Unmarshal([]byte(w.CommonOperationWaiter.Op.Response), response)
}

func filestoreOperationWaitTime(config *Config, op map[string]interface{}, project, activity string, timeoutMinutes int) error {
w, err := createFilestoreWaiter(config, op, project, activity)
if err != nil || w == nil {
// If w is nil, the op was synchronous.
return err
}
return OperationWait(w, activity, timeoutMinutes)
Expand Down
27 changes: 25 additions & 2 deletions google/firestore_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package google

import (
"encoding/json"
"fmt"
)

Expand All @@ -32,16 +33,38 @@ func (w *FirestoreOperationWaiter) QueryOp() (interface{}, error) {
return sendRequest(w.Config, "GET", w.Project, url, nil)
}

func firestoreOperationWaitTime(config *Config, op map[string]interface{}, project, activity string, timeoutMinutes int) error {
func createFirestoreWaiter(config *Config, op map[string]interface{}, project, activity string) (*FirestoreOperationWaiter, error) {
if val, ok := op["name"]; !ok || val == "" {
// This was a synchronous call - there is no operation to wait for.
return nil
return nil, nil
}
w := &FirestoreOperationWaiter{
Config: config,
Project: project,
}
if err := w.CommonOperationWaiter.SetOp(op); err != nil {
return nil, err
}
return w, nil
}

// nolint: deadcode,unused
func firestoreOperationWaitTimeWithResponse(config *Config, op map[string]interface{}, response *map[string]interface{}, project, activity string, timeoutMinutes int) error {
w, err := createFirestoreWaiter(config, op, project, activity)
if err != nil || w == nil {
// If w is nil, the op was synchronous.
return err
}
if err := OperationWait(w, activity, timeoutMinutes); err != nil {
return err
}
return json.Unmarshal([]byte(w.CommonOperationWaiter.Op.Response), response)
}

func firestoreOperationWaitTime(config *Config, op map[string]interface{}, project, activity string, timeoutMinutes int) error {
w, err := createFirestoreWaiter(config, op, project, activity)
if err != nil || w == nil {
// If w is nil, the op was synchronous.
return err
}
return OperationWait(w, activity, timeoutMinutes)
Expand Down
27 changes: 25 additions & 2 deletions google/ml_engine_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package google

import (
"encoding/json"
"fmt"
)

Expand All @@ -32,16 +33,38 @@ func (w *MLEngineOperationWaiter) QueryOp() (interface{}, error) {
return sendRequest(w.Config, "GET", w.Project, url, nil)
}

func mLEngineOperationWaitTime(config *Config, op map[string]interface{}, project, activity string, timeoutMinutes int) error {
func createMLEngineWaiter(config *Config, op map[string]interface{}, project, activity string) (*MLEngineOperationWaiter, error) {
if val, ok := op["name"]; !ok || val == "" {
// This was a synchronous call - there is no operation to wait for.
return nil
return nil, nil
}
w := &MLEngineOperationWaiter{
Config: config,
Project: project,
}
if err := w.CommonOperationWaiter.SetOp(op); err != nil {
return nil, err
}
return w, nil
}

// nolint: deadcode,unused
func mLEngineOperationWaitTimeWithResponse(config *Config, op map[string]interface{}, response *map[string]interface{}, project, activity string, timeoutMinutes int) error {
w, err := createMLEngineWaiter(config, op, project, activity)
if err != nil || w == nil {
// If w is nil, the op was synchronous.
return err
}
if err := OperationWait(w, activity, timeoutMinutes); err != nil {
return err
}
return json.Unmarshal([]byte(w.CommonOperationWaiter.Op.Response), response)
}

func mLEngineOperationWaitTime(config *Config, op map[string]interface{}, project, activity string, timeoutMinutes int) error {
w, err := createMLEngineWaiter(config, op, project, activity)
if err != nil || w == nil {
// If w is nil, the op was synchronous.
return err
}
return OperationWait(w, activity, timeoutMinutes)
Expand Down
14 changes: 12 additions & 2 deletions google/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,14 @@ func Provider() terraform.ResourceProvider {
"GOOGLE_DATAPROC_CUSTOM_ENDPOINT",
}, DataprocDefaultBasePath),
},
"datastore_custom_endpoint": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateCustomEndpoint,
DefaultFunc: schema.MultiEnvDefaultFunc([]string{
"GOOGLE_DATASTORE_CUSTOM_ENDPOINT",
}, DatastoreDefaultBasePath),
},
"deployment_manager_custom_endpoint": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -486,9 +494,9 @@ func Provider() terraform.ResourceProvider {
return provider
}

// Generated resources: 99
// Generated resources: 100
// Generated IAM resources: 48
// Total generated resources: 147
// Total generated resources: 148
func ResourceMap() map[string]*schema.Resource {
resourceMap, _ := ResourceMapWithErrors()
return resourceMap
Expand Down Expand Up @@ -577,6 +585,7 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) {
"google_compute_vpn_tunnel": resourceComputeVpnTunnel(),
"google_container_analysis_note": resourceContainerAnalysisNote(),
"google_dataproc_autoscaling_policy": resourceDataprocAutoscalingPolicy(),
"google_datastore_index": resourceDatastoreIndex(),
"google_deployment_manager_deployment": resourceDeploymentManagerDeployment(),
"google_dialogflow_agent": resourceDialogflowAgent(),
"google_dns_managed_zone": resourceDNSManagedZone(),
Expand Down Expand Up @@ -807,6 +816,7 @@ func providerConfigure(d *schema.ResourceData, p *schema.Provider, terraformVers
config.ComputeBasePath = d.Get("compute_custom_endpoint").(string)
config.ContainerAnalysisBasePath = d.Get("container_analysis_custom_endpoint").(string)
config.DataprocBasePath = d.Get("dataproc_custom_endpoint").(string)
config.DatastoreBasePath = d.Get("datastore_custom_endpoint").(string)
config.DeploymentManagerBasePath = d.Get("deployment_manager_custom_endpoint").(string)
config.DialogflowBasePath = d.Get("dialogflow_custom_endpoint").(string)
config.DNSBasePath = d.Get("dns_custom_endpoint").(string)
Expand Down
Loading

0 comments on commit 28a091a

Please sign in to comment.