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
resource "google_spanner_instance" "spanner_inst" {
config = var.spanner_config
display_name = "spanner-poc"
num_nodes = var.num_spanner_nodes
force_destroy = true
# labels = {
resource "google_spanner_instance" "spanner_tf" {
name = "spannertf"
config = "regional-asia-south1"
display_name = "Spanner from TF"
num_nodes = 1
labels = {
resource "google_spanner_instance" "main" {
config = var.config["config"]
display_name = var.config["display_name"]
}
resource "google_spanner_database" "database" {
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
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
Parameters
-
config
required - string
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.
-
display_name
required - string
The descriptive name for this instance as it appears in UIs. Must be unique per project and between 4 and 30 characters in length.
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.
-
num_nodes
optional - number
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:
- API documentation
- How-to Guides
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.