Google Cloud Spanner Database

This page shows how to write Terraform for Cloud Spanner Database and write them securely.

code-icon

Fix issues in your cloud & app configurations

Test for misconfigurations of this resource in your cloud.

get-started-button

Terraform Example (google_spanner_database)

A Cloud Spanner Database which is hosted on a Spanner instance. To get more information about Database, see:

  • API documentation
  • How-to Guides
    • Official Documentation

      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 for more information on lifecycle parameters.

Parameters

  • ddl optional - list / string
    • 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.

  • deletion_protection optional - bool
  • id optionalcomputed - string
  • instance required - string
    • The instance to create the database on.

  • name required - string
    • 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].

  • project optionalcomputed - string
  • state requiredcomputed - string
    • An explanation of the status of the database.

Example Usage (from GitHub)

github-iconankit25587/course-material
resource "google_spanner_database" "db1"{
    name = "db1"
    instance =  google_spanner_instance.spanner_tf.name
github-iconfarrukh90/gcp
resource "google_spanner_database" "database" {
  instance            = google_spanner_instance.main.name
  name                = var.config["name"]
  ddl                 = var.databases
  deletion_protection = false
}
github-iconbhupeshdavesar/kpmg
resource "google_spanner_database" "database" {
  project  = var.project_id
  instance = var.spanner_instance_name
  name     = var.name
  ddl      = var.ddl

github-iconMirlan777/terraform-google
resource "google_spanner_database" "database" {
    instance = google_spanner_instance.main.name
    name = var.config["name"]
    ddl = var.databases
    deletion_protection = false
}
github-iconTaherasharifi/terraform-google
resource "google_spanner_database" "database" {
    instance = google_spanner_instance.main.name
    name = var.config["name"]
    ddl = var.databases
    deletion_protection = false
}

Frequently asked questions

What is Google Cloud Spanner Database?

Google Cloud Spanner Database is a resource for Cloud Spanner of Google Cloud Platform. Settings can be wrote in Terraform.

Where can I find the example code for the Google Cloud Spanner Database?

For Terraform, the ankit25587/course-material, farrukh90/gcp and bhupeshdavesar/kpmg source code examples are useful. See the Terraform Example section for further details.