|
| 1 | +package sysdig_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "github.com/draios/terraform-provider-sysdig/sysdig" |
| 6 | + "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" |
| 7 | + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" |
| 8 | + "github.com/hashicorp/terraform-plugin-sdk/terraform" |
| 9 | + "os" |
| 10 | + "testing" |
| 11 | +) |
| 12 | + |
| 13 | +func TestAccNotificationChannel(t *testing.T) { |
| 14 | + //var ncBefore, ncAfter secure.NotificationChannel |
| 15 | + |
| 16 | + rText := func() string { return acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) } |
| 17 | + |
| 18 | + resource.ParallelTest(t, resource.TestCase{ |
| 19 | + PreCheck: func() { |
| 20 | + if v := os.Getenv("SYSDIG_SECURE_API_TOKEN"); v == "" { |
| 21 | + t.Fatal("SYSDIG_SECURE_API_TOKEN must be set for acceptance tests") |
| 22 | + } |
| 23 | + }, |
| 24 | + Providers: map[string]terraform.ResourceProvider{ |
| 25 | + "sysdig": sysdig.Provider(), |
| 26 | + }, |
| 27 | + Steps: []resource.TestStep{ |
| 28 | + { |
| 29 | + Config: notificationChannelEmailWithName(rText()), |
| 30 | + }, |
| 31 | + { |
| 32 | + Config: notificationChannelAmazonSNSWithName(rText()), |
| 33 | + }, |
| 34 | + { |
| 35 | + Config: notificationChannelOpsGenieWithName(rText()), |
| 36 | + }, |
| 37 | + { |
| 38 | + Config: notificationChannelVictorOpsWithName(rText()), |
| 39 | + }, |
| 40 | + { |
| 41 | + Config: notificationChannelWebhookWithName(rText()), |
| 42 | + }, |
| 43 | + { |
| 44 | + Config: notificationChannelSlackWithName(rText()), |
| 45 | + }, |
| 46 | + }, |
| 47 | + }) |
| 48 | +} |
| 49 | + |
| 50 | +func notificationChannelEmailWithName(name string) string { |
| 51 | + return fmt.Sprintf(` |
| 52 | +resource "sysdig_secure_notification_channel" "sample_email" { |
| 53 | + name = "%s" |
| 54 | + enabled = true |
| 55 | + type = "EMAIL" |
| 56 | + |
| 57 | + notify_when_ok = false |
| 58 | + notify_when_resolved = false |
| 59 | +}`, name) |
| 60 | +} |
| 61 | + |
| 62 | +func notificationChannelAmazonSNSWithName(name string) string { |
| 63 | + return fmt.Sprintf(` |
| 64 | +resource "sysdig_secure_notification_channel" "sample-amazon-sns" { |
| 65 | + name = "Example Channel %s - Amazon SNS" |
| 66 | + enabled = true |
| 67 | + type = "SNS" |
| 68 | + topics = "arn:aws:sns:us-east-1:273489009834:my-alerts,arn:aws:sns:us-east-1:279948934544:my-alerts2" |
| 69 | + notify_when_ok = false |
| 70 | + notify_when_resolved = false |
| 71 | +}`, name) |
| 72 | +} |
| 73 | + |
| 74 | +func notificationChannelVictorOpsWithName(name string) string { |
| 75 | + return fmt.Sprintf(` |
| 76 | +resource "sysdig_secure_notification_channel" "sample-victorops" { |
| 77 | + name = "Example Channel %s - VictorOps" |
| 78 | + enabled = true |
| 79 | + type = "VICTOROPS" |
| 80 | + api_key = "1234342-4234243-4234-2" |
| 81 | + routing_key = "My team" |
| 82 | + notify_when_ok = false |
| 83 | + notify_when_resolved = false |
| 84 | +}`, name) |
| 85 | +} |
| 86 | + |
| 87 | +func notificationChannelOpsGenieWithName(name string) string { |
| 88 | + return fmt.Sprintf(` |
| 89 | +resource "sysdig_secure_notification_channel" "sample-opsgenie" { |
| 90 | + name = "Example Channel %s - OpsGenie" |
| 91 | + enabled = true |
| 92 | + type = "OPSGENIE" |
| 93 | + api_key = "2349324-342354353-5324-23" |
| 94 | + notify_when_ok = false |
| 95 | + notify_when_resolved = false |
| 96 | +}`, name) |
| 97 | +} |
| 98 | + |
| 99 | +func notificationChannelWebhookWithName(name string) string { |
| 100 | + return fmt.Sprintf(` |
| 101 | +resource "sysdig_secure_notification_channel" "sample-webhook" { |
| 102 | + name = "Example Channel %s - Webhook" |
| 103 | + enabled = true |
| 104 | + type = "WEBHOOK" |
| 105 | + url = "localhost:8080" |
| 106 | + notify_when_ok = false |
| 107 | + notify_when_resolved = false |
| 108 | +}`, name) |
| 109 | +} |
| 110 | + |
| 111 | +func notificationChannelSlackWithName(name string) string { |
| 112 | + return fmt.Sprintf(` |
| 113 | +resource "sysdig_secure_notification_channel" "sample-slack" { |
| 114 | + name = "Example Channel %s - Slack" |
| 115 | + enabled = true |
| 116 | + type = "SLACK" |
| 117 | + url = "https://hooks.slack.cwom/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX" |
| 118 | + channel = "#sysdig" |
| 119 | + notify_when_ok = true |
| 120 | + notify_when_resolved = true |
| 121 | +}`, name) |
| 122 | +} |
0 commit comments