From 8c78dfc67c0afacf008c031dcf27eb2b3ab6540c Mon Sep 17 00:00:00 2001 From: Julien Duchesne Date: Wed, 5 Jun 2024 10:15:04 -0400 Subject: [PATCH] Contact Points: Add recreation test (#1614) From this PR: https://github.com/grafana/terraform-provider-grafana/pull/1612 This was already fixed in v3, but it can't hurt to have the test here as well. --- .../resource_alerting_contact_point_test.go | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/internal/resources/grafana/resource_alerting_contact_point_test.go b/internal/resources/grafana/resource_alerting_contact_point_test.go index 9cfb9e7d6..42c11a5bc 100644 --- a/internal/resources/grafana/resource_alerting_contact_point_test.go +++ b/internal/resources/grafana/resource_alerting_contact_point_test.go @@ -10,6 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/stretchr/testify/require" "github.com/grafana/terraform-provider-grafana/v3/internal/testutils" ) @@ -483,6 +484,53 @@ func TestAccContactPoint_inOrg(t *testing.T) { }) } +func TestAccContactPoint_recreate(t *testing.T) { + testutils.CheckOSSTestsEnabled(t, ">=9.1.0") + + var points models.ContactPoints + name := acctest.RandString(10) + config := testutils.TestAccExampleWithReplace(t, "resources/grafana_contact_point/resource.tf", map[string]string{ + "My Contact Point": name, + }) + + resource.ParallelTest(t, resource.TestCase{ + ProtoV5ProviderFactories: testutils.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + // Creation + { + Config: config, + Check: resource.ComposeTestCheckFunc( + checkAlertingContactPointExistsWithLength("grafana_contact_point.my_contact_point", &points, 1), + resource.TestCheckResourceAttr("grafana_contact_point.my_contact_point", "name", name), + resource.TestCheckResourceAttr("grafana_contact_point.my_contact_point", "email.#", "1"), + ), + }, + // Delete the contact point and check that it is missing + { + PreConfig: func() { + client := grafanaTestClient() + for _, point := range points { + _, err := client.Provisioning.DeleteContactpoints(point.UID) + require.NoError(t, err) + } + }, + Config: config, + PlanOnly: true, + ExpectNonEmptyPlan: true, + }, + // Recreate the contact point + { + Config: config, + Check: resource.ComposeTestCheckFunc( + checkAlertingContactPointExistsWithLength("grafana_contact_point.my_contact_point", &points, 1), + resource.TestCheckResourceAttr("grafana_contact_point.my_contact_point", "name", name), + resource.TestCheckResourceAttr("grafana_contact_point.my_contact_point", "email.#", "1"), + ), + }, + }, + }) +} + func TestAccContactPoint_empty(t *testing.T) { testutils.CheckOSSTestsEnabled(t, ">=9.1.0")