Skip to content

Commit 9e22cfd

Browse files
authored
feat: Add variable for managing read replica deletion protection (#155)
1 parent 5210126 commit 9e22cfd

File tree

16 files changed

+54
-8
lines changed

16 files changed

+54
-8
lines changed

examples/mssql-public/main.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,6 @@ module "mssql" {
2626
project_id = var.project_id
2727
user_name = "simpleuser"
2828
user_password = "foobar"
29+
30+
deletion_protection = false
2931
}

examples/mysql-ha/main.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ module "mysql" {
5050
database_version = "MYSQL_5_7"
5151
region = "us-central1"
5252

53+
deletion_protection = false
54+
5355
// Master configurations
5456
tier = "db-n1-standard-1"
55-
zone = "c"
57+
zone = "us-central1-c"
5658
availability_type = "REGIONAL"
5759
maintenance_window_day = 7
5860
maintenance_window_hour = 12

examples/mysql-private/main.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,11 @@ module "safer-mysql-db" {
6565
random_instance_name = true
6666
project_id = var.project_id
6767

68+
deletion_protection = false
69+
6870
database_version = "MYSQL_5_6"
6971
region = "us-central1"
70-
zone = "c"
72+
zone = "us-central1-c"
7173
tier = "db-n1-standard-1"
7274

7375
// By default, all users will be permitted to connect only via the

examples/mysql-public/main.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ module "mysql-db" {
3636
random_instance_name = true
3737
database_version = "MYSQL_5_6"
3838
project_id = var.project_id
39-
zone = "c"
39+
zone = "us-central1-c"
4040
region = "us-central1"
4141
tier = "db-n1-standard-1"
4242

43+
deletion_protection = false
44+
4345
ip_configuration = {
4446
ipv4_enabled = true
4547
private_network = null

examples/postgresql-ha/main.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,14 @@ module "pg" {
5050

5151
// Master configurations
5252
tier = "db-custom-2-13312"
53-
zone = "c"
53+
zone = "us-central1-c"
5454
availability_type = "REGIONAL"
5555
maintenance_window_day = 7
5656
maintenance_window_hour = 12
5757
maintenance_window_update_track = "stable"
5858

59+
deletion_protection = false
60+
5961
database_flags = [{ name = "autovacuum", value = "off" }]
6062

6163
user_labels = {
@@ -83,7 +85,6 @@ module "pg" {
8385

8486
// Read replica configurations
8587
read_replica_name_suffix = "-test"
86-
8788
read_replicas = [
8889
{
8990
name = "0"

examples/postgresql-public/main.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ module "postgresql-db" {
3636
random_instance_name = true
3737
database_version = "POSTGRES_9_6"
3838
project_id = var.project_id
39-
zone = "c"
39+
zone = "us-central1-c"
4040
region = "us-central1"
4141
tier = "db-f1-micro"
4242

43+
deletion_protection = false
44+
4345
ip_configuration = {
4446
ipv4_enabled = true
4547
private_network = null

modules/mysql/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Note: CloudSQL provides [disk autoresize](https://cloud.google.com/sql/docs/mysq
3434
| pricing\_plan | The pricing plan for the master instance. | string | `"PER_USE"` | no |
3535
| project\_id | The project ID to manage the Cloud SQL resources | string | n/a | yes |
3636
| random\_instance\_name | Sets random suffix at the end of the Cloud SQL resource name | bool | `"false"` | no |
37+
| read\_replica\_deletion\_protection | Used to block Terraform from deleting replica SQL Instances. | bool | `"false"` | no |
3738
| read\_replica\_name\_suffix | The optional suffix to add to the read instance name | string | `""` | no |
3839
| read\_replicas | List of read replicas to create | object | `<list>` | no |
3940
| region | The region of the Cloud SQL resources | string | `"us-central1"` | no |

modules/mysql/read_replica.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ resource "google_sql_database_instance" "replicas" {
2727
database_version = var.database_version
2828
region = join("-", slice(split("-", lookup(each.value, "zone", var.zone)), 0, 2))
2929
master_instance_name = google_sql_database_instance.default.name
30+
deletion_protection = var.read_replica_deletion_protection
3031

3132
replica_configuration {
3233
failover_target = false

modules/mysql/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,3 +285,9 @@ variable "deletion_protection" {
285285
type = bool
286286
default = true
287287
}
288+
289+
variable "read_replica_deletion_protection" {
290+
description = "Used to block Terraform from deleting replica SQL Instances."
291+
type = bool
292+
default = false
293+
}

modules/postgresql/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Note: CloudSQL provides [disk autoresize](https://cloud.google.com/sql/docs/mysq
3333
| pricing\_plan | The pricing plan for the master instance. | string | `"PER_USE"` | no |
3434
| project\_id | The project ID to manage the Cloud SQL resources | string | n/a | yes |
3535
| random\_instance\_name | Sets random suffix at the end of the Cloud SQL resource name | bool | `"false"` | no |
36+
| read\_replica\_deletion\_protection | Used to block Terraform from deleting replica SQL Instances. | bool | `"false"` | no |
3637
| read\_replica\_name\_suffix | The optional suffix to add to the read instance name | string | `""` | no |
3738
| read\_replicas | List of read replicas to create | object | `<list>` | no |
3839
| region | The region of the Cloud SQL resources | string | `"us-central1"` | no |

0 commit comments

Comments
 (0)