Skip to content

Commit 44c69af

Browse files
boarikiyabchen
authored andcommitted
Adds support for Filestore instance new feature: deletion protection. (GoogleCloudPlatform#11602)
1 parent 77dc4d8 commit 44c69af

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed

mmv1/products/filestore/Instance.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -265,3 +265,11 @@ properties:
265265
immutable: true
266266
description: |
267267
KMS key name used for data encryption.
268+
- !ruby/object:Api::Type::Boolean
269+
name: 'deletionProtectionEnabled'
270+
description: |
271+
Indicates whether the instance is protected against deletion.
272+
- !ruby/object:Api::Type::String
273+
name: 'deletionProtectionReason'
274+
description: |
275+
The reason for enabling deletion protection.

mmv1/third_party/terraform/services/filestore/resource_filestore_instance_test.go

+95
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,98 @@ resource "google_filestore_instance" "instance" {
190190
}
191191
`, name)
192192
}
193+
194+
func TestAccFilestoreInstance_deletionProtection_update(t *testing.T) {
195+
t.Parallel()
196+
197+
name := fmt.Sprintf("tf-test-%d", acctest.RandInt(t))
198+
location := "us-central1-a"
199+
tier := "ZONAL"
200+
201+
deletionProtection := true
202+
203+
acctest.VcrTest(t, resource.TestCase{
204+
PreCheck: func() { acctest.AccTestPreCheck(t) },
205+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
206+
CheckDestroy: testAccCheckFilestoreInstanceDestroyProducer(t),
207+
Steps: []resource.TestStep{
208+
{
209+
Config: testAccFilestoreInstance_deletionProtection_create(name, location, tier),
210+
},
211+
{
212+
ResourceName: "google_filestore_instance.instance",
213+
ImportState: true,
214+
ImportStateVerify: true,
215+
ImportStateVerifyIgnore: []string{"zone"},
216+
},
217+
{
218+
Config: testAccFilestoreInstance_deletionProtection_update(name, location, tier, deletionProtection),
219+
},
220+
{
221+
ResourceName: "google_filestore_instance.instance",
222+
ImportState: true,
223+
ImportStateVerify: true,
224+
ImportStateVerifyIgnore: []string{"zone"},
225+
},
226+
{
227+
Config: testAccFilestoreInstance_deletionProtection_update(name, location, tier, !deletionProtection),
228+
},
229+
{
230+
ResourceName: "google_filestore_instance.instance",
231+
ImportState: true,
232+
ImportStateVerify: true,
233+
ImportStateVerifyIgnore: []string{"zone"},
234+
},
235+
},
236+
})
237+
}
238+
239+
func testAccFilestoreInstance_deletionProtection_create(name, location, tier string) string {
240+
return fmt.Sprintf(`
241+
resource "google_filestore_instance" "instance" {
242+
name = "%s"
243+
zone = "%s"
244+
tier = "%s"
245+
description = "An instance created during testing."
246+
247+
file_shares {
248+
capacity_gb = 1024
249+
name = "share"
250+
}
251+
252+
networks {
253+
network = "default"
254+
modes = ["MODE_IPV4"]
255+
}
256+
}
257+
`, name, location, tier)
258+
}
259+
260+
func testAccFilestoreInstance_deletionProtection_update(name, location, tier string, deletionProtection bool) string {
261+
deletionProtectionReason := ""
262+
if deletionProtection {
263+
deletionProtectionReason = "A reason for deletion protection"
264+
}
265+
266+
return fmt.Sprintf(`
267+
resource "google_filestore_instance" "instance" {
268+
name = "%s"
269+
zone = "%s"
270+
tier = "%s"
271+
description = "An instance created during testing."
272+
273+
file_shares {
274+
capacity_gb = 1024
275+
name = "share"
276+
}
277+
278+
networks {
279+
network = "default"
280+
modes = ["MODE_IPV4"]
281+
}
282+
283+
deletion_protection_enabled = %t
284+
deletion_protection_reason = "%s"
285+
}
286+
`, name, location, tier, deletionProtection, deletionProtectionReason)
287+
}

0 commit comments

Comments
 (0)