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:

Example Usage - Firestore Index Basic

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

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

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:

The fields block supports:

The vector_config block supports:


Attributes Reference

In addition to the arguments listed above, the following computed attributes are exported:

Timeouts

This resource provides the following Timeouts configuration options:

Import

Index can be imported using any of these accepted formats:

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}}

User Project Overrides

This resource supports User Project Overrides.