blob: 81e68fdc246e8cf5f86334904dafa367fe15261a [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: "Cloud Spanner"
description: |-
A Cloud Spanner Database which is hosted on a Spanner instance.
---
# google\_spanner\_database
A Cloud Spanner Database which is hosted on a Spanner instance.
To get more information about Database, see:
* [API documentation](https://cloud.google.com/spanner/docs/reference/rest/v1/projects.instances.databases)
* How-to Guides
* [Official Documentation](https://cloud.google.com/spanner/)
~> **Warning:** On newer versions of the provider, you must explicitly set `deletion_protection=false`
(and run `terraform apply` to write the field to state) in order to destroy an instance.
It is recommended to not set this field (or set it to true) until you're ready to destroy.
On older versions, it is strongly recommended to set `lifecycle { prevent_destroy = true }`
on databases in order to prevent accidental data loss. See
[Terraform docs](https://developer.hashicorp.com/terraform/language/meta-arguments/lifecycle#prevent_destroy)
for more information on lifecycle parameters.
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=spanner_database_basic&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
</a>
</div>
## Example Usage - Spanner Database Basic
```hcl
resource "google_spanner_instance" "main" {
config = "regional-europe-west1"
display_name = "main-instance"
num_nodes = 1
}
resource "google_spanner_database" "database" {
instance = google_spanner_instance.main.name
name = "my-database"
version_retention_period = "3d"
ddl = [
"CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)",
"CREATE TABLE t2 (t2 INT64 NOT NULL,) PRIMARY KEY(t2)",
]
deletion_protection = false
}
```
## Argument Reference
The following arguments are supported:
* `name` -
(Required)
A unique identifier for the database, which cannot be changed after
the instance is created. Values are of the form [a-z][-a-z0-9]*[a-z0-9].
* `instance` -
(Required)
The instance to create the database on.
- - -
* `version_retention_period` -
(Optional)
The retention period for the database. The retention period must be between 1 hour
and 7 days, and can be specified in days, hours, minutes, or seconds. For example,
the values 1d, 24h, 1440m, and 86400s are equivalent. Default value is 1h.
If this property is used, you must avoid adding new DDL statements to `ddl` that
update the database's version_retention_period.
* `ddl` -
(Optional)
An optional list of DDL statements to run inside the newly created
database. Statements can create tables, indexes, etc. These statements
execute atomically with the creation of the database: if there is an
error in any statement, the database is not created.
* `encryption_config` -
(Optional)
Encryption configuration for the database
Structure is [documented below](#nested_encryption_config).
* `database_dialect` -
(Optional)
The dialect of the Cloud Spanner Database.
If it is not provided, "GOOGLE_STANDARD_SQL" will be used.
Possible values are: `GOOGLE_STANDARD_SQL`, `POSTGRESQL`.
* `enable_drop_protection` -
(Optional)
Whether drop protection is enabled for this database. Defaults to false.
Drop protection is different from
the "deletion_protection" attribute in the following ways:
(1) "deletion_protection" only protects the database from deletions in Terraform.
whereas setting enableDropProtection to true protects the database from deletions in all interfaces.
(2) Setting "enableDropProtection" to true also prevents the deletion of the parent instance containing the database.
"deletion_protection" attribute does not provide protection against the deletion of the parent instance.
* `project` - (Optional) The ID of the project in which the resource belongs.
If it is not provided, the provider project is used.
* `deletion_protection` - (Optional) Whether or not to allow Terraform to destroy the database. Defaults to true. Unless this field is set to false
in Terraform state, a `terraform destroy` or `terraform apply` that would delete the database will fail.
<a name="nested_encryption_config"></a>The `encryption_config` block supports:
* `kms_key_name` -
(Required)
Fully qualified name of the KMS key to use to encrypt this database. This key must exist
in the same location as the Spanner Database.
## Attributes Reference
In addition to the arguments listed above, the following computed attributes are exported:
* `id` - an identifier for the resource with format `{{instance}}/{{name}}`
* `state` -
An explanation of the status of the database.
## 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
Database can be imported using any of these accepted formats:
* `projects/{{project}}/instances/{{instance}}/databases/{{name}}`
* `instances/{{instance}}/databases/{{name}}`
* `{{project}}/{{instance}}/{{name}}`
* `{{instance}}/{{name}}`
In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import Database using one of the formats above. For example:
```tf
import {
id = "projects/{{project}}/instances/{{instance}}/databases/{{name}}"
to = google_spanner_database.default
}
```
When using the [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import), Database can be imported using one of the formats above. For example:
```
$ terraform import google_spanner_database.default projects/{{project}}/instances/{{instance}}/databases/{{name}}
$ terraform import google_spanner_database.default instances/{{instance}}/databases/{{name}}
$ terraform import google_spanner_database.default {{project}}/{{instance}}/{{name}}
$ terraform import google_spanner_database.default {{instance}}/{{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).