Skip to content

GoogleCloudPlatform/terraform-google-cloud-spanner

Repository files navigation

terraform-google-cloud-spanner

This module is used to create a Cloud Spanner Instance.

The resources/services/activations/deletions that this module will create/trigger are:

  • Creates a Cloud Spanner Instance
  • Creates a Cloud Spanner Database
  • Creates a Cloud Spanner Database Backup Scheduler

Usage

Basic usage of this module is as follows:

module "cloud_spanner" {
  source  = "terraform-google-modules/cloud-spanner/google"
  version = "~> 0.3"

  project_id  = "<PROJECT ID>"
  instance_name = "spanner-instance"
  instance_display_name = "Sapnner DEV"
  instance_size = {
    # num_nodes = 2
    processing_units = 200
  }
  instance_config = "regional-europe-west1"
  instance_labels = {
    "key" = "value"
  }
  database_config = {
    db1 = {
      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
      database_iam        = []
      enable_backup       = false
      backup_retention    = 86400
      create_db           = true
    }
  }
  backup_schedule = "0 */6 * * *"
}

Functional examples are included in the examples directory.

Inputs

Name Description Type Default Required
backup_schedule The schedule to be enabled on scheduler to trigger spanner DB backup string "0 */6 * * *" no
backup_schedule_region The schedule to be enabled on scheduler to trigger spanner DB backup string "us-central1" no
create_instance Switch to use create OR use existing Spanner Instance bool true no
database_config The list of databases with their configuration to be created
map(object({
version_retention_period = string
ddl = list(string)
kms_key_name = optional(string)
deletion_protection = bool
database_iam = list(string)
enable_backup = optional(bool)
backup_retention = optional(number)
create_db = optional(bool)
}))
{
"db1": {
"backup_retention": 86400,
"create_db": true,
"database_iam": [],
"ddl": [],
"deletion_protection": false,
"enable_backup": true,
"version_retention_period": "3d"
}
}
no
instance_config The name of the instance's configuration (similar but not quite the same as a region) which defines the geographic placement and replication of your databases in this instance. string n/a yes
instance_display_name The descriptive name for this instance as it appears in UIs. string "regional-europe-west1" no
instance_iam The list of permissions on spanner instance list(string) [] no
instance_labels A set of key/value label pairs to assign to the spanner instance map(string) {} no
instance_name A unique identifier for the instance, which cannot be changed after the instance is created. The name must be between 6 and 30 characters in length. string "regional-europe-west1" no
instance_size The sizing configuration of Spanner Instance based on num of nodes OR instance processing units.
object({
num_nodes = optional(number)
processing_units = optional(number)
})
n/a yes
project_id The project ID to deploy to string n/a yes

Outputs

Name Description
cloud_scheduler_id Spanner Backup Cloud Scheduler ID
spanner_db_details Spanner Databases information map
spanner_instance_id Spanner Instance ID
workflow_id Spanner Backup Workflow ID

Requirements

These sections describe requirements for using this module.

Software

The following dependencies must be available:

Service Account

A service account with the following roles must be used to provision the resources of this module:

  • Spanner Admin: roles/spanner.admin

The Project Factory module and the IAM module may be used in combination to provision a service account with the necessary roles applied.

APIs

A project with the following APIs enabled must be used to host the resources of this module:

  • iam.googleapis.com
  • cloudresourcemanager.googleapis.com
  • storage-api.googleapis.com
  • serviceusage.googleapis.com
  • workflows.googleapis.com
  • cloudscheduler.googleapis.com
  • spanner.googleapis.com
  • pubsub.googleapis.com
  • logging.googleapis.com
  • storage.googleapis.com
  • appengine.googleapis.com
  • cloudkms.googleapis.com

The Project Factory module can be used to provision a project with the necessary APIs enabled.

Contributing

Refer to the contribution guidelines for information on contributing to this module.

Security Disclosures

Please see our security disclosure process.