|
1 | 1 | package grafana |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "context" |
4 | 5 | "regexp" |
| 6 | + "strconv" |
5 | 7 | "testing" |
6 | 8 |
|
7 | 9 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" |
| 10 | + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" |
8 | 11 | ) |
9 | 12 |
|
10 | 13 | func TestAccResourceSyntheticMonitoringCheck_dns(t *testing.T) { |
@@ -235,6 +238,40 @@ func TestAccResourceSyntheticMonitoringCheck_traceroute(t *testing.T) { |
235 | 238 | }) |
236 | 239 | } |
237 | 240 |
|
| 241 | +// Test that a check is recreated if deleted outside the Terraform process |
| 242 | +func TestAccResourceSyntheticMonitoringCheck_recreate(t *testing.T) { |
| 243 | + CheckCloudInstanceTestsEnabled(t) |
| 244 | + |
| 245 | + resource.Test(t, resource.TestCase{ |
| 246 | + ProviderFactories: testAccProviderFactories, |
| 247 | + Steps: []resource.TestStep{ |
| 248 | + { |
| 249 | + Config: testAccExample(t, "resources/grafana_synthetic_monitoring_check/http_basic.tf"), |
| 250 | + Check: func(s *terraform.State) error { |
| 251 | + rs := s.RootModule().Resources["grafana_synthetic_monitoring_check.http"] |
| 252 | + id, _ := strconv.ParseInt(rs.Primary.ID, 10, 64) |
| 253 | + return testAccProvider.Meta().(*client).smapi.DeleteCheck(context.Background(), id) |
| 254 | + }, |
| 255 | + ExpectNonEmptyPlan: true, |
| 256 | + }, |
| 257 | + { |
| 258 | + Config: testAccExample(t, "resources/grafana_synthetic_monitoring_check/http_basic.tf"), |
| 259 | + Check: resource.ComposeTestCheckFunc( |
| 260 | + resource.TestCheckResourceAttrSet("grafana_synthetic_monitoring_check.http", "id"), |
| 261 | + resource.TestCheckResourceAttrSet("grafana_synthetic_monitoring_check.http", "tenant_id"), |
| 262 | + resource.TestCheckResourceAttr("grafana_synthetic_monitoring_check.http", "job", "HTTP Defaults"), |
| 263 | + resource.TestCheckResourceAttr("grafana_synthetic_monitoring_check.http", "target", "https://grafana.com"), |
| 264 | + resource.TestCheckResourceAttr("grafana_synthetic_monitoring_check.http", "probes.0", "1"), |
| 265 | + resource.TestCheckResourceAttr("grafana_synthetic_monitoring_check.http", "labels.foo", "bar"), |
| 266 | + resource.TestCheckResourceAttr("grafana_synthetic_monitoring_check.http", "settings.0.http.0.ip_version", "V4"), |
| 267 | + resource.TestCheckResourceAttr("grafana_synthetic_monitoring_check.http", "settings.0.http.0.method", "GET"), |
| 268 | + resource.TestCheckResourceAttr("grafana_synthetic_monitoring_check.http", "settings.0.http.0.no_follow_redirects", "false"), |
| 269 | + ), |
| 270 | + }, |
| 271 | + }, |
| 272 | + }) |
| 273 | +} |
| 274 | + |
238 | 275 | func TestAccResourceSyntheticMonitoringCheck_noSettings(t *testing.T) { |
239 | 276 | CheckCloudInstanceTestsEnabled(t) |
240 | 277 |
|
|
0 commit comments