diff options
author | Stan Hu <stanhu@gmail.com> | 2022-01-28 19:52:24 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2022-01-31 21:42:30 +0300 |
commit | b5e0045dbbd4b4ab1c0407ef26258dd4cf6b77df (patch) | |
tree | 73bcaafede29f14ff565d99cc601f6c58d2882c5 | |
parent | d56fd8e9ba34ec7d54f7390e4ceab9adb43e49d9 (diff) |
demo: Fix deletion of Praefect Cloud SQL instance
Previously attempting to destroy a cluster would result in the following errors:
```
Error: Error, failed to deleteuser praefect in instance <instance name>
```
```
Error: Error, failed to delete instance because deletion_protection
is set to true. Set it to false to proceed with instance deletion
```
For the `deleteuser` error,
https://github.com/hashicorp/terraform-provider-google/issues/7677 has
added the `ABANDON` flag, which according to
https://github.com/GoogleCloudPlatform/magic-modules/pull/4231:
```
Setting ABANDON allows the resource to be abandoned rather than
deleted. This is useful for Postgres, where users cannot be deleted from
the API if they have been granted SQL roles.
```
For the `delete_protection` error, as described in
https://stackoverflow.com/a/64911997, recent versions of Terraform sets
`delete_protection` on by default. We need to disable this to be able to
destroy this Cloud SQL instance.
Changelog: fixed
-rw-r--r-- | _support/terraform/terraform/main.tf | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/_support/terraform/terraform/main.tf b/_support/terraform/terraform/main.tf index 87bc8c9a9..ba42feca3 100644 --- a/_support/terraform/terraform/main.tf +++ b/_support/terraform/terraform/main.tf @@ -22,7 +22,7 @@ variable "praefect_disk_size" { default = "10" } variable "praefect_sql_password" { } provider "google" { - version = "~> 3.12" + version = "~> 3.90" project = var.project region = var.demo_region @@ -43,6 +43,7 @@ resource "google_sql_database_instance" "praefect_sql" { name = "${var.praefect_demo_cluster_name}-praefect-postgresql-${random_id.db_name_suffix.hex}" database_version = "POSTGRES_12" region = var.demo_region + deletion_protection = false settings { tier = "db-f1-micro" @@ -85,6 +86,7 @@ resource "google_sql_user" "users" { name = "praefect" instance = google_sql_database_instance.praefect_sql.name password = var.praefect_sql_password + deletion_policy = "ABANDON" } resource "google_sql_database" "praefect-database" { |