From 549203976f472bb7668482a6ef2a4a6218ba2121 Mon Sep 17 00:00:00 2001 From: The Magician Date: Thu, 14 Mar 2019 10:06:57 -0700 Subject: [PATCH] Change all fields for monitored resource to force recreation (#3160) /cc @chrisst --- ...resource_monitoring_uptime_check_config.go | 25 ++------- ...rce_monitoring_uptime_check_config_test.go | 53 +++++++++++++++++-- 2 files changed, 53 insertions(+), 25 deletions(-) diff --git a/google/resource_monitoring_uptime_check_config.go b/google/resource_monitoring_uptime_check_config.go index c563e124..58d7126e 100644 --- a/google/resource_monitoring_uptime_check_config.go +++ b/google/resource_monitoring_uptime_check_config.go @@ -150,17 +150,20 @@ func resourceMonitoringUptimeCheckConfig() *schema.Resource { "monitored_resource": { Type: schema.TypeList, Optional: true, + ForceNew: true, MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "labels": { Type: schema.TypeMap, Required: true, + ForceNew: true, Elem: &schema.Schema{Type: schema.TypeString}, }, "type": { Type: schema.TypeString, Required: true, + ForceNew: true, }, }, }, @@ -175,6 +178,7 @@ func resourceMonitoringUptimeCheckConfig() *schema.Resource { "resource_group": { Type: schema.TypeList, Optional: true, + ForceNew: true, MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ @@ -187,6 +191,7 @@ func resourceMonitoringUptimeCheckConfig() *schema.Resource { "resource_type": { Type: schema.TypeString, Optional: true, + ForceNew: true, ValidateFunc: validation.StringInSlice([]string{"RESOURCE_TYPE_UNSPECIFIED", "INSTANCE", "AWS_ELB_LOAD_BALANCER", ""}, false), }, }, @@ -450,18 +455,6 @@ func resourceMonitoringUptimeCheckConfigUpdate(d *schema.ResourceData, meta inte } else if v, ok := d.GetOkExists("tcp_check"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, tcpCheckProp)) { obj["tcpCheck"] = tcpCheckProp } - resourceGroupProp, err := expandMonitoringUptimeCheckConfigResourceGroup(d.Get("resource_group"), d, config) - if err != nil { - return err - } else if v, ok := d.GetOkExists("resource_group"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, resourceGroupProp)) { - obj["resourceGroup"] = resourceGroupProp - } - monitoredResourceProp, err := expandMonitoringUptimeCheckConfigMonitoredResource(d.Get("monitored_resource"), d, config) - if err != nil { - return err - } else if v, ok := d.GetOkExists("monitored_resource"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, monitoredResourceProp)) { - obj["monitoredResource"] = monitoredResourceProp - } url, err := replaceVars(d, config, "https://monitoring.googleapis.com/v3/{{name}}") if err != nil { @@ -502,14 +495,6 @@ func resourceMonitoringUptimeCheckConfigUpdate(d *schema.ResourceData, meta inte if d.HasChange("tcp_check") { updateMask = append(updateMask, "tcpCheck") } - - if d.HasChange("resource_group") { - updateMask = append(updateMask, "resourceGroup") - } - - if d.HasChange("monitored_resource") { - updateMask = append(updateMask, "monitoredResource") - } // updateMask is a URL parameter but not present in the schema, so replaceVars // won't set it url, err = addQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")}) diff --git a/google/resource_monitoring_uptime_check_config_test.go b/google/resource_monitoring_uptime_check_config_test.go index 9521a4cb..498de8fe 100644 --- a/google/resource_monitoring_uptime_check_config_test.go +++ b/google/resource_monitoring_uptime_check_config_test.go @@ -11,6 +11,7 @@ import ( func TestAccMonitoringUptimeCheckConfig_update(t *testing.T) { t.Parallel() project := getTestProjectFromEnv() + host := "192.168.1.1" resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -18,7 +19,7 @@ func TestAccMonitoringUptimeCheckConfig_update(t *testing.T) { CheckDestroy: testAccCheckMonitoringUptimeCheckConfigDestroy, Steps: []resource.TestStep{ { - Config: testAccMonitoringUptimeCheckConfig_update("mypath", "password1", project), + Config: testAccMonitoringUptimeCheckConfig_update("mypath", "password1", project, host), }, { ResourceName: "google_monitoring_uptime_check_config.http", @@ -27,7 +28,7 @@ func TestAccMonitoringUptimeCheckConfig_update(t *testing.T) { ImportStateVerifyIgnore: []string{"http_check.0.auth_info.0.password"}, }, { - Config: testAccMonitoringUptimeCheckConfig_update("", "password2", project), + Config: testAccMonitoringUptimeCheckConfig_update("", "password2", project, host), }, { ResourceName: "google_monitoring_uptime_check_config.http", @@ -39,7 +40,49 @@ func TestAccMonitoringUptimeCheckConfig_update(t *testing.T) { }) } -func testAccMonitoringUptimeCheckConfig_update(path, project, pwd string) string { +// The second update should force a recreation of the uptime check because 'monitored_resource' isn't +// updatable in place +func TestAccMonitoringUptimeCheckConfig_changeNonUpdatableFields(t *testing.T) { + t.Parallel() + project := getTestProjectFromEnv() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckMonitoringUptimeCheckConfigDestroy, + Steps: []resource.TestStep{ + { + Config: testAccMonitoringUptimeCheckConfig_update("mypath", "password1", project, "192.168.1.1"), + }, + { + ResourceName: "google_monitoring_uptime_check_config.http", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"http_check.0.auth_info.0.password"}, + }, + { + Config: testAccMonitoringUptimeCheckConfig_update("mypath", "password1", project, "192.168.1.2"), + }, + { + ResourceName: "google_monitoring_uptime_check_config.http", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"http_check.0.auth_info.0.password"}, + }, + { + Config: testAccMonitoringUptimeCheckConfig_update("mypath", "password2", project, "192.168.1.2"), + }, + { + ResourceName: "google_monitoring_uptime_check_config.http", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"http_check.0.auth_info.0.password"}, + }, + }, + }) +} + +func testAccMonitoringUptimeCheckConfig_update(path, project, pwd, host string) string { return fmt.Sprintf(` resource "google_monitoring_uptime_check_config" "http" { display_name = "http-uptime-check-%s" @@ -58,7 +101,7 @@ resource "google_monitoring_uptime_check_config" "http" { type = "uptime_url" labels = { project_id = "%s" - host = "192.168.1.1" + host = "%s" } } @@ -66,6 +109,6 @@ resource "google_monitoring_uptime_check_config" "http" { content = "example" } } -`, acctest.RandString(4), path, project, pwd, +`, acctest.RandString(4), path, project, pwd, host, ) }