Skip to content

googleFirestoreDocument

In Cloud Firestore, the unit of storage is the document. A document is a lightweight record that contains fields, which map to values. Each document is identified by a name.

To get more information about Document, see:

\~> Warning: This resource creates a Firestore Document on a project that already has a Firestore database. If you haven't already created it, you may create a googleFirestoreDatabase resource with type set to "firestoreNative" and locationId set to your chosen location. If you wish to use App Engine, you may instead create a googleAppEngineApplication resource with databaseType set to "cloudFirestore". Your Firestore location will be the same as the App Engine location specified.

Example Usage - Firestore Document Basic

resource "google_firestore_document" "mydoc" {
  project     = "my-project-name"
  collection  = "somenewcollection"
  document_id = "my-doc-%{random_suffix}"
  fields      = "{\"something\":{\"mapValue\":{\"fields\":{\"akey\":{\"stringValue\":\"avalue\"}}}}}"
}

Example Usage - Firestore Document Nested Document

resource "google_firestore_document" "mydoc" {
  project     = "my-project-name"
  collection  = "somenewcollection"
  document_id = "my-doc-%{random_suffix}"
  fields      = "{\"something\":{\"mapValue\":{\"fields\":{\"akey\":{\"stringValue\":\"avalue\"}}}}}"
}

resource "google_firestore_document" "sub_document" {
  project     = "my-project-name"
  collection  = "${google_firestore_document.mydoc.path}/subdocs"
  document_id = "bitcoinkey"
  fields      = "{\"something\":{\"mapValue\":{\"fields\":{\"ayo\":{\"stringValue\":\"val2\"}}}}}"
}

resource "google_firestore_document" "sub_sub_document" {
  project     = "my-project-name"
  collection  = "${google_firestore_document.sub_document.path}/subsubdocs"
  document_id = "asecret"
  fields      = "{\"something\":{\"mapValue\":{\"fields\":{\"secret\":{\"stringValue\":\"hithere\"}}}}}"
}

Argument Reference

The following arguments are supported:

  • fields - (Required) The document's fields formated as a json string.

  • collection - (Required) The collection ID, relative to database. For example: chatrooms or chatrooms/my-document/private-messages.

  • documentId - (Required) The client-assigned document ID to use for this document during creation.


  • database - (Optional) The Firestore database id. Defaults to "(default)".

  • project - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

Attributes Reference

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/{{projectId}}/databases/{{databaseId}}/documents/{{path}}/{{documentId}}

  • path - A relative path to the collection this document exists within

  • createTime - Creation timestamp in RFC3339 format.

  • updateTime - Last update timestamp in RFC3339 format.

Timeouts

This resource provides the following Timeouts configuration options:

  • create - Default is 20 minutes.
  • update - Default is 20 minutes.
  • delete - Default is 20 minutes.

Import

Document can be imported using any of these accepted formats:

$ terraform import google_firestore_document.default {{name}}

User Project Overrides

This resource supports User Project Overrides.