Skip to content

Commit

Permalink
Prevent permadiff on monitoring_uptime_check_config (#10694)
Browse files Browse the repository at this point in the history
  • Loading branch information
VenelinMartinov committed May 16, 2024
1 parent 3b13231 commit 19dd78e
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
1 change: 1 addition & 0 deletions mmv1/products/monitoring/UptimeCheckConfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ properties:
name: 'labels'
immutable: true
required: true
diff_suppress_func: resourceMonitoringUptimeCheckConfigMonitoredResourceLabelsDiffSuppress
description:
Values for all of the labels listed in the associated monitored
resource descriptor. For example, Compute Engine VM instances use the
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
func resourceMonitoringUptimeCheckConfigHttpCheckPathDiffSuppress(k, old, new string, d *schema.ResourceData) bool {
return old == "/"+new
}

func resourceMonitoringUptimeCheckConfigMonitoredResourceLabelsDiffSuppress(k, old, new string, d *schema.ResourceData) bool {
// GCP adds the project_id to the labels if unset.
// We want to suppress the diff if not set in the config.
if strings.HasSuffix(k, "project_id") && new == "" && old != "" {
return true
}
return false
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,34 @@ func TestAccMonitoringUptimeCheckConfig_update(t *testing.T) {
})
}

func TestAccMonitoringUptimeCheckConfig_noProjectId(t *testing.T) {
t.Parallel()
host := "192.168.1.1"
suffix := acctest.RandString(t, 4)

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckMonitoringUptimeCheckConfigDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccMonitoringUptimeCheckConfig_noProjectId(suffix, host),
},
{
ResourceName: "google_monitoring_uptime_check_config.http",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"http_check.0.auth_info.0.password"},
},
{
Config: testAccMonitoringUptimeCheckConfig_noProjectId(suffix, host),
PlanOnly: true,
ResourceName: "google_monitoring_uptime_check_config.http",
},
},
})
}

// 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) {
Expand Down Expand Up @@ -180,3 +208,36 @@ resource "google_monitoring_uptime_check_config" "http" {
`, suffix, project, host, content, json_path, json_path_matcher,
)
}

func testAccMonitoringUptimeCheckConfig_noProjectId(suffix, host string) string {
return fmt.Sprintf(`
resource "google_monitoring_uptime_check_config" "http" {
display_name = "http-uptime-check-%s"
timeout = "60s"
period = "60s"
http_check {
path = "/mypath"
port = "8010"
request_method = "GET"
auth_info {
username = "name"
password = "mypassword"
}
}
monitored_resource {
type = "uptime_url"
labels = {
host = "%s"
}
}
content_matchers {
content = "example"
matcher = "CONTAINS_STRING"
}
}
`, suffix, host,
)
}

0 comments on commit 19dd78e

Please sign in to comment.