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:
resource "google_project" "project" {
project_id = "project-id"
name = "project-id"
org_id = "123456789"
}
resource "time_sleep" "wait_60_seconds" {
depends_on = [google_project.project]
create_duration = "60s"
}
resource "google_project_service" "firestore" {
project = google_project.project.project_id
service = "firestore.googleapis.com"
# Needed for CI tests for permissions to propagate, should not be needed for actual usage
depends_on = [time_sleep.wait_60_seconds]
}
resource "google_firestore_database" "database" {
project = google_project.project.project_id
name = "(default)"
location_id = "nam5"
type = "FIRESTORE_NATIVE"
depends_on = [google_project_service.firestore]
}
resource "google_firestore_document" "mydoc" {
project = google_project.project.project_id
database = google_firestore_database.database.name
collection = "somenewcollection"
document_id = "my-doc-id"
fields = "{\"something\":{\"mapValue\":{\"fields\":{\"akey\":{\"stringValue\":\"avalue\"}}}}}"
}
resource "google_project" "project" {
project_id = "project-id"
name = "project-id"
org_id = "123456789"
}
resource "time_sleep" "wait_60_seconds" {
depends_on = [google_project.project]
create_duration = "60s"
}
resource "google_project_service" "firestore" {
project = google_project.project.project_id
service = "firestore.googleapis.com"
# Needed for CI tests for permissions to propagate, should not be needed for actual usage
depends_on = [time_sleep.wait_60_seconds]
}
resource "google_firestore_database" "database" {
project = google_project.project.project_id
name = "(default)"
location_id = "nam5"
type = "FIRESTORE_NATIVE"
depends_on = [google_project_service.firestore]
}
resource "google_firestore_document" "mydoc" {
project = google_project.project.project_id
database = google_firestore_database.database.name
collection = "somenewcollection"
document_id = "my-doc-id"
fields = "{\"something\":{\"mapValue\":{\"fields\":{\"akey\":{\"stringValue\":\"avalue\"}}}}}"
}
resource "google_firestore_document" "sub_document" {
project = google_project.project.project_id
database = google_firestore_database.database.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 = google_project.project.project_id
database = google_firestore_database.database.name
collection = "${google_firestore_document.sub_document.path}/subsubdocs"
document_id = "asecret"
fields = "{\"something\":{\"mapValue\":{\"fields\":{\"secret\":{\"stringValue\":\"hithere\"}}}}}"
}
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.
document_id
-
(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.
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 document. Format:
projects/{{project_id}}/databases/{{database_id}}/documents/{{path}}/{{document_id}}
path
-
A relative path to the collection this document exists within
create_time
-
Creation timestamp in RFC3339 format.
update_time
-
Last update timestamp in RFC3339 format.
This resource provides the following Timeouts configuration options:
create
- Default is 20 minutes.update
- Default is 20 minutes.delete
- Default is 20 minutes.Document can be imported using any of these accepted formats:
{{name}}
In Terraform v1.5.0 and later, use an import
block to import Document using one of the formats above. For example:
import {
id = "{{name}}"
to = google_firestore_document.default
}
When using the terraform import
command, Document can be imported using one of the formats above. For example:
$ terraform import google_firestore_document.default {{name}}
This resource supports User Project Overrides.