Skip to content

Commit

Permalink
suppress diff on website (#6827) (#13069)
Browse files Browse the repository at this point in the history
Co-authored-by: Edward Sun <sunedward@google.com>
Fixes #12870

Signed-off-by: Modular Magician <magic-modules@google.com>

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician committed Nov 17, 2022
1 parent 1afe086 commit c2514e8
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .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`
```
7 changes: 7 additions & 0 deletions google/resource_storage_bucket.go
Expand Up @@ -251,19 +251,26 @@ func resourceStorageBucket() *schema.Resource {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"main_page_suffix": {
Type: schema.TypeString,
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 == ""
},
},
},
},
Expand Down
44 changes: 44 additions & 0 deletions google/resource_storage_bucket_test.go
Expand Up @@ -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),
},
Expand All @@ -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"},
},
},
})
}
Expand Down Expand Up @@ -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" {
Expand All @@ -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" {
Expand Down

0 comments on commit c2514e8

Please sign in to comment.