blob: 543e4ec4e2528cfb6c20e7de8b417d41bee813a5 [file] [log] [blame] [edit]
---
# ----------------------------------------------------------------------------
#
# *** 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.
Both Firestore Native and Datastore Mode indexes are supported.
This resource manages composite indexes and not single field indexes.
To manage single field indexes, use the `google_firestore_field` resource instead.
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.
Your Firestore location will be the same as the App Engine location specified.
## Example Usage - Firestore Index Basic
```hcl
resource "google_firestore_database" "database" {
project = "my-project-name"
name = "database-id"
location_id = "nam5"
type = "FIRESTORE_NATIVE"
delete_protection_state = "DELETE_PROTECTION_DISABLED"
deletion_policy = "DELETE"
}
resource "google_firestore_index" "my-index" {
project = "my-project-name"
database = google_firestore_database.database.name
collection = "atestcollection"
fields {
field_path = "name"
order = "ASCENDING"
}
fields {
field_path = "description"
order = "DESCENDING"
}
}
```
## Example Usage - Firestore Index Datastore Mode
```hcl
resource "google_firestore_database" "database" {
project = "my-project-name"
name = "database-id-dm"
location_id = "nam5"
type = "DATASTORE_MODE"
delete_protection_state = "DELETE_PROTECTION_DISABLED"
deletion_policy = "DELETE"
}
resource "google_firestore_index" "my-index" {
project = "my-project-name"
database = google_firestore_database.database.name
collection = "atestcollection"
query_scope = "COLLECTION_RECURSIVE"
api_scope = "DATASTORE_MODE_API"
fields {
field_path = "name"
order = "ASCENDING"
}
fields {
field_path = "description"
order = "DESCENDING"
}
}
```
## Example Usage - Firestore Index Vector
```hcl
resource "google_firestore_database" "database" {
project = "my-project-name"
name = "database-id-vector"
location_id = "nam5"
type = "FIRESTORE_NATIVE"
delete_protection_state = "DELETE_PROTECTION_DISABLED"
deletion_policy = "DELETE"
}
resource "google_firestore_index" "my-index" {
project = "my-project-name"
database = google_firestore_database.database.name
collection = "atestcollection"
fields {
field_path = "field_name"
order = "ASCENDING"
}
fields {
field_path = "__name__"
order = "ASCENDING"
}
fields {
field_path = "description"
vector_config {
dimension = 128
flat {}
}
}
}
```
## Argument Reference
The following arguments are supported:
* `collection` -
(Required)
The collection being indexed.
* `fields` -
(Required)
The fields supported by this index. The last non-stored 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`, `arrayConfig`, and `vectorConfig` can be specified.
Possible values are: `ASCENDING`, `DESCENDING`.
* `array_config` -
(Optional)
Indicates that this field supports operations on arrayValues. Only one of `order`, `arrayConfig`, and
`vectorConfig` can be specified.
Possible values are: `CONTAINS`.
* `vector_config` -
(Optional)
Indicates that this field supports vector search operations. Only one of `order`, `arrayConfig`, and
`vectorConfig` can be specified. Vector Fields should come after the field path `__name__`.
Structure is [documented below](#nested_vector_config).
<a name="nested_vector_config"></a>The `vector_config` block supports:
* `dimension` -
(Optional)
The resulting index will only include vectors of this dimension, and can be used for vector search
with the same dimension.
* `flat` -
(Optional)
Indicates the vector index is a flat index.
- - -
* `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).