Skip to content

Commit

Permalink
Change all fields for monitored resource to force recreation (#485)
Browse files Browse the repository at this point in the history
<!-- This change is generated by MagicModules. -->
/cc @chrisst
  • Loading branch information
modular-magician authored and chrisst committed Mar 14, 2019
1 parent 9ec09a4 commit df964e7
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 25 deletions.
25 changes: 5 additions & 20 deletions google-beta/resource_monitoring_uptime_check_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
},
Expand All @@ -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{
Expand All @@ -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),
},
},
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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, ",")})
Expand Down
53 changes: 48 additions & 5 deletions google-beta/resource_monitoring_uptime_check_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ 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) },
Providers: testAccProviders,
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",
Expand All @@ -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",
Expand All @@ -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"
Expand All @@ -58,14 +101,14 @@ resource "google_monitoring_uptime_check_config" "http" {
type = "uptime_url"
labels = {
project_id = "%s"
host = "192.168.1.1"
host = "%s"
}
}
content_matchers {
content = "example"
}
}
`, acctest.RandString(4), path, project, pwd,
`, acctest.RandString(4), path, project, pwd, host,
)
}

0 comments on commit df964e7

Please sign in to comment.