Google Cloud Spanner Instance

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

google_spanner_instance (Terraform)

The Instance in Cloud Spanner can be configured in Terraform with the resource name google_spanner_instance. The following sections describe 5 examples of how to use the resource and its parameters.

Example Usage from GitHub

spanner.tf#L1
resource "google_spanner_instance" "spanner_inst" {
  config       = var.spanner_config
  display_name = "spanner-poc"
  num_nodes    = var.num_spanner_nodes
  force_destroy = true
  #   labels = {
main.tf#L1
resource "google_spanner_instance" "spanner_tf" {
  name = "spannertf"
  config = "regional-asia-south1"
  display_name = "Spanner from TF"
  num_nodes = 1
  labels = {
cloudspanner.tf#L1
resource "google_spanner_instance" "main" {
  config       = var.config["config"]
  display_name = var.config["display_name"]
}

resource "google_spanner_database" "database" {
main.tf#L1
resource "google_spanner_instance" "instance" {
  project      = var.project_id
  config       = var.config
  name         = var.name
  display_name = var.display_name
  num_nodes    = var.num_nodes
spanner.tf#L1
resource "google_spanner_instance" "main" {
    config = var.config["config"]
    display_name = var.config["display_name"]
}
resource "google_spanner_database" "database" {
    instance = google_spanner_instance.main.name

Review your Terraform file for Google best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

The name of the instance's configuration (similar but not quite the same as a region) which defines 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 Configuration section of the docs.

The descriptive name for this instance as it appears in UIs. Must be unique per project and between 4 and 30 characters in length.

  • id optional computed - string
  • labels optional - map from string to string

An object containing a list of "key": value pairs. Example: [ "name": "wrench", "mass": "1.3kg", "count": "3" ].

  • name optional computed - string

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. If not provided, a random string starting with 'tf-' will be selected.

The number of nodes allocated to this instance.

Instance status: 'CREATING' or 'READY'.

Explanation in Terraform Registry

An isolated set of Cloud Spanner resources on which databases can be hosted. To get more information about Instance, see:

Frequently asked questions

What is Google Cloud Spanner Instance?

Google Cloud Spanner Instance 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 Instance?

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

security-icon

Automate config file reviews on your commits

Fix issues in your infrastructure as code with auto-generated patches.