Skip to content

Commit

Permalink
Fix permadiffs in regional health_checks and backend_service (#4998
Browse files Browse the repository at this point in the history
…) (#10553)

Co-authored-by: upodroid <cy@borg.dev>
Signed-off-by: Modular Magician <magic-modules@google.com>

Co-authored-by: upodroid <cy@borg.dev>
  • Loading branch information
modular-magician and upodroid authored Nov 12, 2021
1 parent cbc3945 commit 6f82109
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .changelog/4998.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
compute: fixed a perma-diff on `google_compute_region_health_check` when `log_config.enable` is set to false
```
17 changes: 7 additions & 10 deletions google/resource_compute_region_health_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ can only be ASCII.`,
},
"log_config": {
Type: schema.TypeList,
Computed: true,
Optional: true,
Description: `Configure logging on this health check.`,
MaxItems: 1,
Expand Down Expand Up @@ -1470,21 +1471,17 @@ func flattenComputeRegionHealthCheckGrpcHealthCheckGrpcServiceName(v interface{}
}

func flattenComputeRegionHealthCheckLogConfig(v interface{}, d *schema.ResourceData, config *Config) interface{} {
transformed := make(map[string]interface{})
if v == nil {
return nil
// Disabled by default, but API will not return object if value is false
transformed["enable"] = false
return []interface{}{transformed}
}

original := v.(map[string]interface{})
if len(original) == 0 {
return nil
}
transformed := make(map[string]interface{})
transformed["enable"] =
flattenComputeRegionHealthCheckLogConfigEnable(original["enable"], d, config)
transformed["enable"] = original["enable"]
return []interface{}{transformed}
}
func flattenComputeRegionHealthCheckLogConfigEnable(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}

func flattenComputeRegionHealthCheckRegion(v interface{}, d *schema.ResourceData, config *Config) interface{} {
if v == nil {
Expand Down
41 changes: 41 additions & 0 deletions google/resource_compute_region_health_check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,47 @@ func TestAccComputeRegionHealthCheck_tcpAndSsl_shouldFail(t *testing.T) {
})
}

func TestAccComputeRegionHealthCheck_logConfigDisabled(t *testing.T) {
t.Parallel()

hckName := fmt.Sprintf("tf-test-%s", randString(t, 10))

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeHealthCheckDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeRegionHealthCheck_logConfigDisabled(hckName),
},
{
ResourceName: "google_compute_region_health_check.foobar",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccComputeRegionHealthCheck_logConfigDisabled(hckName string) string {
return fmt.Sprintf(`
resource "google_compute_region_health_check" "foobar" {
check_interval_sec = 3
description = "Resource created for Terraform acceptance testing"
healthy_threshold = 3
name = "%s"
timeout_sec = 2
unhealthy_threshold = 3
http2_health_check {
port = "443"
}
log_config {
enable = false
}
}
`, hckName)
}

func testAccComputeRegionHealthCheck_tcp(hckName string) string {
return fmt.Sprintf(`
resource "google_compute_region_health_check" "foobar" {
Expand Down

0 comments on commit 6f82109

Please sign in to comment.