diff --git a/.changelog/8713.txt b/.changelog/8713.txt new file mode 100644 index 0000000000..9a36c5d99f --- /dev/null +++ b/.changelog/8713.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +firestore: added `api_scope` field to `google_firestore_index` resource +``` diff --git a/google-beta/services/firestore/resource_firestore_index.go b/google-beta/services/firestore/resource_firestore_index.go index 6699eb7eff..27af3a5f3e 100644 --- a/google-beta/services/firestore/resource_firestore_index.go +++ b/google-beta/services/firestore/resource_firestore_index.go @@ -134,6 +134,14 @@ Only one of 'order' and 'arrayConfig' can be specified. Possible values: ["ASCEN }, }, }, + "api_scope": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + ValidateFunc: verify.ValidateEnum([]string{"ANY_API", "DATASTORE_MODE_API", ""}), + Description: `The API scope at which a query is run. Default value: "ANY_API" Possible values: ["ANY_API", "DATASTORE_MODE_API"]`, + Default: "ANY_API", + }, "database": { Type: schema.TypeString, Optional: true, @@ -145,8 +153,8 @@ Only one of 'order' and 'arrayConfig' can be specified. Possible values: ["ASCEN Type: schema.TypeString, Optional: true, ForceNew: true, - ValidateFunc: verify.ValidateEnum([]string{"COLLECTION", "COLLECTION_GROUP", ""}), - Description: `The scope at which a query is run. Default value: "COLLECTION" Possible values: ["COLLECTION", "COLLECTION_GROUP"]`, + ValidateFunc: verify.ValidateEnum([]string{"COLLECTION", "COLLECTION_GROUP", "COLLECTION_RECURSIVE", ""}), + Description: `The scope at which a query is run. Default value: "COLLECTION" Possible values: ["COLLECTION", "COLLECTION_GROUP", "COLLECTION_RECURSIVE"]`, Default: "COLLECTION", }, "name": { @@ -192,6 +200,12 @@ func resourceFirestoreIndexCreate(d *schema.ResourceData, meta interface{}) erro } else if v, ok := d.GetOkExists("query_scope"); !tpgresource.IsEmptyValue(reflect.ValueOf(queryScopeProp)) && (ok || !reflect.DeepEqual(v, queryScopeProp)) { obj["queryScope"] = queryScopeProp } + apiScopeProp, err := expandFirestoreIndexApiScope(d.Get("api_scope"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("api_scope"); !tpgresource.IsEmptyValue(reflect.ValueOf(apiScopeProp)) && (ok || !reflect.DeepEqual(v, apiScopeProp)) { + obj["apiScope"] = apiScopeProp + } fieldsProp, err := expandFirestoreIndexFields(d.Get("fields"), d, config) if err != nil { return err @@ -328,6 +342,9 @@ func resourceFirestoreIndexRead(d *schema.ResourceData, meta interface{}) error if err := d.Set("query_scope", flattenFirestoreIndexQueryScope(res["queryScope"], d, config)); err != nil { return fmt.Errorf("Error reading Index: %s", err) } + if err := d.Set("api_scope", flattenFirestoreIndexApiScope(res["apiScope"], d, config)); err != nil { + return fmt.Errorf("Error reading Index: %s", err) + } if err := d.Set("fields", flattenFirestoreIndexFields(res["fields"], d, config)); err != nil { return fmt.Errorf("Error reading Index: %s", err) } @@ -426,6 +443,14 @@ func flattenFirestoreIndexQueryScope(v interface{}, d *schema.ResourceData, conf return v } +func flattenFirestoreIndexApiScope(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + if v == nil || tpgresource.IsEmptyValue(reflect.ValueOf(v)) { + return "ANY_API" + } + + return v +} + func flattenFirestoreIndexFields(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { if v == nil { return v @@ -470,6 +495,10 @@ func expandFirestoreIndexQueryScope(v interface{}, d tpgresource.TerraformResour return v, nil } +func expandFirestoreIndexApiScope(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + func expandFirestoreIndexFields(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { l := v.([]interface{}) req := make([]interface{}, 0, len(l)) diff --git a/google-beta/services/firestore/resource_firestore_index_generated_test.go b/google-beta/services/firestore/resource_firestore_index_generated_test.go index 8db34a5cfd..57d741a963 100644 --- a/google-beta/services/firestore/resource_firestore_index_generated_test.go +++ b/google-beta/services/firestore/resource_firestore_index_generated_test.go @@ -78,6 +78,56 @@ resource "google_firestore_index" "my-index" { `, context) } +func TestAccFirestoreIndex_firestoreIndexDatastoreModeExample(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "project_id": envvar.GetTestFirestoreProjectFromEnv(t), + "random_suffix": acctest.RandString(t, 10), + } + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + CheckDestroy: testAccCheckFirestoreIndexDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccFirestoreIndex_firestoreIndexDatastoreModeExample(context), + }, + { + ResourceName: "google_firestore_index.my-datastore-mode-index", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"database", "collection"}, + }, + }, + }) +} + +func testAccFirestoreIndex_firestoreIndexDatastoreModeExample(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_firestore_index" "my-datastore-mode-index" { + project = "%{project_id}" + + collection = "chatrooms" + + query_scope = "COLLECTION_RECURSIVE" + api_scope = "DATASTORE_MODE_API" + + fields { + field_path = "name" + order = "ASCENDING" + } + + fields { + field_path = "description" + order = "DESCENDING" + } + +} +`, context) +} + func testAccCheckFirestoreIndexDestroyProducer(t *testing.T) func(s *terraform.State) error { return func(s *terraform.State) error { for name, rs := range s.RootModule().Resources { diff --git a/website/docs/r/firestore_index.html.markdown b/website/docs/r/firestore_index.html.markdown index ff9c169a5a..38eaf0a9c4 100644 --- a/website/docs/r/firestore_index.html.markdown +++ b/website/docs/r/firestore_index.html.markdown @@ -32,12 +32,11 @@ To get more information about Index, see: ~> **Warning:** This resource creates a Firestore Index on a project that already has a Firestore database. If you haven't already created it, you may -create a `google_firestore_database` resource with `type` set to -`"FIRESTORE_NATIVE"` and `location_id` set to your chosen location. -If you wish to use App Engine, you may instead create a -`google_app_engine_application` resource with `database_type` set to -`"CLOUD_FIRESTORE"`. Your Firestore location will be the same as -the App Engine location specified. +create a `google_firestore_database` resource and `location_id` set +to your chosen location. If you wish to use App Engine, you may +instead create a `google_app_engine_application` resource with +`database_type` set to `"CLOUD_FIRESTORE"`. Your Firestore location +will be the same as the App Engine location specified. ## Example Usage - Firestore Index Basic @@ -58,6 +57,30 @@ resource "google_firestore_index" "my-index" { order = "DESCENDING" } +} +``` +## Example Usage - Firestore Index Datastore Mode + + +```hcl +resource "google_firestore_index" "my-datastore-mode-index" { + project = "my-project-name" + + collection = "chatrooms" + + query_scope = "COLLECTION_RECURSIVE" + api_scope = "DATASTORE_MODE_API" + + fields { + field_path = "name" + order = "ASCENDING" + } + + fields { + field_path = "description" + order = "DESCENDING" + } + } ``` @@ -110,7 +133,13 @@ The following arguments are supported: (Optional) The scope at which a query is run. Default value is `COLLECTION`. - Possible values are: `COLLECTION`, `COLLECTION_GROUP`. + Possible values are: `COLLECTION`, `COLLECTION_GROUP`, `COLLECTION_RECURSIVE`. + +* `api_scope` - + (Optional) + The API scope at which a query is run. + Default value is `ANY_API`. + Possible values are: `ANY_API`, `DATASTORE_MODE_API`. * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used.