Skip to content

Commit 20eabd8

Browse files
committed
Improve db deletion protection
1 parent f624397 commit 20eabd8

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

docs/concourse/README.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,25 @@ terragrunt run-all apply
111111
## Recommendations
112112
### Cloud SQL Instance deletion protection
113113

114-
Terraform hashicorp provider includes a deletion protection flag however in some cases it's misleading as it's not setting it on Google Cloud.
115-
To avoid confusion we do not set it in the code and recommend altering your production SQL Instance to protect from the deletion on the cloud side.
114+
The [database.tf](../../terraform-modules/concourse/infra/database.tf) configuration enables deletion protection on multiple levels. The Terraform hashicorp provider includes a deletion protection flag:
115+
```
116+
resource "google_sql_database_instance" "concourse" {
117+
118+
# This option prevents Terraform from deleting an instance
119+
deletion_protection = true
120+
```
121+
122+
In addition, we are setting a flag that enables the "Prevent instance deletion" option from the GCP console:
123+
```
124+
settings {
125+
deletion_protection_enabled = "true"
126+
}
127+
```
128+
129+
:warning: The option "Retain backups after instance deletion" should also be enabled. There is no Terraform configuration parameter,
130+
so you have to set it manually in the GCP console:
116131

117-
https://console.cloud.google.com/sql/instances/ -> select instance name -> edit -> Data Protection -> tick: Enable delete protection
132+
Cloud SQL -> Instances -> Edit configuration -> Data Protection -> Retain backups after instance deletion
118133

119134
### End-to-end testing
120135

terraform-modules/concourse/infra/database.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ resource "google_sql_database_instance" "concourse" {
44
project = var.project
55
region = var.region
66

7-
# recommended protection via GCP SQL Instance settings
8-
# https://console.cloud.google.com/sql/instances/ -> select instance name -> edit
9-
# -> Data Protection -> tick: Enable delete protection
10-
deletion_protection = false
7+
# This option prevents Terraform from deleting an instance
8+
deletion_protection = true
119

1210
settings {
1311
activation_policy = "ALWAYS"
@@ -28,6 +26,8 @@ resource "google_sql_database_instance" "concourse" {
2826
transaction_log_retention_days = "7"
2927
}
3028

29+
deletion_protection_enabled = "true"
30+
3131
disk_autoresize = "true"
3232
disk_autoresize_limit = "0"
3333
disk_size = var.sql_instance_disk_size

0 commit comments

Comments
 (0)