Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix permadiffs in regional health_checks and backend_service #10553

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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