Skip to content

Commit

Permalink
suppress diff on website (GoogleCloudPlatform#6827)
Browse files Browse the repository at this point in the history
Co-authored-by: Edward Sun <sunedward@google.com>
Fixes hashicorp/terraform-provider-google#12870
  • Loading branch information
edwardmedia authored and kimihrr committed Dec 6, 2022
1 parent 782cb1f commit 6104f05
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -252,19 +252,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
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,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 @@ -1026,6 +1035,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 @@ -1940,6 +1958,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 @@ -1955,6 +1984,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 6104f05

Please sign in to comment.