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

main.tf#L1
resource "google_firestore_index" "composite-name-location-asc" {
    project           = var.project
    collection        = var.collection
    database          = "(default)"

    fields {
indexes.tf#L2
resource "google_firestore_index" "dev-consent-form" {
  project     = google_project.covidguard_lis_server.project_id

  collection = "dev_consent"

  fields {
firestore.tf#L9
resource "google_firestore_index" "trainings_user_time" {
  collection = "trainings"

  fields {
    field_path = "UserUuid"
    order      = "ASCENDING"
firestore.tf#L9
resource "google_firestore_index" "trainings_user_time" {
  collection = "trainings"

  fields {
    field_path = "UserUuid"
    order      = "ASCENDING"
firestore.tf#L9
resource "google_firestore_index" "trainings_user_time" {
  collection = "trainings"

  fields {
    field_path = "UserUuid"
    order      = "ASCENDING"

Review your Terraform file for Google best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

The collection being indexed.

The Firestore database id. Defaults to '"(default)"'.

  • id optional computed - string
  • name optional computed - string

A server defined name for this index. Format: 'projects/[[project]]/databases/[[database]]/collectionGroups/[[collection]]/indexes/[[server_generated_id]]'

The scope at which a query is run. Default value: "COLLECTION" Possible values: ["COLLECTION", "COLLECTION_GROUP"]

  • fields list block

    Indicates that this field supports operations on arrayValues. Only one of 'order' and 'arrayConfig' can be specified. Possible values: ["CONTAINS"]

    Name of the field.

    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 with database_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.

security-icon

Automate config file reviews on your commits

Fix issues in your infrastructure as code with auto-generated patches.