blob: 465fa056ae6254a1cd8e60da4c4111c5018c2f38 [file] [log] [blame]
---
# ----------------------------------------------------------------------------
#
# *** AUTO GENERATED CODE *** Type: MMv1 ***
#
# ----------------------------------------------------------------------------
#
# This file is automatically generated by Magic Modules and manual
# changes will be clobbered when the file is regenerated.
#
# Please read more about how to change this file in
# .github/CONTRIBUTING.md.
#
# ----------------------------------------------------------------------------
subcategory: "Firestore"
description: |-
In Cloud Firestore, the unit of storage is the document.
---
# google\_firestore\_document
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:
* [API documentation](https://cloud.google.com/firestore/docs/reference/rest/v1/projects.databases.documents)
* How-to Guides
* [Official Documentation](https://cloud.google.com/firestore/docs/manage-data/add-data)
~> **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 `google_firestore_database` resource with `type` set to
`"FIRESTORE_NATIVE"` and `location_id` set to your chosen location.
If you wish to use App Engine, you may instead create a
`google_app_engine_application` resource with `database_type` set to
`"CLOUD_FIRESTORE"`. Your Firestore location will be the same as
the App Engine location specified.
Note: The surface does not support configurable database id. Only `(default)`
is allowed for the database parameter.
## Example Usage - Firestore Document Basic
```hcl
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\"}}}}}"
}
```
## Example Usage - Firestore Document Nested Document
```hcl
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\"}}}}}"
}
```
## Argument Reference
The following arguments are supported:
* `fields` -
(Required)
The document's [fields](https://cloud.google.com/firestore/docs/reference/rest/v1/projects.databases.documents) 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.
## 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/{{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.
## Timeouts
This resource provides the following
[Timeouts](https://developer.hashicorp.com/terraform/plugin/sdkv2/resources/retries-and-customizable-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:
* `{{name}}`
In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import Document using one of the formats above. For example:
```tf
import {
id = "{{name}}"
to = google_firestore_document.default
}
```
When using the [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import), Document can be imported using one of the formats above. For example:
```
$ terraform import google_firestore_document.default {{name}}
```
## User Project Overrides
This resource supports [User Project Overrides](https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/provider_reference#user_project_override).