Skip to content

Commit 0193377

Browse files
committed
SUMO-170407: updated connection schema
1 parent 9a04f30 commit 0193377

File tree

2 files changed

+60
-2
lines changed

2 files changed

+60
-2
lines changed

sumologic/resource_sumologic_connection.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,15 @@ 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+
Default: "",
88+
},
8389
},
8490
}
8591
}
@@ -136,6 +142,7 @@ func resourceSumologicConnectionRead(d *schema.ResourceData, meta interface{}) e
136142
}
137143
d.Set("default_payload", connection.DefaultPayload)
138144
d.Set("webhook_type", connection.WebhookType)
145+
d.Set("connection_subtype", connection.ConnectionSubtype)
139146
d.SetId(connection.ID)
140147

141148
log.Println("====End Connection Read====")
@@ -200,8 +207,8 @@ func resourceToConnection(d *schema.ResourceData) Connection {
200207
connection.Headers = mapToHeaders(d.Get("headers").(map[string]interface{}))
201208
connection.CustomHeaders = mapToHeaders(d.Get("custom_headers").(map[string]interface{}))
202209
connection.DefaultPayload = d.Get("default_payload").(string)
203-
connection.ConnectionSubtype = d.Get("connection_subtype").(string)
204210
connection.WebhookType = d.Get("webhook_type").(string)
211+
connection.ConnectionSubtype = d.Get("connection_subtype").(string)
205212

206213
return connection
207214
}
@@ -234,4 +241,5 @@ func printConnection(connection Connection) {
234241
log.Printf("CustomHeaders: %s", connection.CustomHeaders)
235242
log.Printf("DefaultPayload: %s", connection.DefaultPayload)
236243
log.Printf("WebhookType: %s", connection.WebhookType)
244+
log.Printf("ConnectionSubtype: %s", connection.ConnectionSubtype)
237245
}

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+
}

0 commit comments

Comments
 (0)