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.
- Loading branch information
Showing
4 changed files
with
104 additions
and
5 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
11 changes: 11 additions & 0 deletions
11
mmv1/templates/terraform/custom_update/storage_managed_folder.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,11 @@ | ||
_ = config | ||
|
||
// we can only get here if force_destroy was updated | ||
if d.Get("force_destroy") != nil { | ||
if err := d.Set("force_destroy", d.Get("force_destroy")); err != nil { | ||
return fmt.Errorf("Error updating force_destroy: %s", err) | ||
} | ||
} | ||
|
||
// all other fields are immutable, don't do anything else | ||
return nil |
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
73 changes: 73 additions & 0 deletions
73
mmv1/third_party/terraform/services/storage/resource_storage_managed_folder_test.go
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,73 @@ | ||
package storage_test | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
"github.com/hashicorp/terraform-provider-google/google/acctest" | ||
) | ||
|
||
func TestAccStorageManagedFolder_storageManagedFolderUpdate(t *testing.T) { | ||
t.Parallel() | ||
bucketName := fmt.Sprintf("tf-test-managed-folder-%s", acctest.RandString(t, 10)) | ||
|
||
acctest.VcrTest(t, resource.TestCase{ | ||
PreCheck: func() { acctest.AccTestPreCheck(t) }, | ||
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccStorageManagedFolder_bucket(bucketName) + testAccStorageManagedFolder_managedFolder(false), | ||
}, | ||
{ | ||
ResourceName: "google_storage_managed_folder.folder", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
ImportStateVerifyIgnore: []string{"bucket", "force_destroy"}, | ||
}, | ||
{ | ||
Config: testAccStorageManagedFolder_bucket(bucketName), | ||
ExpectError: regexp.MustCompile(`Error 409: The managed folder you tried to delete is not empty.`), | ||
}, | ||
{ | ||
Config: testAccStorageManagedFolder_bucket(bucketName) + testAccStorageManagedFolder_managedFolder(true), | ||
}, | ||
{ | ||
ResourceName: "google_storage_managed_folder.folder", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
ImportStateVerifyIgnore: []string{"bucket", "force_destroy"}, | ||
}, | ||
{ | ||
Config: testAccStorageManagedFolder_bucket(bucketName), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccStorageManagedFolder_bucket(bucketName string) string { | ||
return fmt.Sprintf(` | ||
resource "google_storage_bucket" "bucket" { | ||
name = "%s" | ||
location = "EU" | ||
uniform_bucket_level_access = true | ||
} | ||
resource "google_storage_bucket_object" "object" { | ||
name = "managed/folder/name/file.txt" | ||
content = "This file will affect the folder being deleted if allowNonEmpty=false" | ||
bucket = google_storage_bucket.bucket.name | ||
} | ||
`, bucketName) | ||
} | ||
|
||
func testAccStorageManagedFolder_managedFolder(forceDestroy bool) string { | ||
return fmt.Sprintf(` | ||
resource "google_storage_managed_folder" "folder" { | ||
bucket = google_storage_bucket.bucket.name | ||
name = "managed/folder/name/" | ||
force_destroy = %t | ||
} | ||
`, forceDestroy) | ||
} |