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:
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"
}
}
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"
}
}
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 {}
}
}
}
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.
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.
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.
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}}
This resource provides the following Timeouts configuration options:
create
- Default is 20 minutes.delete
- Default is 20 minutes.Index can be imported using any of these accepted formats:
{{name}}
In Terraform v1.5.0 and later, use an import
block to import Index using one of the formats above. For example:
import {
id = "{{name}}"
to = google_firestore_index.default
}
When using the terraform import
command, Index can be imported using one of the formats above. For example:
$ terraform import google_firestore_index.default {{name}}
This resource supports User Project Overrides.