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 (GoogleCloudPlatform#9450)
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 * delete_protection_state being enabled with deletion_policy = DELETE fails the destroy Fixes hashicorp/terraform-provider-google#16488 Fixes hashicorp/terraform-provider-google#16404 Fixes hashicorp/terraform-provider-google#16325
- Loading branch information
Showing
7 changed files
with
62 additions
and
78 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
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
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
11 changes: 0 additions & 11 deletions
11
mmv1/templates/terraform/examples/firestore_database_with_delete_protection.tf.erb
This file was deleted.
Oops, something went wrong.
31 changes: 6 additions & 25 deletions
31
mmv1/templates/terraform/examples/firestore_default_database.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 |
---|---|---|
@@ -1,27 +1,8 @@ | ||
resource "google_project" "project" { | ||
project_id = "<%= ctx[:vars]['project_id'] %>" | ||
name = "<%= ctx[:vars]['project_id'] %>" | ||
org_id = "<%= ctx[:test_env_vars]['org_id'] %>" | ||
} | ||
|
||
resource "time_sleep" "wait_60_seconds" { | ||
depends_on = [google_project.project] | ||
|
||
create_duration = "60s" | ||
} | ||
|
||
resource "google_project_service" "firestore" { | ||
project = google_project.project.project_id | ||
service = "firestore.googleapis.com" | ||
# Needed for CI tests for permissions to propagate, should not be needed for actual usage | ||
depends_on = [time_sleep.wait_60_seconds] | ||
} | ||
|
||
resource "google_firestore_database" "<%= ctx[:primary_resource_id] %>" { | ||
project = google_project.project.project_id | ||
name = "(default)" | ||
location_id = "nam5" | ||
type = "FIRESTORE_NATIVE" | ||
|
||
depends_on = [google_project_service.firestore] | ||
project = "<%= ctx[:test_env_vars]['project_id'] %>" | ||
name = "(default)" | ||
location_id = "nam5" | ||
type = "FIRESTORE_NATIVE" | ||
delete_protection_state = "<%= ctx[:vars]['delete_protection_state'] %>" | ||
deletion_policy = "DELETE" | ||
} |
32 changes: 6 additions & 26 deletions
32
mmv1/templates/terraform/examples/firestore_default_database_in_datastore_mode.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 |
---|---|---|
@@ -1,28 +1,8 @@ | ||
resource "google_project" "project" { | ||
project_id = "tf-test%{random_suffix}" | ||
name = "tf-test%{random_suffix}" | ||
org_id = "<%= ctx[:test_env_vars]['org_id'] %>" | ||
} | ||
|
||
resource "time_sleep" "wait_60_seconds" { | ||
depends_on = [google_project.project] | ||
create_duration = "60s" | ||
} | ||
|
||
resource "google_project_service" "firestore" { | ||
project = google_project.project.project_id | ||
service = "firestore.googleapis.com" | ||
# Needed for CI tests for permissions to propagate, should not be needed for actual usage | ||
depends_on = [time_sleep.wait_60_seconds] | ||
} | ||
|
||
resource "google_firestore_database" "<%= ctx[:primary_resource_id] %>" { | ||
project = google_project.project.project_id | ||
|
||
name = "(default)" | ||
|
||
location_id = "nam5" | ||
type = "DATASTORE_MODE" | ||
|
||
depends_on = [google_project_service.firestore] | ||
project = "<%= ctx[:test_env_vars]['project_id'] %>" | ||
name = "(default)" | ||
location_id = "nam5" | ||
type = "DATASTORE_MODE" | ||
delete_protection_state = "<%= ctx[:vars]['delete_protection_state'] %>" | ||
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 != "DELETE" { | ||
log.Printf("[WARN] Firestore database %q deletion_policy is not set to 'DELETE', skipping deletion", d.Get("name").(string)) | ||
return nil | ||
} | ||
if deleteProtection := d.Get("delete_protection_state"); deleteProtection == "DELETE_PROTECTION_ENABLED" { | ||
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)) | ||
} |