Skip to content

Commit 8c78dfc

Browse files
Contact Points: Add recreation test (#1614)
From this PR: #1612 This was already fixed in v3, but it can't hurt to have the test here as well.
1 parent 6d6fb31 commit 8c78dfc

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

internal/resources/grafana/resource_alerting_contact_point_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
1111
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1212
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
13+
"github.com/stretchr/testify/require"
1314

1415
"github.com/grafana/terraform-provider-grafana/v3/internal/testutils"
1516
)
@@ -483,6 +484,53 @@ func TestAccContactPoint_inOrg(t *testing.T) {
483484
})
484485
}
485486

487+
func TestAccContactPoint_recreate(t *testing.T) {
488+
testutils.CheckOSSTestsEnabled(t, ">=9.1.0")
489+
490+
var points models.ContactPoints
491+
name := acctest.RandString(10)
492+
config := testutils.TestAccExampleWithReplace(t, "resources/grafana_contact_point/resource.tf", map[string]string{
493+
"My Contact Point": name,
494+
})
495+
496+
resource.ParallelTest(t, resource.TestCase{
497+
ProtoV5ProviderFactories: testutils.ProtoV5ProviderFactories,
498+
Steps: []resource.TestStep{
499+
// Creation
500+
{
501+
Config: config,
502+
Check: resource.ComposeTestCheckFunc(
503+
checkAlertingContactPointExistsWithLength("grafana_contact_point.my_contact_point", &points, 1),
504+
resource.TestCheckResourceAttr("grafana_contact_point.my_contact_point", "name", name),
505+
resource.TestCheckResourceAttr("grafana_contact_point.my_contact_point", "email.#", "1"),
506+
),
507+
},
508+
// Delete the contact point and check that it is missing
509+
{
510+
PreConfig: func() {
511+
client := grafanaTestClient()
512+
for _, point := range points {
513+
_, err := client.Provisioning.DeleteContactpoints(point.UID)
514+
require.NoError(t, err)
515+
}
516+
},
517+
Config: config,
518+
PlanOnly: true,
519+
ExpectNonEmptyPlan: true,
520+
},
521+
// Recreate the contact point
522+
{
523+
Config: config,
524+
Check: resource.ComposeTestCheckFunc(
525+
checkAlertingContactPointExistsWithLength("grafana_contact_point.my_contact_point", &points, 1),
526+
resource.TestCheckResourceAttr("grafana_contact_point.my_contact_point", "name", name),
527+
resource.TestCheckResourceAttr("grafana_contact_point.my_contact_point", "email.#", "1"),
528+
),
529+
},
530+
},
531+
})
532+
}
533+
486534
func TestAccContactPoint_empty(t *testing.T) {
487535
testutils.CheckOSSTestsEnabled(t, ">=9.1.0")
488536

0 commit comments

Comments
 (0)