Support instance deletion protection (#56)

also bump google provider version to 3.57.0
This commit is contained in:
Rob Morgan
2021-02-23 11:49:03 +08:00
committed by GitHub
parent f2a6c5d401
commit 0b560e6d0e
10 changed files with 58 additions and 20 deletions

View File

@@ -45,6 +45,9 @@ resource "google_sql_database_instance" "master" {
region = var.region
database_version = var.engine
# Whether or not to allow Terraform to destroy the instance.
deletion_protection = var.deletion_protection
settings {
tier = var.machine_type
activation_policy = var.activation_policy
@@ -173,6 +176,9 @@ resource "google_sql_database_instance" "failover_replica" {
# The name of the instance that will act as the master in the replication setup.
master_instance_name = google_sql_database_instance.master.name
# Whether or not to allow Terraform to destroy the instance.
deletion_protection = var.deletion_protection
replica_configuration {
# Specifies that the replica is the failover target.
failover_target = true
@@ -253,6 +259,9 @@ resource "google_sql_database_instance" "read_replica" {
# The name of the instance that will act as the master in the replication setup.
master_instance_name = google_sql_database_instance.master.name
# Whether or not to allow Terraform to destroy the instance.
deletion_protection = var.deletion_protection
replica_configuration {
# Specifies that the replica is not the failover target.
failover_target = false

View File

@@ -232,6 +232,13 @@ variable "resource_timeout" {
default = "60m"
}
# Whether or not to allow Terraform to destroy the instance.
variable "deletion_protection" {
description = "Whether or not to allow Terraform to destroy the instance. Unless this field is set to false in Terraform state, a terraform destroy or terraform apply command that deletes the instance will fail."
type = bool
default = "true"
}
# ---------------------------------------------------------------------------------------------------------------------
# MODULE DEPENDENCIES
# Workaround Terraform limitation where there is no module depends_on.