diff --git a/.changelog/9794.txt b/.changelog/9794.txt new file mode 100644 index 00000000000..6fc7726162f --- /dev/null +++ b/.changelog/9794.txt @@ -0,0 +1,3 @@ +```release-note:bug +filestore: make source_backup field configurable +``` diff --git a/google/services/filestore/resource_filestore_instance.go b/google/services/filestore/resource_filestore_instance.go index 9b73332badb..057e0da7fef 100644 --- a/google/services/filestore/resource_filestore_instance.go +++ b/google/services/filestore/resource_filestore_instance.go @@ -138,7 +138,8 @@ for not allowing root access. The default is NO_ROOT_SQUASH. Default value: "NO_ }, "source_backup": { Type: schema.TypeString, - Computed: true, + Optional: true, + ForceNew: true, Description: `The resource name of the backup, in the format projects/{projectId}/locations/{locationId}/backups/{backupId}, that this file share has been restored from.`, diff --git a/google/services/filestore/resource_filestore_restore_test.go b/google/services/filestore/resource_filestore_restore_test.go new file mode 100644 index 00000000000..1131c05ed9a --- /dev/null +++ b/google/services/filestore/resource_filestore_restore_test.go @@ -0,0 +1,87 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 +package filestore_test + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-provider-google/google/acctest" +) + +func TestAccFilestoreInstance_restore(t *testing.T) { + t.Parallel() + + srcInstancetName := fmt.Sprintf("tf-fs-inst-source-%d", acctest.RandInt(t)) + restoreInstanceName := fmt.Sprintf("tf-fs-inst-restored-%d", acctest.RandInt(t)) + backupName := fmt.Sprintf("tf-fs-bkup-%d", acctest.RandInt(t)) + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + CheckDestroy: testAccCheckFilestoreInstanceDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccFilestoreInstanceRestore_restore(srcInstancetName, restoreInstanceName, backupName), + }, + { + ResourceName: "google_filestore_instance.instance_source", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"location"}, + }, + }, + }) +} + +func testAccFilestoreInstanceRestore_restore(srcInstancetName, restoreInstanceName, backupName string) string { + return fmt.Sprintf(` + resource "google_filestore_instance" "instance_source" { + name = "%s" + location = "us-central1-b" + tier = "BASIC_HDD" + description = "An instance created during testing." + + file_shares { + capacity_gb = 1024 + name = "volume1" + } + + networks { + network = "default" + modes = ["MODE_IPV4"] + connect_mode = "DIRECT_PEERING" + } + } + + resource "google_filestore_instance" "instance_restored" { + name = "%s" + location = "us-central1-b" + tier = "BASIC_HDD" + description = "An instance created during testing." + + file_shares { + capacity_gb = 1024 + name = "volume1" + source_backup = google_filestore_backup.backup.id + } + + networks { + network = "default" + modes = ["MODE_IPV4"] + connect_mode = "DIRECT_PEERING" + } + } + + resource "google_filestore_backup" "backup" { + name = "%s" + location = "us-central1" + source_instance = google_filestore_instance.instance_source.id + source_file_share = "volume1" + + description = "This is a filestore backup for the test instance" + } + + `, srcInstancetName, restoreInstanceName, backupName) +} diff --git a/website/docs/r/filestore_instance.html.markdown b/website/docs/r/filestore_instance.html.markdown index 7353d8d43ee..27c3efb032c 100644 --- a/website/docs/r/filestore_instance.html.markdown +++ b/website/docs/r/filestore_instance.html.markdown @@ -167,7 +167,7 @@ The following arguments are supported: for the standard tier, or 2560 GiB for the premium tier. * `source_backup` - - (Output) + (Optional) The resource name of the backup, in the format projects/{projectId}/locations/{locationId}/backups/{backupId}, that this file share has been restored from.