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.
Support deleting Firestore databases
Due to backwards compatibility concerns, the default behavior remains to abandon the database upon destroy rather than to actually delete it. To actually delete the database, you must set deletion_policy to DELETE, and apply if necessary, before running `terraform destroy`. This also cleans up some related deletion-related docs and bugs: * Updates the delete protection docs * Either delete protection or deletion policy being set prevents destroy Fixes hashicorp/terraform-provider-google#16488 Fixes hashicorp/terraform-provider-google#16404 Fixes hashicorp/terraform-provider-google#16325
- Loading branch information
Showing
3 changed files
with
46 additions
and
2 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
10 changes: 10 additions & 0 deletions
10
mmv1/templates/terraform/examples/firestore_database_with_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,10 @@ | ||
resource "google_firestore_database" "<%= ctx[:primary_resource_id] %>" { | ||
project = "<%= ctx[:test_env_vars]['project_id'] %>" | ||
name = "<%= ctx[:vars]['name']%>" | ||
location_id = "nam5" | ||
type = "FIRESTORE_NATIVE" | ||
|
||
# Required to allow deleting the database with Terraform | ||
# Also ensure that delete_protection_state is set to DELETE_PROTECTION_DISABLED (the default) | ||
deletion_policy = "DELETE" | ||
} |
7 changes: 7 additions & 0 deletions
7
mmv1/templates/terraform/pre_delete/firestore_database.go.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,7 @@ | ||
if deletionPolicy := d.Get("deletion_policy"); deletionPolicy == "ABANDON" { | ||
log.Printf("[WARN] Firestore database %q deletion_policy is set to 'ABANDON', skipping deletion", d.Get("name").(string)) | ||
return nil | ||
} | ||
if d.Get("deletion_protection").(bool) { | ||
return fmt.Errorf("Cannot delete Firestore database %s: Delete Protection is enabled. Set delete_protection_state to DELETE_PROTECTION_DISABLED for this resource and run \"terraform apply\" before attempting to delete it.", d.Get("name").(string)) | ||
} |