Skip to content

livechat/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 = "~> 1.1"

  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
create_instance Switch to use create OR use existing Spanner Instance bool true no
cron_spec_text The cron expression for the backup schedule. string "0 2 * * *" no
database_config The list of databases with their configuration to be created
map(object({
version_retention_period = string
ddl = optional(list(string), [])
kms_key_name = optional(string)
deletion_protection = bool
database_iam = optional(list(string), [])
enable_backup = optional(bool)
backup_retention = optional(string)
create_db = optional(bool)
}))
{
"db1": {
"backup_retention": "86400s",
"create_db": true,
"database_iam": [],
"ddl": [],
"deletion_protection": false,
"enable_backup": true,
"version_retention_period": "3d"
}
}
no
default_backup_schedule_type Default backup schedule type for new databases. string "NONE" no
edition The edition of the Spanner instance. string "STANDARD" no
enable_autoscaling Enable autoscaling for the Spanner Instance bool false no
force_destroy Whether to force destroy the instance and its backups. bool false no
high_priority_cpu_utilization_percent Target high priority CPU utilization percentage for autoscaling. number 60 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. It determines where your data is stored. Values are typically of the form regional-europe-west1, us-central etc. In order to obtain a valid list please consult the https://cloud.google.com/spanner/docs/instance-configurations string n/a yes
instance_display_name The descriptive name for this instance as it appears in UIs. string "spanner-instance" 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 n/a yes
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
max_nodes Maximum number of nodes for autoscaling. number 3 no
max_processing_units Maximum number of processing units for autoscaling. number 3000 no
min_nodes Minimum number of nodes for autoscaling. number 1 no
min_processing_units Minimum number of processing units for autoscaling. number 1000 no
override_max_nodes Maximum number of nodes for specific replica overrides. number 3 no
override_min_nodes Minimum number of nodes for specific replica overrides. number 1 no
project_id The project ID to deploy to string n/a yes
replica_location Location of the replica for asymmetric autoscaling. string "us-central1" no
storage_utilization_percent Target storage utilization percentage for autoscaling. number 70 no
use_full_backup_spec Whether to use full backup specification. bool true no
use_incremental_backup_spec Whether to use incremental backup specification. bool false no

Outputs

Name Description
env_vars Map of environment variables for Spanner databases with keys as project_id:instance_name:database_name and values as fully qualified database paths
spanner_db_details Spanner Databases information map
spanner_instance_id Spanner Instance ID
spanner_schedule_backup_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.

Releases

No releases published

Packages

No packages published

Languages

  • HCL 57.8%
  • Go 34.0%
  • Makefile 8.2%