forked from GoogleCloudPlatform/magic-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sql database add deletion policy (GoogleCloudPlatform#6821)
* feat: adding deletion_policy=abandon to google_sql_database resource * feat: honing in on correct behavior of google_sql_database * feat: got tests to pass * fix: simplified adding deletion_policy to google_sql_database * chore: switch deletion_policy to virtual field
- Loading branch information
Showing
3 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
mmv1/templates/terraform/examples/sql_database_deletion_policy.tf.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# [START cloud_sql_database_create] | ||
resource "google_sql_database" "<%= ctx[:primary_resource_id] %>" { | ||
name = "<%= ctx[:vars]['database_name'] %>" | ||
instance = google_sql_database_instance.instance.name | ||
deletion_policy = "ABANDON" | ||
} | ||
# [END cloud_sql_database_create] | ||
|
||
# See versions at https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/sql_database_instance#database_version | ||
resource "google_sql_database_instance" "instance" { | ||
name = "<%= ctx[:vars]['database_instance_name'] %>" | ||
region = "us-central1" | ||
database_version = "POSTGRES_14" | ||
settings { | ||
tier = "db-g1-small" | ||
} | ||
|
||
deletion_protection = "<%= ctx[:vars]['deletion_protection'] %>" | ||
} |
5 changes: 5 additions & 0 deletions
5
mmv1/templates/terraform/pre_delete/sql_database_deletion_policy.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
if deletionPolicy := d.Get("deletion_policy"); deletionPolicy == "ABANDON" { | ||
// Allows for database to be abandoned without deletion to avoid deletion failing | ||
// for Postgres databases in some circumstances due to existing SQL users | ||
return nil | ||
} |