Skip to content

GoogleCloudPlatform/terraform-google-firestore

Repository files navigation

terraform-google-firestore

Description

Tagline

This terraform module is used to create a Cloud Firestore database

Detailed

The resources/services/activations/deletions that this module will create/trigger are:

  • Creates a Cloud Firestore database.
  • Creates a daily/weekly backup schedule for the Firestore database.
  • Creates composite indexes for the database.
  • Creates single fields exempt from default indexing for the database.

Usage

Basic usage of this module is as follows:

module "firestore_infra" {
  source = "terraform-google-modules/firestore/google"
  project_id = "<PROJECT_ID>"
  database_id = "firestore-test-db"
  location_id = "us-central1"
  database_type = "FIRESTORE_NATIVE"
  concurrency_mode = "OPTIMISTIC"
  delete_protection_state = "DELETE_PROTECTION_DISABLED"
  point_in_time_recovery_enablement = "POINT_IN_TIME_RECOVERY_DISABLED"
  deletion_policy = "ABANDON"
  backup_schedule_configuration = {
    daily_recurrence = {}
    retention = "2419200s"
  }

  composite_index_configuration = [
    {
      index_id = "my-index1"
      collection = "terraform-firestore-collection"
      query_scope = "COLLECTION"
      api_scope = "ANY_API"
      fields = [
        {
          field_path = "field1"
          order = "ASCENDING"
        },
        {
          field_path = "field2"
          order = "DESCENDING"
        }
      ]
    }
  ]

  field_configuration = [
    {
      collection = "reviews"
      field = "field3"
      ascending_index_query_scope = ["COLLECTION_GROUP"]
      descending_index_query_scope = ["COLLECTION_GROUP"]
      array_index_query_scope = ["COLLECTION"]
    },
    {
      collection = "reviews"
      field = "field4"
      ascending_index_query_scope = ["COLLECTION_GROUP", "COLLECTION_GROUP"]
    }
  ]
}

Functional examples are included in the examples directory.

Inputs

Name Description Type Default Required
backup_schedule_configuration Backup schedule configuration for the Firestore Database.
object({
weekly_recurrence = optional(object({
day = string
retention = string
}))

daily_recurrence = optional(object({
retention = string
}))
})
null no
composite_index_configuration Composite index configuration for the Firestore Database.
list(object({
index_id = string
collection = string
query_scope = optional(string, "COLLECTION")
api_scope = optional(string, "ANY_API")
density = optional(string)
multikey = optional(bool)
fields = list(object({
field_path = string
order = optional(string)
array_config = optional(string)
vector_config = optional(object({
dimension = number
}))
}))
}))
[] no
concurrency_mode Concurrency control mode to be used for the Firestore Database. string "PESSIMISTIC" no
database_edition The database edition used to create the Firestore database. string "STANDARD" no
database_id Unique identifier of the Firestore Database. string n/a yes
database_type Database type used to created the Firestore Database. string "FIRESTORE_NATIVE" no
delete_protection_state Determines whether deletion protection is enabled or not for the Firestore Database. string "DELETE_PROTECTION_ENABLED" no
deletion_policy Deletion policy enforced when Firestore Database is destroyed via Terraform. string "DELETE" no
field_configuration Single field configurations for the Firestore Database.
list(object({
collection = string
field = string
ttl_enabled = optional(bool, false)
ascending_index_query_scope = optional(set(string), [])
descending_index_query_scope = optional(set(string), [])
array_index_query_scope = optional(set(string), [])
}))
[] no
kms_key_name The resource ID of the Customer-managed Encryption Key (CMEK) using which the created database will be encrypted. string null no
location The location in which the Firesotre Database is created. string n/a yes
point_in_time_recovery_enablement Determines whether point-in-time recovery is enabled for the Firestore Database. string "POINT_IN_TIME_RECOVERY_ENABLED" no
project_id The ID of the project in which the Firestore resources are created. string n/a yes

Outputs

Name Description
composite_index_ids List of composite indices for the firestore database.
daily_backup_schedule_id The unique backup schedule identifier across all locations and databases for the given project.
database_id The full database resource name of the firestore database, in the format projects/{{project_id}}/databases/{{name}}
database_resource_id The database id of the firestore database.
field_ids List of firestore fields created for the database.
weekly_backup_schedule_id The unique backup schedule identifier across all locations and databases for the given project.

Requirements

These sections describe requirements for using this module.

Software

The following dependencies must be available:

Service Account

A service account with the following roles must be used to provision the resources of this module:

  • Storage Admin: roles/storage.admin

The Project Factory module and the IAM module may be used in combination to provision a service account with the necessary roles applied.

APIs

A project with the following APIs enabled must be used to host the resources of this module:

  • Google Cloud Storage JSON API: storage-api.googleapis.com

The Project Factory module can be used to provision a project with the necessary APIs enabled.

Contributing

Refer to the contribution guidelines for information on contributing to this module.

Security Disclosures

Please see our security disclosure process.

About

Create and manage Google Cloud Firestore resources

Topics

Resources

License

Contributing

Security policy

Stars

5 stars

Watchers

13 watching

Forks

Packages

 
 
 

Contributors