diff --git a/.changelog/3085.txt b/.changelog/3085.txt new file mode 100644 index 00000000000..be1bfc44d49 --- /dev/null +++ b/.changelog/3085.txt @@ -0,0 +1,4 @@ +```release-note:new-resource +google_datastore_index + +``` diff --git a/google/access_context_manager_operation.go b/google/access_context_manager_operation.go index c45aaecfeb9..e31b715109a 100644 --- a/google/access_context_manager_operation.go +++ b/google/access_context_manager_operation.go @@ -14,6 +14,7 @@ package google import ( + "encoding/json" "fmt" ) @@ -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) diff --git a/google/appengine_operation.go b/google/appengine_operation.go index 0e96a21110c..11ebc12f9c7 100644 --- a/google/appengine_operation.go +++ b/google/appengine_operation.go @@ -1,6 +1,7 @@ package google import ( + "encoding/json" "fmt" "regexp" @@ -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) diff --git a/google/config.go b/google/config.go index 9e06b2196ca..fe3175f9f70 100644 --- a/google/config.go +++ b/google/config.go @@ -86,6 +86,7 @@ type Config struct { ComputeBasePath string ContainerAnalysisBasePath string DataprocBasePath string + DatastoreBasePath string DeploymentManagerBasePath string DialogflowBasePath string DNSBasePath string @@ -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/" @@ -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 diff --git a/google/datastore_operation.go b/google/datastore_operation.go new file mode 100644 index 00000000000..c9b1b5380e4 --- /dev/null +++ b/google/datastore_operation.go @@ -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) +} diff --git a/google/filestore_operation.go b/google/filestore_operation.go index 7885f36ff81..39038b6dd4d 100644 --- a/google/filestore_operation.go +++ b/google/filestore_operation.go @@ -14,6 +14,7 @@ package google import ( + "encoding/json" "fmt" ) @@ -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) diff --git a/google/firestore_operation.go b/google/firestore_operation.go index 2e99c69331c..a0c4330a1c8 100644 --- a/google/firestore_operation.go +++ b/google/firestore_operation.go @@ -14,6 +14,7 @@ package google import ( + "encoding/json" "fmt" ) @@ -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) diff --git a/google/ml_engine_operation.go b/google/ml_engine_operation.go index 653acea5f90..48770b36d4e 100644 --- a/google/ml_engine_operation.go +++ b/google/ml_engine_operation.go @@ -14,6 +14,7 @@ package google import ( + "encoding/json" "fmt" ) @@ -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) diff --git a/google/provider.go b/google/provider.go index 0579869106a..c2bb300f3b2 100644 --- a/google/provider.go +++ b/google/provider.go @@ -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, @@ -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 @@ -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(), @@ -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) diff --git a/google/redis_operation.go b/google/redis_operation.go index 76489d30c52..750af4bbe3d 100644 --- a/google/redis_operation.go +++ b/google/redis_operation.go @@ -14,6 +14,7 @@ package google import ( + "encoding/json" "fmt" ) @@ -32,16 +33,38 @@ func (w *RedisOperationWaiter) QueryOp() (interface{}, error) { return sendRequest(w.Config, "GET", w.Project, url, nil) } -func redisOperationWaitTime(config *Config, op map[string]interface{}, project, activity string, timeoutMinutes int) error { +func createRedisWaiter(config *Config, op map[string]interface{}, project, activity string) (*RedisOperationWaiter, 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 := &RedisOperationWaiter{ Config: config, Project: project, } if err := w.CommonOperationWaiter.SetOp(op); err != nil { + return nil, err + } + return w, nil +} + +// nolint: deadcode,unused +func redisOperationWaitTimeWithResponse(config *Config, op map[string]interface{}, response *map[string]interface{}, project, activity string, timeoutMinutes int) error { + w, err := createRedisWaiter(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 redisOperationWaitTime(config *Config, op map[string]interface{}, project, activity string, timeoutMinutes int) error { + w, err := createRedisWaiter(config, op, project, activity) + if err != nil || w == nil { + // If w is nil, the op was synchronous. return err } return OperationWait(w, activity, timeoutMinutes) diff --git a/google/resource_access_context_manager_access_level.go b/google/resource_access_context_manager_access_level.go index 5777be23b4d..045e814314a 100644 --- a/google/resource_access_context_manager_access_level.go +++ b/google/resource_access_context_manager_access_level.go @@ -281,8 +281,9 @@ func resourceAccessContextManagerAccessLevelCreate(d *schema.ResourceData, meta } d.SetId(id) - err = accessContextManagerOperationWaitTime( - config, res, "Creating AccessLevel", + var response map[string]interface{} + err = accessContextManagerOperationWaitTimeWithResponse( + config, res, &response, "Creating AccessLevel", int(d.Timeout(schema.TimeoutCreate).Minutes())) if err != nil { @@ -290,6 +291,16 @@ func resourceAccessContextManagerAccessLevelCreate(d *schema.ResourceData, meta d.SetId("") return fmt.Errorf("Error waiting to create AccessLevel: %s", err) } + if err := d.Set("name", flattenAccessContextManagerAccessLevelName(response["name"], d, config)); err != nil { + return err + } + + // This may have caused the ID to update - update it if so. + id, err = replaceVars(d, config, "{{name}}") + if err != nil { + return fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) log.Printf("[DEBUG] Finished creating AccessLevel %q: %#v", d.Id(), res) diff --git a/google/resource_access_context_manager_access_policy.go b/google/resource_access_context_manager_access_policy.go index 67230319dee..3ce2cb0ede0 100644 --- a/google/resource_access_context_manager_access_policy.go +++ b/google/resource_access_context_manager_access_policy.go @@ -108,8 +108,9 @@ func resourceAccessContextManagerAccessPolicyCreate(d *schema.ResourceData, meta } d.SetId(id) - err = accessContextManagerOperationWaitTime( - config, res, "Creating AccessPolicy", + var response map[string]interface{} + err = accessContextManagerOperationWaitTimeWithResponse( + config, res, &response, "Creating AccessPolicy", int(d.Timeout(schema.TimeoutCreate).Minutes())) if err != nil { @@ -117,6 +118,16 @@ func resourceAccessContextManagerAccessPolicyCreate(d *schema.ResourceData, meta d.SetId("") return fmt.Errorf("Error waiting to create AccessPolicy: %s", err) } + if err := d.Set("name", flattenAccessContextManagerAccessPolicyName(response["name"], d, config)); err != nil { + return err + } + + // This may have caused the ID to update - update it if so. + id, err = replaceVars(d, config, "{{name}}") + if err != nil { + return fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) log.Printf("[DEBUG] Finished creating AccessPolicy %q: %#v", d.Id(), res) diff --git a/google/resource_access_context_manager_service_perimeter.go b/google/resource_access_context_manager_service_perimeter.go index b8d1ef14b1c..8d5964a8ff7 100644 --- a/google/resource_access_context_manager_service_perimeter.go +++ b/google/resource_access_context_manager_service_perimeter.go @@ -231,8 +231,9 @@ func resourceAccessContextManagerServicePerimeterCreate(d *schema.ResourceData, } d.SetId(id) - err = accessContextManagerOperationWaitTime( - config, res, "Creating ServicePerimeter", + var response map[string]interface{} + err = accessContextManagerOperationWaitTimeWithResponse( + config, res, &response, "Creating ServicePerimeter", int(d.Timeout(schema.TimeoutCreate).Minutes())) if err != nil { @@ -240,6 +241,16 @@ func resourceAccessContextManagerServicePerimeterCreate(d *schema.ResourceData, d.SetId("") return fmt.Errorf("Error waiting to create ServicePerimeter: %s", err) } + if err := d.Set("name", flattenAccessContextManagerServicePerimeterName(response["name"], d, config)); err != nil { + return err + } + + // This may have caused the ID to update - update it if so. + id, err = replaceVars(d, config, "{{name}}") + if err != nil { + return fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) log.Printf("[DEBUG] Finished creating ServicePerimeter %q: %#v", d.Id(), res) diff --git a/google/resource_access_context_manager_service_perimeter_resource.go b/google/resource_access_context_manager_service_perimeter_resource.go index 9251feb2133..7dc3d94831a 100644 --- a/google/resource_access_context_manager_service_perimeter_resource.go +++ b/google/resource_access_context_manager_service_perimeter_resource.go @@ -104,8 +104,9 @@ func resourceAccessContextManagerServicePerimeterResourceCreate(d *schema.Resour } d.SetId(id) - err = accessContextManagerOperationWaitTime( - config, res, "Creating ServicePerimeterResource", + var response map[string]interface{} + err = accessContextManagerOperationWaitTimeWithResponse( + config, res, &response, "Creating ServicePerimeterResource", int(d.Timeout(schema.TimeoutCreate).Minutes())) if err != nil { @@ -113,6 +114,16 @@ func resourceAccessContextManagerServicePerimeterResourceCreate(d *schema.Resour d.SetId("") return fmt.Errorf("Error waiting to create ServicePerimeterResource: %s", err) } + if err := d.Set("resource", flattenAccessContextManagerServicePerimeterResourceResource(response["resource"], d, config)); err != nil { + return err + } + + // This may have caused the ID to update - update it if so. + id, err = replaceVars(d, config, "{{perimeter_name}}/{{resource}}") + if err != nil { + return fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) log.Printf("[DEBUG] Finished creating ServicePerimeterResource %q: %#v", d.Id(), res) diff --git a/google/resource_app_engine_domain_mapping.go b/google/resource_app_engine_domain_mapping.go index 62cc1bae099..f98294f5e33 100644 --- a/google/resource_app_engine_domain_mapping.go +++ b/google/resource_app_engine_domain_mapping.go @@ -189,8 +189,9 @@ func resourceAppEngineDomainMappingCreate(d *schema.ResourceData, meta interface } d.SetId(id) - err = appEngineOperationWaitTime( - config, res, project, "Creating DomainMapping", + var response map[string]interface{} + err = appEngineOperationWaitTimeWithResponse( + config, res, &response, project, "Creating DomainMapping", int(d.Timeout(schema.TimeoutCreate).Minutes())) if err != nil { @@ -198,6 +199,16 @@ func resourceAppEngineDomainMappingCreate(d *schema.ResourceData, meta interface d.SetId("") return fmt.Errorf("Error waiting to create DomainMapping: %s", err) } + if err := d.Set("name", flattenAppEngineDomainMappingName(response["name"], d, config)); err != nil { + return err + } + + // This may have caused the ID to update - update it if so. + id, err = replaceVars(d, config, "apps/{{project}}/domainMappings/{{domain_name}}") + if err != nil { + return fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) log.Printf("[DEBUG] Finished creating DomainMapping %q: %#v", d.Id(), res) diff --git a/google/resource_datastore_index.go b/google/resource_datastore_index.go new file mode 100644 index 00000000000..bd3c97b95be --- /dev/null +++ b/google/resource_datastore_index.go @@ -0,0 +1,340 @@ +// ---------------------------------------------------------------------------- +// +// *** 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 ( + "fmt" + "log" + "reflect" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/helper/validation" +) + +func resourceDatastoreIndex() *schema.Resource { + return &schema.Resource{ + Create: resourceDatastoreIndexCreate, + Read: resourceDatastoreIndexRead, + Delete: resourceDatastoreIndexDelete, + + Importer: &schema.ResourceImporter{ + State: resourceDatastoreIndexImport, + }, + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(10 * time.Minute), + Delete: schema.DefaultTimeout(10 * time.Minute), + }, + + Schema: map[string]*schema.Schema{ + "kind": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: `The entity kind which the index applies to.`, + }, + "ancestor": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + ValidateFunc: validation.StringInSlice([]string{"NONE", "ALL_ANCESTORS", ""}, false), + Description: `Policy for including ancestors in the index. Either 'ALL_ANCESTORS' or 'NONE', +the default is 'NONE'.`, + Default: "NONE", + }, + "properties": { + Type: schema.TypeList, + Optional: true, + ForceNew: true, + Description: `An ordered list of properties to index on.`, + MinItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "direction": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringInSlice([]string{"ASCENDING", "DESCENDING"}, false), + Description: `The direction the index should optimize for sorting. Possible values are ASCENDING and DESCENDING.`, + }, + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: `The property name to index.`, + }, + }, + }, + }, + "index_id": { + Type: schema.TypeString, + Computed: true, + Description: `The index id.`, + }, + "project": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + }, + }, + } +} + +func resourceDatastoreIndexCreate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + + obj := make(map[string]interface{}) + kindProp, err := expandDatastoreIndexKind(d.Get("kind"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("kind"); !isEmptyValue(reflect.ValueOf(kindProp)) && (ok || !reflect.DeepEqual(v, kindProp)) { + obj["kind"] = kindProp + } + ancestorProp, err := expandDatastoreIndexAncestor(d.Get("ancestor"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("ancestor"); !isEmptyValue(reflect.ValueOf(ancestorProp)) && (ok || !reflect.DeepEqual(v, ancestorProp)) { + obj["ancestor"] = ancestorProp + } + propertiesProp, err := expandDatastoreIndexProperties(d.Get("properties"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("properties"); !isEmptyValue(reflect.ValueOf(propertiesProp)) && (ok || !reflect.DeepEqual(v, propertiesProp)) { + obj["properties"] = propertiesProp + } + + url, err := replaceVars(d, config, "{{DatastoreBasePath}}projects/{{project}}/indexes") + if err != nil { + return err + } + + log.Printf("[DEBUG] Creating new Index: %#v", obj) + project, err := getProject(d, config) + if err != nil { + return err + } + res, err := sendRequestWithTimeout(config, "POST", project, url, obj, d.Timeout(schema.TimeoutCreate)) + if err != nil { + return fmt.Errorf("Error creating Index: %s", err) + } + + // Store the ID now + id, err := replaceVars(d, config, "projects/{{project}}/indexes/{{index_id}}") + if err != nil { + return fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) + + var response map[string]interface{} + err = datastoreOperationWaitTimeWithResponse( + config, res, &response, project, "Creating Index", + int(d.Timeout(schema.TimeoutCreate).Minutes())) + + if err != nil { + // The resource didn't actually create + d.SetId("") + return fmt.Errorf("Error waiting to create Index: %s", err) + } + if err := d.Set("index_id", flattenDatastoreIndexIndexId(response["indexId"], d, config)); err != nil { + return err + } + + // This may have caused the ID to update - update it if so. + id, err = replaceVars(d, config, "projects/{{project}}/indexes/{{index_id}}") + if err != nil { + return fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) + + log.Printf("[DEBUG] Finished creating Index %q: %#v", d.Id(), res) + + return resourceDatastoreIndexRead(d, meta) +} + +func resourceDatastoreIndexRead(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + + url, err := replaceVars(d, config, "{{DatastoreBasePath}}projects/{{project}}/indexes/{{index_id}}") + if err != nil { + return err + } + + project, err := getProject(d, config) + if err != nil { + return err + } + res, err := sendRequest(config, "GET", project, url, nil) + if err != nil { + return handleNotFoundError(err, d, fmt.Sprintf("DatastoreIndex %q", d.Id())) + } + + if err := d.Set("project", project); err != nil { + return fmt.Errorf("Error reading Index: %s", err) + } + + if err := d.Set("index_id", flattenDatastoreIndexIndexId(res["indexId"], d, config)); err != nil { + return fmt.Errorf("Error reading Index: %s", err) + } + if err := d.Set("kind", flattenDatastoreIndexKind(res["kind"], d, config)); err != nil { + return fmt.Errorf("Error reading Index: %s", err) + } + if err := d.Set("ancestor", flattenDatastoreIndexAncestor(res["ancestor"], d, config)); err != nil { + return fmt.Errorf("Error reading Index: %s", err) + } + if err := d.Set("properties", flattenDatastoreIndexProperties(res["properties"], d, config)); err != nil { + return fmt.Errorf("Error reading Index: %s", err) + } + + return nil +} + +func resourceDatastoreIndexDelete(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + + project, err := getProject(d, config) + if err != nil { + return err + } + + url, err := replaceVars(d, config, "{{DatastoreBasePath}}projects/{{project}}/indexes/{{index_id}}") + if err != nil { + return err + } + + var obj map[string]interface{} + log.Printf("[DEBUG] Deleting Index %q", d.Id()) + + res, err := sendRequestWithTimeout(config, "DELETE", project, url, obj, d.Timeout(schema.TimeoutDelete)) + if err != nil { + return handleNotFoundError(err, d, "Index") + } + + err = datastoreOperationWaitTime( + config, res, project, "Deleting Index", + int(d.Timeout(schema.TimeoutDelete).Minutes())) + + if err != nil { + return err + } + + log.Printf("[DEBUG] Finished deleting Index %q: %#v", d.Id(), res) + return nil +} + +func resourceDatastoreIndexImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + config := meta.(*Config) + if err := parseImportId([]string{ + "projects/(?P[^/]+)/indexes/(?P[^/]+)", + "(?P[^/]+)/(?P[^/]+)", + "(?P[^/]+)", + }, d, config); err != nil { + return nil, err + } + + // Replace import id for the resource id + id, err := replaceVars(d, config, "projects/{{project}}/indexes/{{index_id}}") + if err != nil { + return nil, fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) + + return []*schema.ResourceData{d}, nil +} + +func flattenDatastoreIndexIndexId(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenDatastoreIndexKind(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenDatastoreIndexAncestor(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenDatastoreIndexProperties(v interface{}, d *schema.ResourceData, config *Config) interface{} { + if v == nil { + return v + } + l := v.([]interface{}) + transformed := make([]interface{}, 0, len(l)) + for _, raw := range l { + original := raw.(map[string]interface{}) + if len(original) < 1 { + // Do not include empty json objects coming back from the api + continue + } + transformed = append(transformed, map[string]interface{}{ + "name": flattenDatastoreIndexPropertiesName(original["name"], d, config), + "direction": flattenDatastoreIndexPropertiesDirection(original["direction"], d, config), + }) + } + return transformed +} +func flattenDatastoreIndexPropertiesName(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenDatastoreIndexPropertiesDirection(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func expandDatastoreIndexKind(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandDatastoreIndexAncestor(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandDatastoreIndexProperties(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + l := v.([]interface{}) + req := make([]interface{}, 0, len(l)) + for _, raw := range l { + if raw == nil { + continue + } + original := raw.(map[string]interface{}) + transformed := make(map[string]interface{}) + + transformedName, err := expandDatastoreIndexPropertiesName(original["name"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedName); val.IsValid() && !isEmptyValue(val) { + transformed["name"] = transformedName + } + + transformedDirection, err := expandDatastoreIndexPropertiesDirection(original["direction"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedDirection); val.IsValid() && !isEmptyValue(val) { + transformed["direction"] = transformedDirection + } + + req = append(req, transformed) + } + return req, nil +} + +func expandDatastoreIndexPropertiesName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandDatastoreIndexPropertiesDirection(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} diff --git a/google/resource_datastore_index_generated_test.go b/google/resource_datastore_index_generated_test.go new file mode 100644 index 00000000000..280b97d3e9d --- /dev/null +++ b/google/resource_datastore_index_generated_test.go @@ -0,0 +1,90 @@ +// ---------------------------------------------------------------------------- +// +// *** 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 ( + "fmt" + "strings" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" +) + +func TestAccDatastoreIndex_datastoreIndexExample(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": acctest.RandString(10), + } + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckDatastoreIndexDestroy, + Steps: []resource.TestStep{ + { + Config: testAccDatastoreIndex_datastoreIndexExample(context), + }, + { + ResourceName: "google_datastore_index.default", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccDatastoreIndex_datastoreIndexExample(context map[string]interface{}) string { + return Nprintf(` +resource "google_datastore_index" "default" { + kind = "foo" + properties { + name = "tf_test_property_a%{random_suffix}" + direction = "ASCENDING" + } + properties { + name = "tf_test_property_b%{random_suffix}" + direction = "ASCENDING" + } +} +`, context) +} + +func testAccCheckDatastoreIndexDestroy(s *terraform.State) error { + for name, rs := range s.RootModule().Resources { + if rs.Type != "google_datastore_index" { + continue + } + if strings.HasPrefix(name, "data.") { + continue + } + + config := testAccProvider.Meta().(*Config) + + url, err := replaceVarsForTest(config, rs, "{{DatastoreBasePath}}projects/{{project}}/indexes/{{index_id}}") + if err != nil { + return err + } + + _, err = sendRequest(config, "GET", "", url, nil) + if err == nil { + return fmt.Errorf("DatastoreIndex still exists at %s", url) + } + } + + return nil +} diff --git a/google/resource_filestore_instance.go b/google/resource_filestore_instance.go index e398762be49..3120b672b4d 100644 --- a/google/resource_filestore_instance.go +++ b/google/resource_filestore_instance.go @@ -218,8 +218,9 @@ func resourceFilestoreInstanceCreate(d *schema.ResourceData, meta interface{}) e } d.SetId(id) - err = filestoreOperationWaitTime( - config, res, project, "Creating Instance", + var response map[string]interface{} + err = filestoreOperationWaitTimeWithResponse( + config, res, &response, project, "Creating Instance", int(d.Timeout(schema.TimeoutCreate).Minutes())) if err != nil { @@ -228,6 +229,13 @@ func resourceFilestoreInstanceCreate(d *schema.ResourceData, meta interface{}) e return fmt.Errorf("Error waiting to create Instance: %s", err) } + // This may have caused the ID to update - update it if so. + id, err = replaceVars(d, config, "projects/{{project}}/locations/{{zone}}/instances/{{name}}") + if err != nil { + return fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) + log.Printf("[DEBUG] Finished creating Instance %q: %#v", d.Id(), res) return resourceFilestoreInstanceRead(d, meta) diff --git a/google/resource_firestore_index.go b/google/resource_firestore_index.go index 8d9bf278032..bbde97363e7 100644 --- a/google/resource_firestore_index.go +++ b/google/resource_firestore_index.go @@ -173,8 +173,9 @@ func resourceFirestoreIndexCreate(d *schema.ResourceData, meta interface{}) erro } d.SetId(id) - err = firestoreOperationWaitTime( - config, res, project, "Creating Index", + var response map[string]interface{} + err = firestoreOperationWaitTimeWithResponse( + config, res, &response, project, "Creating Index", int(d.Timeout(schema.TimeoutCreate).Minutes())) if err != nil { @@ -182,6 +183,16 @@ func resourceFirestoreIndexCreate(d *schema.ResourceData, meta interface{}) erro d.SetId("") return fmt.Errorf("Error waiting to create Index: %s", err) } + if err := d.Set("name", flattenFirestoreIndexName(response["name"], d, config)); err != nil { + return err + } + + // This may have caused the ID to update - update it if so. + id, err = replaceVars(d, config, "{{name}}") + if err != nil { + return fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) log.Printf("[DEBUG] Finished creating Index %q: %#v", d.Id(), res) diff --git a/google/resource_manager_operation.go b/google/resource_manager_operation.go index 4c7ec6079b6..3e42774b028 100644 --- a/google/resource_manager_operation.go +++ b/google/resource_manager_operation.go @@ -14,6 +14,7 @@ package google import ( + "encoding/json" "fmt" ) @@ -31,15 +32,37 @@ func (w *ResourceManagerOperationWaiter) QueryOp() (interface{}, error) { return sendRequest(w.Config, "GET", "", url, nil) } -func resourceManagerOperationWaitTime(config *Config, op map[string]interface{}, activity string, timeoutMinutes int) error { +func createResourceManagerWaiter(config *Config, op map[string]interface{}, activity string) (*ResourceManagerOperationWaiter, 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 := &ResourceManagerOperationWaiter{ Config: config, } if err := w.CommonOperationWaiter.SetOp(op); err != nil { + return nil, err + } + return w, nil +} + +// nolint: deadcode,unused +func resourceManagerOperationWaitTimeWithResponse(config *Config, op map[string]interface{}, response *map[string]interface{}, activity string, timeoutMinutes int) error { + w, err := createResourceManagerWaiter(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 resourceManagerOperationWaitTime(config *Config, op map[string]interface{}, activity string, timeoutMinutes int) error { + w, err := createResourceManagerWaiter(config, op, activity) + if err != nil || w == nil { + // If w is nil, the op was synchronous. return err } return OperationWait(w, activity, timeoutMinutes) diff --git a/google/resource_redis_instance.go b/google/resource_redis_instance.go index 09f9dcbb7bc..fcf826fad3a 100644 --- a/google/resource_redis_instance.go +++ b/google/resource_redis_instance.go @@ -279,8 +279,9 @@ func resourceRedisInstanceCreate(d *schema.ResourceData, meta interface{}) error } d.SetId(id) - err = redisOperationWaitTime( - config, res, project, "Creating Instance", + var response map[string]interface{} + err = redisOperationWaitTimeWithResponse( + config, res, &response, project, "Creating Instance", int(d.Timeout(schema.TimeoutCreate).Minutes())) if err != nil { @@ -288,6 +289,16 @@ func resourceRedisInstanceCreate(d *schema.ResourceData, meta interface{}) error d.SetId("") return fmt.Errorf("Error waiting to create Instance: %s", err) } + if err := d.Set("name", flattenRedisInstanceName(response["name"], d, config)); err != nil { + return err + } + + // This may have caused the ID to update - update it if so. + id, err = replaceVars(d, config, "projects/{{project}}/locations/{{region}}/instances/{{name}}") + if err != nil { + return fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) log.Printf("[DEBUG] Finished creating Instance %q: %#v", d.Id(), res) diff --git a/google/resource_spanner_database.go b/google/resource_spanner_database.go index 15518a29c3f..b4a45b3fa71 100644 --- a/google/resource_spanner_database.go +++ b/google/resource_spanner_database.go @@ -131,8 +131,9 @@ func resourceSpannerDatabaseCreate(d *schema.ResourceData, meta interface{}) err } d.SetId(id) - err = spannerOperationWaitTime( - config, res, project, "Creating Database", + var response map[string]interface{} + err = spannerOperationWaitTimeWithResponse( + config, res, &response, project, "Creating Database", int(d.Timeout(schema.TimeoutCreate).Minutes())) if err != nil { @@ -140,6 +141,16 @@ func resourceSpannerDatabaseCreate(d *schema.ResourceData, meta interface{}) err d.SetId("") return fmt.Errorf("Error waiting to create Database: %s", err) } + if err := d.Set("name", flattenSpannerDatabaseName(response["name"], d, config)); err != nil { + return err + } + + // This may have caused the ID to update - update it if so. + id, err = replaceVars(d, config, "projects/{{project}}/instances/{{instance}}/databases/{{name}}") + if err != nil { + return fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) log.Printf("[DEBUG] Finished creating Database %q: %#v", d.Id(), res) diff --git a/google/resource_spanner_instance.go b/google/resource_spanner_instance.go index af8ed5b101d..79b47da0ea4 100644 --- a/google/resource_spanner_instance.go +++ b/google/resource_spanner_instance.go @@ -165,8 +165,9 @@ func resourceSpannerInstanceCreate(d *schema.ResourceData, meta interface{}) err } d.SetId(id) - err = spannerOperationWaitTime( - config, res, project, "Creating Instance", + var response map[string]interface{} + err = spannerOperationWaitTimeWithResponse( + config, res, &response, project, "Creating Instance", int(d.Timeout(schema.TimeoutCreate).Minutes())) if err != nil { @@ -174,6 +175,16 @@ func resourceSpannerInstanceCreate(d *schema.ResourceData, meta interface{}) err d.SetId("") return fmt.Errorf("Error waiting to create Instance: %s", err) } + if err := d.Set("name", flattenSpannerInstanceName(response["name"], d, config)); err != nil { + return err + } + + // This may have caused the ID to update - update it if so. + id, err = replaceVars(d, config, "{{project}}/{{name}}") + if err != nil { + return fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) log.Printf("[DEBUG] Finished creating Instance %q: %#v", d.Id(), res) diff --git a/google/resource_tpu_node.go b/google/resource_tpu_node.go index 824a22c4845..3840ac5798e 100644 --- a/google/resource_tpu_node.go +++ b/google/resource_tpu_node.go @@ -270,8 +270,9 @@ func resourceTPUNodeCreate(d *schema.ResourceData, meta interface{}) error { } d.SetId(id) - err = tpuOperationWaitTime( - config, res, project, "Creating Node", + var response map[string]interface{} + err = tpuOperationWaitTimeWithResponse( + config, res, &response, project, "Creating Node", int(d.Timeout(schema.TimeoutCreate).Minutes())) if err != nil { @@ -279,6 +280,16 @@ func resourceTPUNodeCreate(d *schema.ResourceData, meta interface{}) error { d.SetId("") return fmt.Errorf("Error waiting to create Node: %s", err) } + if err := d.Set("name", flattenTPUNodeName(response["name"], d, config)); err != nil { + return err + } + + // This may have caused the ID to update - update it if so. + id, err = replaceVars(d, config, "projects/{{project}}/locations/{{zone}}/nodes/{{name}}") + if err != nil { + return fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) log.Printf("[DEBUG] Finished creating Node %q: %#v", d.Id(), res) diff --git a/google/spanner_operation.go b/google/spanner_operation.go index 8d5e70d48b8..f246c63791b 100644 --- a/google/spanner_operation.go +++ b/google/spanner_operation.go @@ -14,6 +14,7 @@ package google import ( + "encoding/json" "fmt" ) @@ -32,16 +33,38 @@ func (w *SpannerOperationWaiter) QueryOp() (interface{}, error) { return sendRequest(w.Config, "GET", w.Project, url, nil) } -func spannerOperationWaitTime(config *Config, op map[string]interface{}, project, activity string, timeoutMinutes int) error { +func createSpannerWaiter(config *Config, op map[string]interface{}, project, activity string) (*SpannerOperationWaiter, 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 := &SpannerOperationWaiter{ Config: config, Project: project, } if err := w.CommonOperationWaiter.SetOp(op); err != nil { + return nil, err + } + return w, nil +} + +// nolint: deadcode,unused +func spannerOperationWaitTimeWithResponse(config *Config, op map[string]interface{}, response *map[string]interface{}, project, activity string, timeoutMinutes int) error { + w, err := createSpannerWaiter(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 spannerOperationWaitTime(config *Config, op map[string]interface{}, project, activity string, timeoutMinutes int) error { + w, err := createSpannerWaiter(config, op, project, activity) + if err != nil || w == nil { + // If w is nil, the op was synchronous. return err } return OperationWait(w, activity, timeoutMinutes) diff --git a/google/tpu_operation.go b/google/tpu_operation.go index 8962afb7cbe..e65427ca77b 100644 --- a/google/tpu_operation.go +++ b/google/tpu_operation.go @@ -14,6 +14,7 @@ package google import ( + "encoding/json" "fmt" ) @@ -32,16 +33,38 @@ func (w *TPUOperationWaiter) QueryOp() (interface{}, error) { return sendRequest(w.Config, "GET", w.Project, url, nil) } -func tpuOperationWaitTime(config *Config, op map[string]interface{}, project, activity string, timeoutMinutes int) error { +func createTPUWaiter(config *Config, op map[string]interface{}, project, activity string) (*TPUOperationWaiter, 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 := &TPUOperationWaiter{ Config: config, Project: project, } if err := w.CommonOperationWaiter.SetOp(op); err != nil { + return nil, err + } + return w, nil +} + +// nolint: deadcode,unused +func tpuOperationWaitTimeWithResponse(config *Config, op map[string]interface{}, response *map[string]interface{}, project, activity string, timeoutMinutes int) error { + w, err := createTPUWaiter(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 tpuOperationWaitTime(config *Config, op map[string]interface{}, project, activity string, timeoutMinutes int) error { + w, err := createTPUWaiter(config, op, project, activity) + if err != nil || w == nil { + // If w is nil, the op was synchronous. return err } return OperationWait(w, activity, timeoutMinutes) diff --git a/website/docs/r/datastore_index.html.markdown b/website/docs/r/datastore_index.html.markdown new file mode 100644 index 00000000000..90774863a20 --- /dev/null +++ b/website/docs/r/datastore_index.html.markdown @@ -0,0 +1,125 @@ +--- +# ---------------------------------------------------------------------------- +# +# *** 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. +# +# ---------------------------------------------------------------------------- +subcategory: "Cloud Datastore" +layout: "google" +page_title: "Google: google_datastore_index" +sidebar_current: "docs-google-datastore-index" +description: |- + Describes a composite index for Cloud Datastore. +--- + +# google\_datastore\_index + +Describes a composite index for Cloud Datastore. + + +To get more information about Index, see: + +* [API documentation](https://cloud.google.com/datastore/docs/reference/admin/rest/v1/projects.indexes) +* How-to Guides + * [Official Documentation](https://cloud.google.com/datastore/docs/concepts/indexes) + + +## Example Usage - Datastore Index + + +```hcl +resource "google_datastore_index" "default" { + kind = "foo" + properties { + name = "property_a" + direction = "ASCENDING" + } + properties { + name = "property_b" + direction = "ASCENDING" + } +} +``` + +## Argument Reference + +The following arguments are supported: + + +* `kind` - + (Required) + The entity kind which the index applies to. + + +- - - + + +* `ancestor` - + (Optional) + Policy for including ancestors in the index. Either `ALL_ANCESTORS` or `NONE`, + the default is `NONE`. + +* `properties` - + (Optional) + An ordered list of properties to index on. Structure is documented below. + +* `project` - (Optional) The ID of the project in which the resource belongs. + If it is not provided, the provider project is used. + + +The `properties` block supports: + +* `name` - + (Required) + The property name to index. + +* `direction` - + (Required) + The direction the index should optimize for sorting. Possible values are ASCENDING and DESCENDING. + +## Attributes Reference + +In addition to the arguments listed above, the following computed attributes are exported: + +* `id` - an identifier for the resource with format `projects/{{project}}/indexes/{{index_id}}` + +* `index_id` - + The index id. + + +## Timeouts + +This resource provides the following +[Timeouts](/docs/configuration/resources.html#timeouts) configuration options: + +- `create` - Default is 10 minutes. +- `delete` - Default is 10 minutes. + +## Import + +Index can be imported using any of these accepted formats: + +``` +$ terraform import google_datastore_index.default projects/{{project}}/indexes/{{index_id}} +$ terraform import google_datastore_index.default {{project}}/{{index_id}} +$ terraform import google_datastore_index.default {{index_id}} +``` + +-> If you're importing a resource with beta features, make sure to include `-provider=google-beta` +as an argument so that Terraform uses the correct provider to import your resource. + +## User Project Overrides + +This resource supports [User Project Overrides](https://www.terraform.io/docs/providers/google/guides/provider_reference.html#user_project_override). diff --git a/website/google.erb b/website/google.erb index f23934615aa..4185228cf3c 100644 --- a/website/google.erb +++ b/website/google.erb @@ -788,6 +788,15 @@ + > + Google Datastore Resources + + + > Google Dataproc Resources