From 6f821098d206a7229f6d9f39ef9ddfc06468e7f8 Mon Sep 17 00:00:00 2001 From: The Magician Date: Fri, 12 Nov 2021 13:02:19 -0800 Subject: [PATCH] Fix permadiffs in regional `health_checks` and `backend_service` (#4998) (#10553) Co-authored-by: upodroid Signed-off-by: Modular Magician Co-authored-by: upodroid --- .changelog/4998.txt | 3 ++ .../resource_compute_region_health_check.go | 17 ++++---- ...source_compute_region_health_check_test.go | 41 +++++++++++++++++++ 3 files changed, 51 insertions(+), 10 deletions(-) create mode 100644 .changelog/4998.txt diff --git a/.changelog/4998.txt b/.changelog/4998.txt new file mode 100644 index 00000000000..d63902d2783 --- /dev/null +++ b/.changelog/4998.txt @@ -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 +``` diff --git a/google/resource_compute_region_health_check.go b/google/resource_compute_region_health_check.go index b5ff82a3bc7..d499468115b 100644 --- a/google/resource_compute_region_health_check.go +++ b/google/resource_compute_region_health_check.go @@ -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, @@ -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 { diff --git a/google/resource_compute_region_health_check_test.go b/google/resource_compute_region_health_check_test.go index 86676071874..6e2eed9e3f0 100644 --- a/google/resource_compute_region_health_check_test.go +++ b/google/resource_compute_region_health_check_test.go @@ -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" {