| --- |
| # ---------------------------------------------------------------------------- |
| # |
| # *** AUTO GENERATED CODE *** Type: MMv1 *** |
| # |
| # ---------------------------------------------------------------------------- |
| # |
| # 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: "Firestore" |
| description: |- |
| Cloud Firestore indexes enable simple and complex queries against documents in a database. |
| --- |
| |
| # google\_firestore\_index |
| |
| Cloud Firestore indexes enable simple and complex queries against documents in a database. |
| This resource manages composite indexes and not single |
| field indexes. |
| |
| |
| To get more information about Index, see: |
| |
| * [API documentation](https://cloud.google.com/firestore/docs/reference/rest/v1/projects.databases.collectionGroups.indexes) |
| * How-to Guides |
| * [Official Documentation](https://cloud.google.com/firestore/docs/query-data/indexing) |
| |
| ~> **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 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 |
| |
| |
| ```hcl |
| resource "google_project" "project" { |
| project_id = "project-id" |
| name = "project-id" |
| org_id = "123456789" |
| } |
| |
| resource "time_sleep" "wait_60_seconds" { |
| depends_on = [google_project.project] |
| |
| create_duration = "60s" |
| } |
| |
| resource "google_project_service" "firestore" { |
| project = google_project.project.project_id |
| service = "firestore.googleapis.com" |
| |
| # Needed for CI tests for permissions to propagate, should not be needed for actual usage |
| depends_on = [time_sleep.wait_60_seconds] |
| } |
| |
| resource "google_firestore_database" "database" { |
| project = google_project.project.project_id |
| name = "(default)" |
| location_id = "nam5" |
| type = "FIRESTORE_NATIVE" |
| |
| depends_on = [google_project_service.firestore] |
| } |
| |
| # Creating a document also creates its collection |
| resource "google_firestore_document" "document" { |
| project = google_project.project.project_id |
| database = google_firestore_database.database.name |
| collection = "somenewcollection" |
| document_id = "" |
| fields = "{\"something\":{\"mapValue\":{\"fields\":{\"akey\":{\"stringValue\":\"avalue\"}}}}}" |
| } |
| |
| resource "google_firestore_index" "my-index" { |
| project = google_project.project.project_id |
| database = google_firestore_database.database.name |
| collection = google_firestore_document.document.collection |
| |
| fields { |
| field_path = "name" |
| order = "ASCENDING" |
| } |
| |
| fields { |
| field_path = "description" |
| order = "DESCENDING" |
| } |
| |
| } |
| ``` |
| ## Example Usage - Firestore Index Datastore Mode |
| |
| |
| ```hcl |
| resource "google_firestore_index" "my-index" { |
| project = "my-project-name" |
| database = "(default)" |
| collection = "chatrooms" |
| |
| query_scope = "COLLECTION_RECURSIVE" |
| api_scope = "DATASTORE_MODE_API" |
| |
| fields { |
| field_path = "name" |
| order = "ASCENDING" |
| } |
| |
| fields { |
| field_path = "description" |
| order = "DESCENDING" |
| } |
| } |
| ``` |
| |
| ## Argument Reference |
| |
| The following arguments are supported: |
| |
| |
| * `collection` - |
| (Required) |
| The collection being indexed. |
| |
| * `fields` - |
| (Required) |
| The fields supported by this index. The last field entry is always for |
| the field path `__name__`. If, on creation, `__name__` was not |
| specified as the last field, it will be added automatically with the |
| same direction as that of the last field defined. If the final field |
| in a composite index is not directional, the `__name__` will be |
| ordered `"ASCENDING"` (unless explicitly specified otherwise). |
| Structure is [documented below](#nested_fields). |
| |
| |
| <a name="nested_fields"></a>The `fields` block supports: |
| |
| * `field_path` - |
| (Optional) |
| Name of the field. |
| |
| * `order` - |
| (Optional) |
| Indicates that this field supports ordering by the specified order or comparing using =, <, <=, >, >=. |
| Only one of `order` and `arrayConfig` can be specified. |
| Possible values are: `ASCENDING`, `DESCENDING`. |
| |
| * `array_config` - |
| (Optional) |
| Indicates that this field supports operations on arrayValues. Only one of `order` and `arrayConfig` can |
| be specified. |
| Possible values are: `CONTAINS`. |
| |
| - - - |
| |
| |
| * `database` - |
| (Optional) |
| The Firestore database id. Defaults to `"(default)"`. |
| |
| * `query_scope` - |
| (Optional) |
| The scope at which a query is run. |
| Default value is `COLLECTION`. |
| 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. |
| |
| |
| ## Attributes Reference |
| |
| In addition to the arguments listed above, the following computed attributes are exported: |
| |
| * `id` - an identifier for the resource with format `{{name}}` |
| |
| * `name` - |
| A server defined name for this index. Format: |
| `projects/{{project}}/databases/{{database}}/collectionGroups/{{collection}}/indexes/{{server_generated_id}}` |
| |
| |
| ## Timeouts |
| |
| This resource provides the following |
| [Timeouts](https://developer.hashicorp.com/terraform/plugin/sdkv2/resources/retries-and-customizable-timeouts) configuration options: |
| |
| - `create` - Default is 20 minutes. |
| - `delete` - Default is 20 minutes. |
| |
| ## Import |
| |
| |
| Index can be imported using any of these accepted formats: |
| |
| * `{{name}}` |
| |
| |
| In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import Index using one of the formats above. For example: |
| |
| ```tf |
| import { |
| id = "{{name}}" |
| to = google_firestore_index.default |
| } |
| ``` |
| |
| When using the [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import), Index can be imported using one of the formats above. For example: |
| |
| ``` |
| $ terraform import google_firestore_index.default {{name}} |
| ``` |
| |
| ## User Project Overrides |
| |
| This resource supports [User Project Overrides](https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/provider_reference#user_project_override). |