@@ -24,12 +24,19 @@ func TestAccAlertNotification_basic(t *testing.T) {
2424 Config : testAccAlertNotificationConfig_basic ,
2525 Check : resource .ComposeTestCheckFunc (
2626 testAccAlertNotificationCheckExists ("grafana_alert_notification.test" , & alertNotification ),
27+ testAccAlertNotificationDefinition (& alertNotification ),
2728 resource .TestCheckResourceAttr (
2829 "grafana_alert_notification.test" , "type" , "email" ,
2930 ),
3031 resource .TestMatchResourceAttr (
3132 "grafana_alert_notification.test" , "id" , regexp .MustCompile (`\d+` ),
3233 ),
34+ resource .TestCheckResourceAttr (
35+ "grafana_alert_notification.test" , "send_reminder" , "true" ,
36+ ),
37+ resource .TestCheckResourceAttr (
38+ "grafana_alert_notification.test" , "frequency" , "12h" ,
39+ ),
3340 resource .TestCheckResourceAttr (
3441 "grafana_alert_notification.test" ,
"settings.addresses" ,
"[email protected] " ,
3542 ),
@@ -39,6 +46,38 @@ func TestAccAlertNotification_basic(t *testing.T) {
3946 })
4047}
4148
49+ func TestAccAlertNotification_invalid_frequence (t * testing.T ) {
50+ var alertNotification gapi.AlertNotification
51+
52+ resource .Test (t , resource.TestCase {
53+ PreCheck : func () { testAccPreCheck (t ) },
54+ Providers : testAccProviders ,
55+ CheckDestroy : testAccAlertNotificationCheckDestroy (& alertNotification ),
56+ Steps : []resource.TestStep {
57+ {
58+ ExpectError : regexp .MustCompile ("invalid duration hi" ),
59+ Config : testAccAlertNotificationConfig_invalid_frequency ,
60+ },
61+ },
62+ })
63+ }
64+
65+ func TestAccAlertNotification_reminder_no_frequence (t * testing.T ) {
66+ var alertNotification gapi.AlertNotification
67+
68+ resource .Test (t , resource.TestCase {
69+ PreCheck : func () { testAccPreCheck (t ) },
70+ Providers : testAccProviders ,
71+ CheckDestroy : testAccAlertNotificationCheckDestroy (& alertNotification ),
72+ Steps : []resource.TestStep {
73+ {
74+ ExpectError : regexp .MustCompile ("frequency must be set when send_reminder is set to 'true'" ),
75+ Config : testAccAlertNotificationConfig_reminder_no_frequency ,
76+ },
77+ },
78+ })
79+ }
80+
4281func testAccAlertNotificationCheckExists (rn string , a * gapi.AlertNotification ) resource.TestCheckFunc {
4382 return func (s * terraform.State ) error {
4483 rs , ok := s .RootModule ().Resources [rn ]
@@ -67,6 +106,16 @@ func testAccAlertNotificationCheckExists(rn string, a *gapi.AlertNotification) r
67106 }
68107}
69108
109+ func testAccAlertNotificationDefinition (a * gapi.AlertNotification ) resource.TestCheckFunc {
110+ return func (s * terraform.State ) error {
111+ if ! a .SendReminder {
112+ return fmt .Errorf ("send_reminder is not set properly" )
113+ }
114+
115+ return nil
116+ }
117+ }
118+
70119func testAccAlertNotificationCheckDestroy (a * gapi.AlertNotification ) resource.TestCheckFunc {
71120 return func (s * terraform.State ) error {
72121 client := testAccProvider .Meta ().(* gapi.Client )
@@ -82,6 +131,35 @@ const testAccAlertNotificationConfig_basic = `
82131resource "grafana_alert_notification" "test" {
83132 type = "email"
84133 name = "terraform-acc-test"
134+ send_reminder = true
135+ frequency = "12h"
136+ settings = {
137+ 138+ "uploadImage" = "false"
139+ "autoResolve" = "true"
140+ }
141+ }
142+ `
143+
144+ const testAccAlertNotificationConfig_invalid_frequency = `
145+ resource "grafana_alert_notification" "test" {
146+ type = "email"
147+ name = "terraform-acc-test"
148+ send_reminder = true
149+ frequency = "hi"
150+ settings = {
151+ 152+ "uploadImage" = "false"
153+ "autoResolve" = "true"
154+ }
155+ }
156+ `
157+
158+ const testAccAlertNotificationConfig_reminder_no_frequency = `
159+ resource "grafana_alert_notification" "test" {
160+ type = "email"
161+ name = "terraform-acc-test"
162+ send_reminder = true
85163 settings = {
8616487165 "uploadImage" = "false"
0 commit comments