Google Firestore Index
This page shows how to write Terraform for Firestore Index and write them securely.
google_firestore_index (Terraform)
The Index in Firestore can be configured in Terraform with the resource name google_firestore_index
. The following sections describe 5 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "google_firestore_index" "composite-name-location-asc" {
project = var.project
collection = var.collection
database = "(default)"
fields {
resource "google_firestore_index" "dev-consent-form" {
project = google_project.covidguard_lis_server.project_id
collection = "dev_consent"
fields {
resource "google_firestore_index" "trainings_user_time" {
collection = "trainings"
fields {
field_path = "UserUuid"
order = "ASCENDING"
resource "google_firestore_index" "trainings_user_time" {
collection = "trainings"
fields {
field_path = "UserUuid"
order = "ASCENDING"
resource "google_firestore_index" "trainings_user_time" {
collection = "trainings"
fields {
field_path = "UserUuid"
order = "ASCENDING"
Parameters
-
collection
required - string
The collection being indexed.
-
database
optional - string
The Firestore database id. Defaults to '"(default)"'.
A server defined name for this index. Format: 'projects/[[project]]/databases/[[database]]/collectionGroups/[[collection]]/indexes/[[server_generated_id]]'
-
project
optional computed - string -
query_scope
optional - string
The scope at which a query is run. Default value: "COLLECTION" Possible values: ["COLLECTION", "COLLECTION_GROUP"]
-
fields
list block-
array_config
optional - string
Indicates that this field supports operations on arrayValues. Only one of 'order' and 'arrayConfig' can be specified. Possible values: ["CONTAINS"]
-
field_path
optional - string
Name of the field.
-
order
optional - string
Indicates that this field supports ordering by the specified order or comparing using =, <, <=, >, >=. Only one of 'order' and 'arrayConfig' can be specified. Possible values: ["ASCENDING", "DESCENDING"]
-
-
timeouts
single block
Explanation in Terraform Registry
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
- How-to Guides
- Official Documentation
Warning: This resource creates a Firestore Index on a project that already has Firestore enabled. If you haven't already enabled it, you can create a
google_app_engine_application
resource withdatabase_type
set to"CLOUD_FIRESTORE"
to do so. Your Firestore location will be the same as the App Engine location specified.
Frequently asked questions
What is Google Firestore Index?
Google Firestore Index is a resource for Firestore of Google Cloud Platform. Settings can be wrote in Terraform.
Where can I find the example code for the Google Firestore Index?
For Terraform, the Black-Artist-Database/blmsheet-terraform, sreeram-boyapati/covid-contact-tracing and franckf-git/reference-go source code examples are useful. See the Terraform Example section for further details.