Skip to content

Commit fc3e5d7

Browse files
authored
Merge pull request #250 from SumoLogic/rohit-servicenow-support
SUMO-170407: initial support for new ServiceNow connection
2 parents ce5df0c + 00a2b6d commit fc3e5d7

File tree

6 files changed

+76
-12
lines changed

6 files changed

+76
-12
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## 2.9.8 (Unreleased)
22

3+
FEATURES:
4+
5+
* Add support for ServiceNow Incident and Event webhook connection (GH-250)
6+
37
## 2.9.7 (July 22, 2021)
48

59
ENHANCEMENTS:

sumologic/resource_sumologic_connection.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,14 @@ func resourceSumologicConnection() *schema.Resource {
7777
"webhook_type": {
7878
Type: schema.TypeString,
7979
Optional: true,
80-
ValidateFunc: validation.StringInSlice([]string{"AWSLambda", "Azure", "Datadog", "HipChat", "PagerDuty", "Slack", "Webhook", "NewRelic", "Jira", "Opsgenie", "MicrosoftTeams"}, false),
80+
ValidateFunc: validation.StringInSlice([]string{"AWSLambda", "Azure", "Datadog", "HipChat", "PagerDuty", "Slack", "Webhook", "NewRelic", "Jira", "Opsgenie", "MicrosoftTeams", "ServiceNow"}, false),
8181
Default: "Webhook",
8282
},
83+
"connection_subtype": {
84+
Type: schema.TypeString,
85+
Optional: true,
86+
ValidateFunc: validation.StringInSlice([]string{"Incident", "Event"}, false),
87+
},
8388
},
8489
}
8590
}
@@ -136,6 +141,7 @@ func resourceSumologicConnectionRead(d *schema.ResourceData, meta interface{}) e
136141
}
137142
d.Set("default_payload", connection.DefaultPayload)
138143
d.Set("webhook_type", connection.WebhookType)
144+
d.Set("connection_subtype", connection.ConnectionSubtype)
139145
d.SetId(connection.ID)
140146

141147
log.Println("====End Connection Read====")
@@ -201,6 +207,7 @@ func resourceToConnection(d *schema.ResourceData) Connection {
201207
connection.CustomHeaders = mapToHeaders(d.Get("custom_headers").(map[string]interface{}))
202208
connection.DefaultPayload = d.Get("default_payload").(string)
203209
connection.WebhookType = d.Get("webhook_type").(string)
210+
connection.ConnectionSubtype = d.Get("connection_subtype").(string)
204211

205212
return connection
206213
}
@@ -233,4 +240,5 @@ func printConnection(connection Connection) {
233240
log.Printf("CustomHeaders: %s", connection.CustomHeaders)
234241
log.Printf("DefaultPayload: %s", connection.DefaultPayload)
235242
log.Printf("WebhookType: %s", connection.WebhookType)
243+
log.Printf("ConnectionSubtype: %s", connection.ConnectionSubtype)
236244
}

sumologic/resource_sumologic_connection_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,40 @@ func TestAccConnection_create(t *testing.T) {
4242
})
4343
}
4444

