Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Firestore deletion protection #8906

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions mmv1/products/firestore/Database.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ examples:
- etag
vars:
project_id: 'my-project'
- !ruby/object:Provider::Terraform::Examples
name: 'firestore_database_with_delete_protection'
primary_resource_id: 'database'
skip_test: true
properties:
- !ruby/object:Api::Type::String
name: name
Expand Down Expand Up @@ -167,6 +171,15 @@ properties:
that is returned from the Cloud Datastore APIs in Google App Engine first generation runtimes.
This value may be empty in which case the appid to use for URL-encoded keys is the project_id (eg: foo instead of v~foo).
output: true
- !ruby/object:Api::Type::Enum
name: deleteProtectionState
description: |
State of delete protection for the database.
values:
- :DELETE_PROTECTION_STATE_UNSPECIFIED
- :DELETE_PROTECTION_ENABLED
- :DELETE_PROTECTION_DISABLED
default_from_api: true
- !ruby/object:Api::Type::Fingerprint
name: etag
description: |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
resource "google_firestore_database" "<%= ctx[:primary_resource_id] %>" {
project = google_project.project.project_id
name = "my-database"
location_id = "nam5"
type = "FIRESTORE_NATIVE"

# Prevents accidental deletion of the database.
# To delete the database, first set this field to `DELETE_PROTECTION_DISABLED`, apply the changes.
# Then delete the database resource and apply the changes again.
delete_protection_state = "DELETE_PROTECTION_ENABLED"

depends_on = [google_project_service.firestore]
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,42 @@ func TestAccFirestoreDatabase_updatePitrEnablement(t *testing.T) {
})
}

func TestAccFirestoreDatabase_updateDeleteProtectionState(t *testing.T) {
t.Parallel()

orgId := envvar.GetTestOrgFromEnv(t)
billingAccount := envvar.GetTestBillingAccountFromEnv(t)
randomSuffix := acctest.RandString(t, 10)

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
ExternalProviders: map[string]resource.ExternalProvider{
"time": {},
},
Steps: []resource.TestStep{
{
Config: testAccFirestoreDatabase_deleteProtectionState(orgId, billingAccount, randomSuffix, "DELETE_PROTECTION_ENABLED"),
},
{
ResourceName: "google_firestore_database.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"etag", "project"},
},
{
Config: testAccFirestoreDatabase_deleteProtectionState(orgId, billingAccount, randomSuffix, "DELETE_PROTECTION_DISABLED"),
},
{
ResourceName: "google_firestore_database.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"etag", "project"},
},
},
})
}

func testAccFirestoreDatabase_basicDependencies(orgId, billingAccount string, randomSuffix string) string {
return fmt.Sprintf(`
resource "google_project" "default" {
Expand Down Expand Up @@ -138,3 +174,19 @@ resource "google_firestore_database" "default" {
}
`, pointInTimeRecoveryEnablement)
}

func testAccFirestoreDatabase_deleteProtectionState(orgId, billingAccount string, randomSuffix string, deleteProtectionState string) string {
return testAccFirestoreDatabase_basicDependencies(orgId, billingAccount, randomSuffix) + fmt.Sprintf(`

resource "google_firestore_database" "default" {
name = "(default)"
type = "DATASTORE_MODE"
location_id = "nam5"
delete_protection_state = "%s"

project = google_project.default.project_id

depends_on = [google_project_service.firestore]
}
`, deleteProtectionState)
}