Skip to content

Adds support for Filestore instance new feature: deletion protection. #11602

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

Merged
merged 3 commits into from
Sep 11, 2024
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
8 changes: 8 additions & 0 deletions mmv1/products/filestore/Instance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,11 @@ properties:
immutable: true
description: |
KMS key name used for data encryption.
- !ruby/object:Api::Type::Boolean
name: 'deletionProtectionEnabled'
description: |
Indicates whether the instance is protected against deletion.
- !ruby/object:Api::Type::String
name: 'deletionProtectionReason'
description: |
The reason for enabling deletion protection.
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,98 @@ resource "google_filestore_instance" "instance" {
}
`, name)
}

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

name := fmt.Sprintf("tf-test-%d", acctest.RandInt(t))
location := "us-central1-a"
tier := "ZONAL"

deletionProtection := true

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckFilestoreInstanceDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccFilestoreInstance_deletionProtection_create(name, location, tier),
},
{
ResourceName: "google_filestore_instance.instance",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"zone"},
},
{
Config: testAccFilestoreInstance_deletionProtection_update(name, location, tier, deletionProtection),
},
{
ResourceName: "google_filestore_instance.instance",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"zone"},
},
{
Config: testAccFilestoreInstance_deletionProtection_update(name, location, tier, !deletionProtection),
},
{
ResourceName: "google_filestore_instance.instance",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"zone"},
},
},
})
}

func testAccFilestoreInstance_deletionProtection_create(name, location, tier string) string {
return fmt.Sprintf(`
resource "google_filestore_instance" "instance" {
name = "%s"
zone = "%s"
tier = "%s"
description = "An instance created during testing."

file_shares {
capacity_gb = 1024
name = "share"
}

networks {
network = "default"
modes = ["MODE_IPV4"]
}
}
`, name, location, tier)
}

func testAccFilestoreInstance_deletionProtection_update(name, location, tier string, deletionProtection bool) string {
deletionProtectionReason := ""
if deletionProtection {
deletionProtectionReason = "A reason for deletion protection"
}

return fmt.Sprintf(`
resource "google_filestore_instance" "instance" {
name = "%s"
zone = "%s"
tier = "%s"
description = "An instance created during testing."

file_shares {
capacity_gb = 1024
name = "share"
}

networks {
network = "default"
modes = ["MODE_IPV4"]
}

deletion_protection_enabled = %t
deletion_protection_reason = "%s"
}
`, name, location, tier, deletionProtection, deletionProtectionReason)
}