A Cloud Spanner Database which is hosted on a Spanner instance.
To get more information about Database, see:
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
}
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.
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.
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.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.
This resource provides the following Timeouts configuration options:
create
- Default is 20 minutes.update
- Default is 20 minutes.delete
- Default is 20 minutes.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 to import Database using one of the formats above. For example:
import {
id = "projects/{{project}}/instances/{{instance}}/databases/{{name}}"
to = google_spanner_database.default
}
When using the terraform import
command, 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}}
This resource supports User Project Overrides.