From d8bd2a3dc7f4c8f6ccdde96554d3f817953140fc Mon Sep 17 00:00:00 2001 From: Modular Magician Date: Thu, 17 Nov 2022 23:01:24 +0000 Subject: [PATCH] suppress diff on website (#6827) Co-authored-by: Edward Sun Fixes https://github.com/hashicorp/terraform-provider-google/issues/12870 Signed-off-by: Modular Magician --- .changelog/6827.txt | 3 ++ google/resource_storage_bucket.go | 7 ++++ google/resource_storage_bucket_test.go | 44 ++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 .changelog/6827.txt diff --git a/.changelog/6827.txt b/.changelog/6827.txt new file mode 100644 index 00000000000..76273e854cf --- /dev/null +++ b/.changelog/6827.txt @@ -0,0 +1,3 @@ +```release-note:bug +storage: fixed permdiff when `website`, `website.main_page_suffix`, `website.not_found_page` are removed on `google_storage_bucket` +``` diff --git a/google/resource_storage_bucket.go b/google/resource_storage_bucket.go index c3a936222a3..ad25882213f 100644 --- a/google/resource_storage_bucket.go +++ b/google/resource_storage_bucket.go @@ -251,6 +251,7 @@ func resourceStorageBucket() *schema.Resource { Type: schema.TypeList, Optional: true, MaxItems: 1, + Computed: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "main_page_suffix": { @@ -258,12 +259,18 @@ func resourceStorageBucket() *schema.Resource { Optional: true, AtLeastOneOf: []string{"website.0.not_found_page", "website.0.main_page_suffix"}, Description: `Behaves as the bucket's directory index where missing objects are treated as potential directories.`, + DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool { + return old != "" && new == "" + }, }, "not_found_page": { Type: schema.TypeString, Optional: true, AtLeastOneOf: []string{"website.0.main_page_suffix", "website.0.not_found_page"}, Description: `The custom object to return when a requested resource is not found.`, + DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool { + return old != "" && new == "" + }, }, }, }, diff --git a/google/resource_storage_bucket_test.go b/google/resource_storage_bucket_test.go index f0ec417124b..95b097b2f6a 100644 --- a/google/resource_storage_bucket_test.go +++ b/google/resource_storage_bucket_test.go @@ -1016,6 +1016,15 @@ func TestAccStorageBucket_website(t *testing.T) { ImportStateVerify: true, ImportStateVerifyIgnore: []string{"force_destroy"}, }, + { + Config: testAccStorageBucket_websiteOneAttributeUpdate(bucketSuffix), + }, + { + ResourceName: "google_storage_bucket.website", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"force_destroy"}, + }, { Config: testAccStorageBucket_website(bucketSuffix), }, @@ -1025,6 +1034,15 @@ func TestAccStorageBucket_website(t *testing.T) { ImportStateVerify: true, ImportStateVerifyIgnore: []string{"force_destroy"}, }, + { + Config: testAccStorageBucket_websiteRemoved(bucketSuffix), + }, + { + ResourceName: "google_storage_bucket.website", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"force_destroy"}, + }, }, }) } @@ -1939,6 +1957,17 @@ resource "google_storage_bucket" "website" { `, bucketName) } +func testAccStorageBucket_websiteRemoved(bucketName string) string { + return fmt.Sprintf(` +resource "google_storage_bucket" "website" { + name = "%s.gcp.tfacc.hashicorptest.com" + location = "US" + storage_class = "STANDARD" + force_destroy = true +} +`, bucketName) +} + func testAccStorageBucket_websiteOneAttribute(bucketName string) string { return fmt.Sprintf(` resource "google_storage_bucket" "website" { @@ -1954,6 +1983,21 @@ resource "google_storage_bucket" "website" { `, bucketName) } +func testAccStorageBucket_websiteOneAttributeUpdate(bucketName string) string { + return fmt.Sprintf(` +resource "google_storage_bucket" "website" { + name = "%s.gcp.tfacc.hashicorptest.com" + location = "US" + storage_class = "STANDARD" + force_destroy = true + + website { + main_page_suffix = "default.html" + } +} +`, bucketName) +} + func testAccStorageBucket_forceDestroy(bucketName string) string { return fmt.Sprintf(` resource "google_storage_bucket" "bucket" {