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

SM Check: Fix panic when settings are nil #1710

Merged
merged 1 commit into from
Jul 24, 2024
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
5 changes: 4 additions & 1 deletion internal/resources/syntheticmonitoring/resource_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -1589,7 +1589,10 @@ func resourceCheckCustomizeDiff(ctx context.Context, diff *schema.ResourceDiff,
if len(settingsList) == 0 {
return fmt.Errorf("at least one check setting must be defined")
}
settings := settingsList[0].(map[string]interface{})
settings, ok := settingsList[0].(map[string]interface{})
if !ok {
return fmt.Errorf("at least one check setting must be defined")
}

count := 0
for k := range syntheticMonitoringCheckSettings.Schema {
Expand Down
30 changes: 30 additions & 0 deletions internal/resources/syntheticmonitoring/resource_check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ func TestAccResourceCheck_dns(t *testing.T) {
resource.TestCheckResourceAttr("grafana_synthetic_monitoring_check.dns", "settings.0.dns.0.validate_additional_rrs.0.fail_if_not_matches_regexp.0", ".+-good-stuff*"),
),
},
{
ImportState: true,
ImportStateVerify: true,
ResourceName: "grafana_synthetic_monitoring_check.dns",
},
},
})
}
Expand Down Expand Up @@ -137,6 +142,11 @@ func TestAccResourceCheck_http(t *testing.T) {
resource.TestCheckResourceAttr("grafana_synthetic_monitoring_check.http", "settings.0.http.0.fail_if_header_matches_regexp.0.allow_missing", "true"),
),
},
{
ImportState: true,
ImportStateVerify: true,
ResourceName: "grafana_synthetic_monitoring_check.http",
},
},
})
}
Expand Down Expand Up @@ -182,6 +192,11 @@ func TestAccResourceCheck_ping(t *testing.T) {
resource.TestCheckResourceAttr("grafana_synthetic_monitoring_check.ping", "settings.0.ping.0.dont_fragment", "true"),
),
},
{
ImportState: true,
ImportStateVerify: true,
ResourceName: "grafana_synthetic_monitoring_check.ping",
},
},
})
}
Expand Down Expand Up @@ -233,6 +248,11 @@ func TestAccResourceCheck_tcp(t *testing.T) {
resource.TestMatchResourceAttr("grafana_synthetic_monitoring_check.tcp", "settings.0.tcp.0.tls_config.0.ca_cert", regexp.MustCompile((`^-{5}BEGIN CERTIFICATE`))),
),
},
{
ImportState: true,
ImportStateVerify: true,
ResourceName: "grafana_synthetic_monitoring_check.tcp",
},
},
})
}
Expand Down Expand Up @@ -280,6 +300,11 @@ func TestAccResourceCheck_traceroute(t *testing.T) {
resource.TestCheckResourceAttr("grafana_synthetic_monitoring_check.traceroute", "settings.0.traceroute.0.ptr_lookup", "false"),
),
},
{
ImportState: true,
ImportStateVerify: true,
ResourceName: "grafana_synthetic_monitoring_check.traceroute",
},
},
})
}
Expand Down Expand Up @@ -365,6 +390,11 @@ func TestAccResourceCheck_multihttp(t *testing.T) {
resource.TestCheckResourceAttr("grafana_synthetic_monitoring_check.multihttp", "settings.0.multihttp.0.entries.1.assertions.4.expression", "$.slideshow.slides"),
),
},
{
ImportState: true,
ImportStateVerify: true,
ResourceName: "grafana_synthetic_monitoring_check.multihttp",
},
},
})
}
Expand Down
Loading