45+
func TestAccConnection_createServiceNowWebhook(t *testing.T) {
46+
connectionType := "WebhookConnection"
47+
name := acctest.RandomWithPrefix("tf-servicenow-webhook-connection-test-name")
48+
description := acctest.RandomWithPrefix("tf-servicenow-webhook-connection-test-description")
49+
url := "https://example.com"
50+
defaultPayload := "{\"eventType\" : \"{{Name}}\"}"
51+
webhookType := "ServiceNow"
52+
connectionSubtype := "Incident"
53+
54+
var connection Connection
55+
56+
resource.Test(t, resource.TestCase{
57+
PreCheck: func() { testAccPreCheck(t) },
58+
Providers: testAccProviders,
59+
CheckDestroy: testAccCheckConnectionDestroy,
60+
Steps: []resource.TestStep{
61+
{
62+
Config: createServiceNowWebhookConnectionConfig(name, connectionType, description, url, connectionSubtype, defaultPayload),
63+
Check: resource.ComposeTestCheckFunc(
64+
testAccCheckConnectionExists("sumologic_connection.serviceNowTest", &connection, t),
65+
testAccCheckConnectionAttributes("sumologic_connection.serviceNowTest"),
66+
resource.TestCheckResourceAttr("sumologic_connection.serviceNowTest", "type", connectionType),
67+
resource.TestCheckResourceAttr("sumologic_connection.serviceNowTest", "name", name),
68+
resource.TestCheckResourceAttr("sumologic_connection.serviceNowTest", "description", description),
69+
resource.TestCheckResourceAttr("sumologic_connection.serviceNowTest", "url", url),
70+
resource.TestCheckResourceAttr("sumologic_connection.serviceNowTest", "default_payload", defaultPayload+"\n"),
71+
resource.TestCheckResourceAttr("sumologic_connection.serviceNowTest", "webhook_type", webhookType),
72+
resource.TestCheckResourceAttr("sumologic_connection.serviceNowTest", "connection_subtype", connectionSubtype),
73+
),
74+
},
75+
},
76+
})
77+
}
78+
4579
func TestAccConnection_update(t *testing.T) {
4680
var connection Connection
4781
connectionType := "WebhookConnection"
@@ -151,3 +185,19 @@ JSON
151185
}
152186
`, name, connectionType, desc, url, webhookType, defaultPayload)
153187
}
188+
189+
func createServiceNowWebhookConnectionConfig(name, connectionType, desc, url, connectionSubtype, defaultPayload string) string {
190+
return fmt.Sprintf(`
191+
resource "sumologic_connection" "serviceNowTest" {
192+
name = "%s"
193+
type = "%s"
194+
description = "%s"
195+
url = "%s"
196+
webhook_type = "ServiceNow"
197+
connection_subtype = "%s"
198+
default_payload = <<JSON
199+
%s
200+
JSON
201+
}
202+
`, name, connectionType, desc, url, connectionSubtype, defaultPayload)
203+
}

sumologic/resource_sumologic_monitors_library_monitor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func resourceSumologicMonitorsLibraryMonitor() *schema.Resource {
149149
Type: schema.TypeString,
150150
Optional: true,
151151
Computed: true,
152-
ValidateFunc: validation.StringInSlice([]string{"Email", "AWSLambda", "AzureFunctions", "Datadog", "HipChat", "Jira", "NewRelic", "Opsgenie", "PagerDuty", "Slack", "MicrosoftTeams", "Webhook"}, false),
152+
ValidateFunc: validation.StringInSlice([]string{"Email", "AWSLambda", "AzureFunctions", "Datadog", "HipChat", "Jira", "NewRelic", "Opsgenie", "PagerDuty", "Slack", "MicrosoftTeams", "ServiceNow", "Webhook"}, false),
153153
},
154154
"subject": {
155155
Type: schema.TypeString,

sumologic/sumologic_client.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -351,15 +351,16 @@ type Content struct {
351351

352352
// Connection is used to describe a connection.
353353
type Connection struct {
354-
ID string `json:"id,omitempty"`
355-
Type string `json:"type"`
356-
Name string `json:"name"`
357-
Description string `json:"description,omitempty"`
358-
URL string `json:"url"`
359-
Headers []Headers `json:"headers,omitempty"`
360-
CustomHeaders []Headers `json:"customHeaders,omitempty"`
361-
DefaultPayload string `json:"defaultPayload"`
362-
WebhookType string `json:"webhookType"`
354+
ID string `json:"id,omitempty"`
355+
Type string `json:"type"`
356+
Name string `json:"name"`
357+
Description string `json:"description,omitempty"`
358+
URL string `json:"url"`
359+
Headers []Headers `json:"headers,omitempty"`
360+
CustomHeaders []Headers `json:"customHeaders,omitempty"`
361+
DefaultPayload string `json:"defaultPayload"`
362+
WebhookType string `json:"webhookType"`
363+
ConnectionSubtype string `json:"connectionSubtype,omitempty"`
363364
}
364365

365366
// Headers is used to describe headers for http requests.

website/docs/r/connection.html.markdown

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ The following arguments are supported:
4848
- `headers` - (Optional) Map of access authorization headers.
4949
- `custom_headers` - (Optional) Map of custom webhook headers
5050
- `default_payload` - (Required) Default payload of the webhook.
51-
- `webhook_type` - (Optional) Type of webhook. Valid values are `AWSLambda`, `Azure`, `Datadog`, `HipChat`, `PagerDuty`, `Slack`, `Webhook`, `NewRelic`, and `MicrosoftTeams`. Default: `Webhook`
51+
- `connection_subtype` - (Optional) The subtype of the connection. Valid values are `Incident` and `Event`. NOTE: This is only used for the `ServiceNow` webhook type.
52+
- `webhook_type` - (Optional) Type of webhook. Valid values are `AWSLambda`, `Azure`, `Datadog`, `HipChat`, `PagerDuty`, `Slack`, `Webhook`, `NewRelic`, `MicrosoftTeams`, and `ServiceNow`. Default: `Webhook`
5253

5354
Additional data provided in state
5455

0 commit comments

Comments
 (0)