99 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1010)
1111
12- func TestAccDataSourceCentralNotificationChannel (t * testing.T ) {
12+ func TestAccDataSourceCentralNotificationChannel_email (t * testing.T ) {
1313 id := fmt .Sprintf ("%s_%s" , t .Name (), utils .RandStringBytes (6 ))
1414 name := id
1515 resourceName := "data.harness_platform_central_notification_channel.test"
@@ -27,6 +27,108 @@ func TestAccDataSourceCentralNotificationChannel(t *testing.T) {
2727 resource .TestCheckResourceAttr (resourceName , "identifier" , id ),
2828 resource .TestCheckResourceAttr (resourceName , "org" , id ),
2929 resource .TestCheckResourceAttr (resourceName , "project" , id ),
30+ resource .TestCheckResourceAttr (resourceName , "notification_channel_type" , "EMAIL" ),
31+ resource .TestCheckResourceAttr (resourceName , "status" , "ENABLED" ),
32+ ),
33+ },
34+ },
35+ })
36+ }
37+
38+ func TestAccDataSourceCentralNotificationChannel_slack (t * testing.T ) {
39+ id := fmt .Sprintf ("%s_%s" , t .Name (), utils .RandStringBytes (6 ))
40+ name := id
41+ resourceName := "data.harness_platform_central_notification_channel.test"
42+
43+ resource .UnitTest (t , resource.TestCase {
44+ PreCheck : func () { acctest .TestAccPreCheck (t ) },
45+ ProviderFactories : acctest .ProviderFactories ,
46+ ExternalProviders : map [string ]resource.ExternalProvider {
47+ "time" : {},
48+ },
49+ Steps : []resource.TestStep {
50+ {
51+ Config : testAccDataSourceCentralNotificationChannelSlack (id , name ),
52+ Check : resource .ComposeTestCheckFunc (
53+ resource .TestCheckResourceAttr (resourceName , "identifier" , id ),
54+ resource .TestCheckResourceAttr (resourceName , "notification_channel_type" , "SLACK" ),
55+ resource .TestCheckResourceAttr (resourceName , "status" , "ENABLED" ),
56+ resource .TestCheckResourceAttr (resourceName , "channel.0.slack_webhook_urls.0" , "https://hooks.slack.com/services/test" ),
57+ ),
58+ },
59+ },
60+ })
61+ }
62+
63+ func TestAccDataSourceCentralNotificationChannel_msteams (t * testing.T ) {
64+ id := fmt .Sprintf ("%s_%s" , t .Name (), utils .RandStringBytes (6 ))
65+ name := id
66+ resourceName := "data.harness_platform_central_notification_channel.test"
67+
68+ resource .UnitTest (t , resource.TestCase {
69+ PreCheck : func () { acctest .TestAccPreCheck (t ) },
70+ ProviderFactories : acctest .ProviderFactories ,
71+ ExternalProviders : map [string ]resource.ExternalProvider {
72+ "time" : {},
73+ },
74+ Steps : []resource.TestStep {
75+ {
76+ Config : testAccDataSourceCentralNotificationChannelMSTeams (id , name ),
77+ Check : resource .ComposeTestCheckFunc (
78+ resource .TestCheckResourceAttr (resourceName , "identifier" , id ),
79+ resource .TestCheckResourceAttr (resourceName , "notification_channel_type" , "MSTEAMS" ),
80+ resource .TestCheckResourceAttr (resourceName , "status" , "ENABLED" ),
81+ resource .TestCheckResourceAttr (resourceName , "channel.0.ms_team_keys.0" , "https://outlook.office.com/webhook/test" ),
82+ ),
83+ },
84+ },
85+ })
86+ }
87+
88+ func TestAccDataSourceCentralNotificationChannel_pagerduty (t * testing.T ) {
89+ id := fmt .Sprintf ("%s_%s" , t .Name (), utils .RandStringBytes (6 ))
90+ name := id
91+ resourceName := "data.harness_platform_central_notification_channel.test"
92+
93+ resource .UnitTest (t , resource.TestCase {
94+ PreCheck : func () { acctest .TestAccPreCheck (t ) },
95+ ProviderFactories : acctest .ProviderFactories ,
96+ ExternalProviders : map [string ]resource.ExternalProvider {
97+ "time" : {},
98+ },
99+ Steps : []resource.TestStep {
100+ {
101+ Config : testAccDataSourceCentralNotificationChannelPagerDuty (id , name ),
102+ Check : resource .ComposeTestCheckFunc (
103+ resource .TestCheckResourceAttr (resourceName , "identifier" , id ),
104+ resource .TestCheckResourceAttr (resourceName , "notification_channel_type" , "PAGERDUTY" ),
105+ resource .TestCheckResourceAttr (resourceName , "status" , "ENABLED" ),
106+ resource .TestCheckResourceAttr (resourceName , "channel.0.pager_duty_integration_keys.0" , "test-integration-key" ),
107+ ),
108+ },
109+ },
110+ })
111+ }
112+
113+ func TestAccDataSourceCentralNotificationChannel_webhook (t * testing.T ) {
114+ id := fmt .Sprintf ("%s_%s" , t .Name (), utils .RandStringBytes (6 ))
115+ name := id
116+ resourceName := "data.harness_platform_central_notification_channel.test"
117+
118+ resource .UnitTest (t , resource.TestCase {
119+ PreCheck : func () { acctest .TestAccPreCheck (t ) },
120+ ProviderFactories : acctest .ProviderFactories ,
121+ ExternalProviders : map [string ]resource.ExternalProvider {
122+ "time" : {},
123+ },
124+ Steps : []resource.TestStep {
125+ {
126+ Config : testAccDataSourceCentralNotificationChannelWebhook (id , name ),
127+ Check : resource .ComposeTestCheckFunc (
128+ resource .TestCheckResourceAttr (resourceName , "identifier" , id ),
129+ resource .TestCheckResourceAttr (resourceName , "notification_channel_type" , "WEBHOOK" ),
130+ resource .TestCheckResourceAttr (resourceName , "status" , "ENABLED" ),
131+ resource .TestCheckResourceAttr (resourceName , "channel.0.webhook_urls.0" , "https://webhook.example.com/test" ),
30132 ),
31133 },
32134 },
@@ -75,3 +177,246 @@ func testAccDataSourceCentralNotificationChannel(id string, name string) string
75177 }
76178 ` , id , name )
77179}
180+
181+ func testAccDataSourceCentralNotificationChannelSlack (id string , name string ) string {
182+ return fmt .Sprintf (`
183+ resource "harness_platform_organization" "test" {
184+ identifier = "%[1]s"
185+ name = "%[2]s"
186+ }
187+
188+ resource "harness_platform_project" "test" {
189+ identifier = "%[1]s"
190+ name = "%[2]s"
191+ org_id = harness_platform_organization.test.id
192+ color = "#472848"
193+ }
194+
195+ resource "harness_platform_central_notification_channel" "test" {
196+ depends_on = [
197+ harness_platform_organization.test,
198+ harness_platform_project.test,
199+ ]
200+ identifier = "%[1]s"
201+ org = harness_platform_organization.test.id
202+ project = harness_platform_project.test.id
203+ name = "%[2]s"
204+ notification_channel_type = "SLACK"
205+ status = "ENABLED"
206+
207+ channel {
208+ slack_webhook_urls = ["https://hooks.slack.com/services/test"]
209+ }
210+ }
211+
212+ data "harness_platform_central_notification_channel" "test" {
213+ identifier = harness_platform_central_notification_channel.test.identifier
214+ org = harness_platform_organization.test.id
215+ project = harness_platform_project.test.id
216+ }
217+
218+ resource "time_sleep" "wait_4_seconds" {
219+ destroy_duration = "4s"
220+ }
221+ ` , id , name )
222+ }
223+
224+ func testAccDataSourceCentralNotificationChannelMSTeams (id string , name string ) string {
225+ return fmt .Sprintf (`
226+ resource "harness_platform_organization" "test" {
227+ identifier = "%[1]s"
228+ name = "%[2]s"
229+ }
230+
231+ resource "harness_platform_project" "test" {
232+ identifier = "%[1]s"
233+ name = "%[2]s"
234+ org_id = harness_platform_organization.test.id
235+ color = "#472848"
236+ }
237+
238+ resource "harness_platform_central_notification_channel" "test" {
239+ depends_on = [
240+ harness_platform_organization.test,
241+ harness_platform_project.test,
242+ ]
243+ identifier = "%[1]s"
244+ org = harness_platform_organization.test.id
245+ project = harness_platform_project.test.id
246+ name = "%[2]s"
247+ notification_channel_type = "MSTEAMS"
248+ status = "ENABLED"
249+
250+ channel {
251+ ms_team_keys = ["https://outlook.office.com/webhook/test"]
252+ }
253+ }
254+
255+ data "harness_platform_central_notification_channel" "test" {
256+ identifier = harness_platform_central_notification_channel.test.identifier
257+ org = harness_platform_organization.test.id
258+ project = harness_platform_project.test.id
259+ }
260+
261+ resource "time_sleep" "wait_4_seconds" {
262+ destroy_duration = "4s"
263+ }
264+ ` , id , name )
265+ }
266+
267+ func testAccDataSourceCentralNotificationChannelPagerDuty (id string , name string ) string {
268+ return fmt .Sprintf (`
269+ resource "harness_platform_organization" "test" {
270+ identifier = "%[1]s"
271+ name = "%[2]s"
272+ }
273+
274+ resource "harness_platform_project" "test" {
275+ identifier = "%[1]s"
276+ name = "%[2]s"
277+ org_id = harness_platform_organization.test.id
278+ color = "#472848"
279+ }
280+
281+ resource "harness_platform_central_notification_channel" "test" {
282+ depends_on = [
283+ harness_platform_organization.test,
284+ harness_platform_project.test,
285+ ]
286+ identifier = "%[1]s"
287+ org = harness_platform_organization.test.id
288+ project = harness_platform_project.test.id
289+ name = "%[2]s"
290+ notification_channel_type = "PAGERDUTY"
291+ status = "ENABLED"
292+
293+ channel {
294+ pager_duty_integration_keys = ["test-integration-key"]
295+ }
296+ }
297+
298+ data "harness_platform_central_notification_channel" "test" {
299+ identifier = harness_platform_central_notification_channel.test.identifier
300+ org = harness_platform_organization.test.id
301+ project = harness_platform_project.test.id
302+ }
303+
304+ resource "time_sleep" "wait_4_seconds" {
305+ destroy_duration = "4s"
306+ }
307+ ` , id , name )
308+ }
309+
310+ func testAccDataSourceCentralNotificationChannelWebhook (id string , name string ) string {
311+ return fmt .Sprintf (`
312+ resource "harness_platform_organization" "test" {
313+ identifier = "%[1]s"
314+ name = "%[2]s"
315+ }
316+
317+ resource "harness_platform_project" "test" {
318+ identifier = "%[1]s"
319+ name = "%[2]s"
320+ org_id = harness_platform_organization.test.id
321+ color = "#472848"
322+ }
323+
324+ resource "harness_platform_central_notification_channel" "test" {
325+ depends_on = [
326+ harness_platform_organization.test,
327+ harness_platform_project.test,
328+ ]
329+ identifier = "%[1]s"
330+ org = harness_platform_organization.test.id
331+ project = harness_platform_project.test.id
332+ name = "%[2]s"
333+ notification_channel_type = "WEBHOOK"
334+ status = "ENABLED"
335+
336+ channel {
337+ webhook_urls = ["https://webhook.example.com/test"]
338+ }
339+ }
340+
341+ data "harness_platform_central_notification_channel" "test" {
342+ identifier = harness_platform_central_notification_channel.test.identifier
343+ org = harness_platform_organization.test.id
344+ project = harness_platform_project.test.id
345+ }
346+
347+ resource "time_sleep" "wait_4_seconds" {
348+ destroy_duration = "4s"
349+ }
350+ ` , id , name )
351+ }
352+
353+ func TestAccDataSourceCentralNotificationChannel_datadog (t * testing.T ) {
354+ id := fmt .Sprintf ("%s_%s" , t .Name (), utils .RandStringBytes (6 ))
355+ name := id
356+ resourceName := "data.harness_platform_central_notification_channel.test"
357+
358+ resource .UnitTest (t , resource.TestCase {
359+ PreCheck : func () { acctest .TestAccPreCheck (t ) },
360+ ProviderFactories : acctest .ProviderFactories ,
361+ ExternalProviders : map [string ]resource.ExternalProvider {
362+ "time" : {},
363+ },
364+ Steps : []resource.TestStep {
365+ {
366+ Config : testAccDataSourceCentralNotificationChannelDatadog (id , name ),
367+ Check : resource .ComposeTestCheckFunc (
368+ resource .TestCheckResourceAttr (resourceName , "identifier" , id ),
369+ resource .TestCheckResourceAttr (resourceName , "notification_channel_type" , "DATADOG" ),
370+ resource .TestCheckResourceAttr (resourceName , "status" , "ENABLED" ),
371+ resource .TestCheckResourceAttr (resourceName , "channel.0.datadog_urls.0" , "https://api.datadoghq.com/api/v1/events" ),
372+ resource .TestCheckResourceAttr (resourceName , "channel.0.api_key" , "test-api-key" ),
373+ ),
374+ },
375+ },
376+ })
377+ }
378+
379+ func testAccDataSourceCentralNotificationChannelDatadog (id string , name string ) string {
380+ return fmt .Sprintf (`
381+ resource "harness_platform_organization" "test" {
382+ identifier = "%[1]s"
383+ name = "%[2]s"
384+ }
385+
386+ resource "harness_platform_project" "test" {
387+ identifier = "%[1]s"
388+ name = "%[2]s"
389+ org_id = harness_platform_organization.test.id
390+ color = "#472848"
391+ }
392+
393+ resource "harness_platform_central_notification_channel" "test" {
394+ depends_on = [
395+ harness_platform_organization.test,
396+ harness_platform_project.test,
397+ ]
398+ identifier = "%[1]s"
399+ org = harness_platform_organization.test.id
400+ project = harness_platform_project.test.id
401+ name = "%[2]s"
402+ notification_channel_type = "DATADOG"
403+ status = "ENABLED"
404+
405+ channel {
406+ datadog_urls = ["https://api.datadoghq.com/api/v1/events"]
407+ api_key = "test-api-key"
408+ }
409+ }
410+
411+ data "harness_platform_central_notification_channel" "test" {
412+ identifier = harness_platform_central_notification_channel.test.identifier
413+ org = harness_platform_organization.test.id
414+ project = harness_platform_project.test.id
415+ }
416+
417+ resource "time_sleep" "wait_4_seconds" {
418+ destroy_duration = "4s"
419+ }
420+ ` , id , name )
421+ }
422+
0 commit comments