Skip to content

Commit 5e39538

Browse files
authored
fix!: add deletion_protection to backup module and set it to false in … (#670)
1 parent 8cb3a03 commit 5e39538

File tree

8 files changed

+26
-4
lines changed

8 files changed

+26
-4
lines changed

examples/mysql-backup-create-service-account/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,5 @@ module "backup" {
5656
backup_schedule = "5 * * * *"
5757
export_schedule = "10 * * * *"
5858
compress_export = false
59+
deletion_protection = false
5960
}

examples/postgresql-backup-provided-service-account/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ module "backup" {
7070
service_account = "${data.google_project.test_project.number}-compute@developer.gserviceaccount.com"
7171
create_notification_channel = false
7272
notification_channels = [google_monitoring_notification_channel.email.id]
73+
deletion_protection = false
7374
}
7475

7576
data "google_project" "test_project" {

examples/postgresql-with-cross-region-failover/kms.tf

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,22 @@ resource "google_project_service_identity" "cloudsql_sa" {
6060
service = "sqladmin.googleapis.com"
6161
}
6262

63+
resource "time_sleep" "wait_10m" {
64+
depends_on = [google_project_service_identity.cloudsql_sa]
65+
create_duration = "10m"
66+
}
67+
6368
resource "google_kms_crypto_key_iam_member" "crypto_key_region1" {
6469
crypto_key_id = google_kms_crypto_key.cloudsql_region1_key.id
6570
role = "roles/cloudkms.cryptoKeyEncrypterDecrypter"
66-
member = "serviceAccount:${google_project_service_identity.cloudsql_sa.email}"
71+
member = google_project_service_identity.cloudsql_sa.member
72+
depends_on = [time_sleep.wait_10m]
6773
}
6874

6975
resource "google_kms_crypto_key_iam_member" "crypto_key_region2" {
7076
crypto_key_id = google_kms_crypto_key.cloudsql_region2_key.id
7177
role = "roles/cloudkms.cryptoKeyEncrypterDecrypter"
72-
member = "serviceAccount:${google_project_service_identity.cloudsql_sa.email}"
78+
member = google_project_service_identity.cloudsql_sa.member
79+
depends_on = [time_sleep.wait_10m]
7380
}
7481

modules/backup/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ fetch workflows.googleapis.com/Workflow
6060
| compress\_export | Whether or not to compress the export when storing in the bucket; Only valid for MySQL and PostgreSQL | `bool` | `true` | no |
6161
| connector\_params\_timeout | The end-to-end duration the connector call is allowed to run for before throwing a timeout exception. The default value is 1800 and this should be the maximum for connector methods that are not long-running operations. Otherwise, for long-running operations, the maximum timeout for a connector call is 31536000 seconds (one year). | `number` | `1800` | no |
6262
| create\_notification\_channel | If set to true it will create email notification channel | `bool` | `false` | no |
63+
| deletion\_protection | Whether Terraform will be prevented from destroying the workflow. | `bool` | `true` | no |
6364
| enable\_backup\_monitoring | Whether to monitor backup workflows or not | `bool` | `false` | no |
6465
| enable\_connector\_params | Whether to enable connector-specific parameters for Google Workflow SQL Export. | `bool` | `false` | no |
6566
| enable\_export\_backup | Weather to create exports to GCS Buckets with this module | `bool` | `true` | no |

modules/backup/main.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ resource "google_workflows_workflow" "sql_backup" {
9999
backupRetentionTime = var.backup_retention_time
100100
backupRunsListMaxResults = var.backup_runs_list_max_results
101101
})
102+
deletion_protection = var.deletion_protection
102103
}
103104

104105
resource "google_cloud_scheduler_job" "sql_backup" {
@@ -171,6 +172,7 @@ resource "google_workflows_workflow" "sql_export" {
171172
logDbName = var.log_db_name_to_export
172173
serverlessExport = var.use_serverless_export
173174
})
175+
deletion_protection = var.deletion_protection
174176
}
175177

176178
resource "google_cloud_scheduler_job" "sql_export" {

modules/backup/metadata.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ spec:
2727
dir: /modules/backup
2828
actuationTool:
2929
flavor: Terraform
30-
version: ">= 0.13"
30+
version: ">= 1.3"
3131
description: {}
3232
content:
3333
examples:
@@ -89,6 +89,10 @@ spec:
8989
description: If set to true it will create email notification channel
9090
varType: bool
9191
defaultValue: false
92+
- name: deletion_protection
93+
description: Whether Terraform will be prevented from destroying the workflow.
94+
varType: bool
95+
defaultValue: true
9296
- name: enable_backup_monitoring
9397
description: Whether to monitor backup workflows or not
9498
varType: bool

modules/backup/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,9 @@ variable "notification_channels" {
192192
type = list(string)
193193
default = []
194194
}
195+
196+
variable "deletion_protection" {
197+
description = "Whether Terraform will be prevented from destroying the workflow."
198+
type = bool
199+
default = true
200+
}

modules/backup/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ terraform {
1919
required_providers {
2020
google = {
2121
source = "hashicorp/google"
22-
version = ">= 4.0, < 7"
22+
version = ">= 6.11.0, < 7"
2323
}
2424
}
2525
}

0 commit comments

Comments
 (0)