diff --git a/.changelog/3085.txt b/.changelog/3085.txt new file mode 100644 index 0000000000..be1bfc44d4 --- /dev/null +++ b/.changelog/3085.txt @@ -0,0 +1,4 @@ +```release-note:new-resource +google_datastore_index + +``` diff --git a/google-beta/access_context_manager_operation.go b/google-beta/access_context_manager_operation.go index c45aaecfeb..e31b715109 100644 --- a/google-beta/access_context_manager_operation.go +++ b/google-beta/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-beta/appengine_operation.go b/google-beta/appengine_operation.go index 0e96a21110..11ebc12f9c 100644 --- a/google-beta/appengine_operation.go +++ b/google-beta/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-beta/config.go b/google-beta/config.go index 7383c053a0..e1e1562517 100644 --- a/google-beta/config.go +++ b/google-beta/config.go @@ -90,6 +90,7 @@ type Config struct { ContainerAnalysisBasePath string DataFusionBasePath string DataprocBasePath string + DatastoreBasePath string DeploymentManagerBasePath string DialogflowBasePath string DNSBasePath string @@ -233,6 +234,7 @@ var ComputeDefaultBasePath = "https://www.googleapis.com/compute/beta/" var ContainerAnalysisDefaultBasePath = "https://containeranalysis.googleapis.com/v1beta1/" var DataFusionDefaultBasePath = "https://datafusion.googleapis.com/v1beta1/" var DataprocDefaultBasePath = "https://dataproc.googleapis.com/v1beta2/" +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/v1beta2/" @@ -734,6 +736,7 @@ func ConfigureBasePaths(c *Config) { c.ContainerAnalysisBasePath = ContainerAnalysisDefaultBasePath c.DataFusionBasePath = DataFusionDefaultBasePath c.DataprocBasePath = DataprocDefaultBasePath + c.DatastoreBasePath = DatastoreDefaultBasePath c.DeploymentManagerBasePath = DeploymentManagerDefaultBasePath c.DialogflowBasePath = DialogflowDefaultBasePath c.DNSBasePath = DNSDefaultBasePath diff --git a/google-beta/data_fusion_operation.go b/google-beta/data_fusion_operation.go index 2a9741cdee..3d45fbaa76 100644 --- a/google-beta/data_fusion_operation.go +++ b/google-beta/data_fusion_operation.go @@ -14,6 +14,7 @@ package google import ( + "encoding/json" "fmt" ) @@ -32,16 +33,38 @@ func (w *DataFusionOperationWaiter) QueryOp() (interface{}, error) { return sendRequest(w.Config, "GET", w.Project, url, nil) } -func dataFusionOperationWaitTime(config *Config, op map[string]interface{}, project, activity string, timeoutMinutes int) error { +func createDataFusionWaiter(config *Config, op map[string]interface{}, project, activity string) (*DataFusionOperationWaiter, 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 := &DataFusionOperationWaiter{ Config: config, Project: project, } if err := w.CommonOperationWaiter.SetOp(op); err != nil { + return nil, err + } + return w, nil +} + +// nolint: deadcode,unused +func dataFusionOperationWaitTimeWithResponse(config *Config, op map[string]interface{}, response *map[string]interface{}, project, activity string, timeoutMinutes int) error { + w, err := createDataFusionWaiter(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 dataFusionOperationWaitTime(config *Config, op map[string]interface{}, project, activity string, timeoutMinutes int) error { + w, err := createDataFusionWaiter(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-beta/datastore_operation.go b/google-beta/datastore_operation.go new file mode 100644 index 0000000000..c9b1b5380e --- /dev/null +++ b/google-beta/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-beta/filestore_operation.go b/google-beta/filestore_operation.go index 7885f36ff8..39038b6dd4 100644 --- a/google-beta/filestore_operation.go +++ b/google-beta/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-beta/firestore_operation.go b/google-beta/firestore_operation.go index 2e99c69331..a0c4330a1c 100644 --- a/google-beta/firestore_operation.go +++ b/google-beta/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-beta/ml_engine_operation.go b/google-beta/ml_engine_operation.go index 653acea5f9..48770b36d4 100644 --- a/google-beta/ml_engine_operation.go +++ b/google-beta/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-beta/provider.go b/google-beta/provider.go index 772d884655..1ff77480ea 100644 --- a/google-beta/provider.go +++ b/google-beta/provider.go @@ -237,6 +237,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, @@ -539,9 +547,9 @@ func Provider() terraform.ResourceProvider { return provider } -// Generated resources: 117 +// Generated resources: 118 // Generated IAM resources: 51 -// Total generated resources: 168 +// Total generated resources: 169 func ResourceMap() map[string]*schema.Resource { resourceMap, _ := ResourceMapWithErrors() return resourceMap @@ -639,6 +647,7 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) { "google_container_analysis_note": resourceContainerAnalysisNote(), "google_data_fusion_instance": resourceDataFusionInstance(), "google_dataproc_autoscaling_policy": resourceDataprocAutoscalingPolicy(), + "google_datastore_index": resourceDatastoreIndex(), "google_deployment_manager_deployment": resourceDeploymentManagerDeployment(), "google_dialogflow_agent": resourceDialogflowAgent(), "google_dns_managed_zone": resourceDNSManagedZone(), @@ -895,6 +904,7 @@ func providerConfigure(d *schema.ResourceData, p *schema.Provider, terraformVers config.ContainerAnalysisBasePath = d.Get("container_analysis_custom_endpoint").(string) config.DataFusionBasePath = d.Get("data_fusion_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-beta/redis_operation.go b/google-beta/redis_operation.go index 9424810ae7..570cd808cd 100644 --- a/google-beta/redis_operation.go +++ b/google-beta/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-beta/resource_access_context_manager_access_level.go b/google-beta/resource_access_context_manager_access_level.go index 5777be23b4..045e814314 100644 --- a/google-beta/resource_access_context_manager_access_level.go +++ b/google-beta/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-beta/resource_access_context_manager_access_policy.go b/google-beta/resource_access_context_manager_access_policy.go index 67230319de..3ce2cb0ede 100644 --- a/google-beta/resource_access_context_manager_access_policy.go +++ b/google-beta/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-beta/resource_access_context_manager_service_perimeter.go b/google-beta/resource_access_context_manager_service_perimeter.go index b8d1ef14b1..8d5964a8ff 100644 --- a/google-beta/resource_access_context_manager_service_perimeter.go +++ b/google-beta/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-beta/resource_access_context_manager_service_perimeter_resource.go b/google-beta/resource_access_context_manager_service_perimeter_resource.go index 9251feb213..7dc3d94831 100644 --- a/google-beta/resource_access_context_manager_service_perimeter_resource.go +++ b/google-beta/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-beta/resource_app_engine_domain_mapping.go b/google-beta/resource_app_engine_domain_mapping.go index 62cc1bae09..f98294f5e3 100644 --- a/google-beta/resource_app_engine_domain_mapping.go +++ b/google-beta/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-beta/resource_data_fusion_instance.go b/google-beta/resource_data_fusion_instance.go index 39efaddd89..7b92b381cf 100644 --- a/google-beta/resource_data_fusion_instance.go +++ b/google-beta/resource_data_fusion_instance.go @@ -264,8 +264,9 @@ func resourceDataFusionInstanceCreate(d *schema.ResourceData, meta interface{}) } d.SetId(id) - err = dataFusionOperationWaitTime( - config, res, project, "Creating Instance", + var response map[string]interface{} + err = dataFusionOperationWaitTimeWithResponse( + config, res, &response, project, "Creating Instance", int(d.Timeout(schema.TimeoutCreate).Minutes())) if err != nil { @@ -273,6 +274,16 @@ func resourceDataFusionInstanceCreate(d *schema.ResourceData, meta interface{}) d.SetId("") return fmt.Errorf("Error waiting to create Instance: %s", err) } + if err := d.Set("name", flattenDataFusionInstanceName(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-beta/resource_datastore_index.go b/google-beta/resource_datastore_index.go new file mode 100644 index 0000000000..bd3c97b95b --- /dev/null +++ b/google-beta/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-beta/resource_datastore_index_generated_test.go b/google-beta/resource_datastore_index_generated_test.go new file mode 100644 index 0000000000..280b97d3e9 --- /dev/null +++ b/google-beta/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-beta/resource_filestore_instance.go b/google-beta/resource_filestore_instance.go index e398762be4..3120b672b4 100644 --- a/google-beta/resource_filestore_instance.go +++ b/google-beta/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-beta/resource_firestore_index.go b/google-beta/resource_firestore_index.go index 8d9bf27803..bbde97363e 100644 --- a/google-beta/resource_firestore_index.go +++ b/google-beta/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-beta/resource_manager_operation.go b/google-beta/resource_manager_operation.go index 4c7ec6079b..3e42774b02 100644 --- a/google-beta/resource_manager_operation.go +++ b/google-beta/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-beta/resource_redis_instance.go b/google-beta/resource_redis_instance.go index 09f9dcbb7b..fcf826fad3 100644 --- a/google-beta/resource_redis_instance.go +++ b/google-beta/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-beta/resource_spanner_database.go b/google-beta/resource_spanner_database.go index 15518a29c3..b4a45b3fa7 100644 --- a/google-beta/resource_spanner_database.go +++ b/google-beta/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-beta/resource_spanner_instance.go b/google-beta/resource_spanner_instance.go index af8ed5b101..79b47da0ea 100644 --- a/google-beta/resource_spanner_instance.go +++ b/google-beta/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-beta/resource_tpu_node.go b/google-beta/resource_tpu_node.go index 824a22c484..3840ac5798 100644 --- a/google-beta/resource_tpu_node.go +++ b/google-beta/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-beta/resource_vpc_access_connector.go b/google-beta/resource_vpc_access_connector.go index 553a0c730d..be0c503a20 100644 --- a/google-beta/resource_vpc_access_connector.go +++ b/google-beta/resource_vpc_access_connector.go @@ -163,8 +163,9 @@ func resourceVPCAccessConnectorCreate(d *schema.ResourceData, meta interface{}) } d.SetId(id) - err = vpcAccessOperationWaitTime( - config, res, project, "Creating Connector", + var response map[string]interface{} + err = vpcAccessOperationWaitTimeWithResponse( + config, res, &response, project, "Creating Connector", int(d.Timeout(schema.TimeoutCreate).Minutes())) if err != nil { @@ -172,6 +173,16 @@ func resourceVPCAccessConnectorCreate(d *schema.ResourceData, meta interface{}) d.SetId("") return fmt.Errorf("Error waiting to create Connector: %s", err) } + if err := d.Set("name", flattenVPCAccessConnectorName(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}}/connectors/{{name}}") + if err != nil { + return fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) log.Printf("[DEBUG] Finished creating Connector %q: %#v", d.Id(), res) diff --git a/google-beta/spanner_operation.go b/google-beta/spanner_operation.go index 8d5e70d48b..f246c63791 100644 --- a/google-beta/spanner_operation.go +++ b/google-beta/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-beta/tpu_operation.go b/google-beta/tpu_operation.go index 8962afb7cb..e65427ca77 100644 --- a/google-beta/tpu_operation.go +++ b/google-beta/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/google-beta/vpc_access_operation.go b/google-beta/vpc_access_operation.go index 5619ae69f5..c1ab477fe5 100644 --- a/google-beta/vpc_access_operation.go +++ b/google-beta/vpc_access_operation.go @@ -14,6 +14,7 @@ package google import ( + "encoding/json" "fmt" ) @@ -32,16 +33,38 @@ func (w *VPCAccessOperationWaiter) QueryOp() (interface{}, error) { return sendRequest(w.Config, "GET", w.Project, url, nil) } -func vpcAccessOperationWaitTime(config *Config, op map[string]interface{}, project, activity string, timeoutMinutes int) error { +func createVPCAccessWaiter(config *Config, op map[string]interface{}, project, activity string) (*VPCAccessOperationWaiter, 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 := &VPCAccessOperationWaiter{ Config: config, Project: project, } if err := w.CommonOperationWaiter.SetOp(op); err != nil { + return nil, err + } + return w, nil +} + +// nolint: deadcode,unused +func vpcAccessOperationWaitTimeWithResponse(config *Config, op map[string]interface{}, response *map[string]interface{}, project, activity string, timeoutMinutes int) error { + w, err := createVPCAccessWaiter(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 vpcAccessOperationWaitTime(config *Config, op map[string]interface{}, project, activity string, timeoutMinutes int) error { + w, err := createVPCAccessWaiter(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 0000000000..90774863a2 --- /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 97fe5b1901..eb7ed0f5d1 100644 --- a/website/google.erb +++ b/website/google.erb @@ -875,6 +875,15 @@ + > + Google Datastore Resources + + + > Google Dataproc Resources