You can use Terraform to create, manage and delete Cloud Spanner resources. Google Terraform modules provide Cloud Spanner support via the following resources:
- google_spanner_instance
- google_spanner_instance_iam
- google_spanner_database
- google_spanner_database_iam
Google Terraform modules can be authenticated
- A service key in JSON format, see documentation for more.
- Application Default Credentials (ADC),
automatically available on GCP machines or via
gcloud auth application-default login
.
You can checkout into the following directories and run terraform apply
to
create a plan and apply changes. The following examples use Application Default
Credentials (ADC) to authenticate. Refer to the
credentials file
to authenticate with a service account.
Edit the main.tf file and replace YOUR_PROJECT_ID
with your Google Cloud project ID.
- regional - Regional cluster with a database.
- multi-regional - Multi-regional cluster with a database.
- lifecycle - Database protected with lifecycle argument against accidental deletion.
Alternatively, a step-by-step tutorial is also available as a codelab.
Please file bugs and feedback to the Cloud Spanner Terraform resources on the Google Terraform Module. Issues and feedback to the examples are appreciated on this repo.