Skip to content

Commit

Permalink
feat: Add support for ServiceNow Alert custom JSON template (#78)
Browse files Browse the repository at this point in the history
* feat: Add support for ServiceNow Alert custom JSON template

Signed-off-by: Darren Murray <darren.murray@lacework.net>
  • Loading branch information
dmurray-lacework authored Feb 26, 2021
1 parent 428aaad commit a315965
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 27 deletions.
6 changes: 6 additions & 0 deletions examples/resource_lacework_alert_channel_service_now/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@ resource "lacework_alert_channel_service_now" "example" {
instance_url = "snow-lacework.com"
username = "snow-user"
password = "snow-pass"
custom_template_file = <<TEMPLATE
{
"description" : "Generated by Lacework:",
"approval" : "Approved"
}
TEMPLATE
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/hashicorp/terraform-plugin-sdk v1.16.0
github.com/hashicorp/terraform-svchost v0.0.0-20191119180714-d2e4933b9136 // indirect
github.com/hashicorp/yamux v0.0.0-20200609203250-aecfd211c9ce // indirect
github.com/lacework/go-sdk v0.2.20-0.20210219142651-0e9f6f57e16e
github.com/lacework/go-sdk v0.2.21-0.20210224193400-129bc2861f7b
github.com/mattn/go-colorable v0.1.7 // indirect
github.com/mitchellh/go-homedir v1.1.0
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,8 @@ github.com/lacework/go-sdk v0.2.20-0.20210219030740-d7242b84a525 h1:AWsfiGWpdtok
github.com/lacework/go-sdk v0.2.20-0.20210219030740-d7242b84a525/go.mod h1:yiEjWVHT4TjkZZ1pa9eS8fIfnnoVuzj1VNTIVEIsSKE=
github.com/lacework/go-sdk v0.2.20-0.20210219142651-0e9f6f57e16e h1:I5iMG4s/y2fgai7f6QXPJv0HqvjObYTKPO1LkgHiJQY=
github.com/lacework/go-sdk v0.2.20-0.20210219142651-0e9f6f57e16e/go.mod h1:yiEjWVHT4TjkZZ1pa9eS8fIfnnoVuzj1VNTIVEIsSKE=
github.com/lacework/go-sdk v0.2.21-0.20210224193400-129bc2861f7b h1:nJVvyGiuUGQmHCkdFLksxCJIio7R8aAhSCBKPgDA56A=
github.com/lacework/go-sdk v0.2.21-0.20210224193400-129bc2861f7b/go.mod h1:yiEjWVHT4TjkZZ1pa9eS8fIfnnoVuzj1VNTIVEIsSKE=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
Expand Down
49 changes: 31 additions & 18 deletions lacework/resource_lacework_alert_channel_service_now.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ func resourceLaceworkAlertChannelServiceNow() *schema.Resource {
}
},
},
"custom_template_file": {
Type: schema.TypeString,
Optional: true,
},
"created_or_updated_time": {
Type: schema.TypeString,
Computed: true,
Expand All @@ -85,16 +89,21 @@ func resourceLaceworkAlertChannelServiceNow() *schema.Resource {

func resourceLaceworkAlertChannelServiceNowCreate(d *schema.ResourceData, meta interface{}) error {
var (
lacework = meta.(*api.Client)
serviceNow = api.NewServiceNowAlertChannel(d.Get("name").(string),
api.ServiceNowChannelData{
InstanceURL: d.Get("instance_url").(string),
Username: d.Get("username").(string),
Password: d.Get("password").(string),
IssueGrouping: d.Get("issue_grouping").(string),
},
)
lacework = meta.(*api.Client)
customTemplateJSON = d.Get("custom_template_file").(string)
snowData = api.ServiceNowChannelData{
InstanceURL: d.Get("instance_url").(string),
Username: d.Get("username").(string),
Password: d.Get("password").(string),
IssueGrouping: d.Get("issue_grouping").(string),
}
)

if len(customTemplateJSON) != 0 {
snowData.EncodeCustomTemplateFile(customTemplateJSON)
}

serviceNow := api.NewServiceNowAlertChannel(d.Get("name").(string), snowData)
if !d.Get("enabled").(bool) {
serviceNow.Enabled = 0
}
Expand Down Expand Up @@ -159,17 +168,21 @@ func resourceLaceworkAlertChannelServiceNowRead(d *schema.ResourceData, meta int

func resourceLaceworkAlertChannelServiceNowUpdate(d *schema.ResourceData, meta interface{}) error {
var (
lacework = meta.(*api.Client)
serviceNow = api.NewServiceNowAlertChannel(d.Get("name").(string),
api.ServiceNowChannelData{
InstanceURL: d.Get("instance_url").(string),
Username: d.Get("username").(string),
Password: d.Get("password").(string),
IssueGrouping: d.Get("issue_grouping").(string),
},
)
lacework = meta.(*api.Client)
customTemplateJSON = d.Get("custom_template_file").(string)
snowData = api.ServiceNowChannelData{
InstanceURL: d.Get("instance_url").(string),
Username: d.Get("username").(string),
Password: d.Get("password").(string),
IssueGrouping: d.Get("issue_grouping").(string),
}
)

if len(customTemplateJSON) != 0 {
snowData.EncodeCustomTemplateFile(customTemplateJSON)
}

serviceNow := api.NewServiceNowAlertChannel(d.Get("name").(string), snowData)
if !d.Get("enabled").(bool) {
serviceNow.Enabled = 0
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions vendor/github.com/lacework/go-sdk/api/version.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ github.com/jstemmer/go-junit-report/formatter
github.com/jstemmer/go-junit-report/parser
# github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd
github.com/kevinburke/ssh_config
# github.com/lacework/go-sdk v0.2.20-0.20210219142651-0e9f6f57e16e
# github.com/lacework/go-sdk v0.2.21-0.20210224193400-129bc2861f7b
## explicit
github.com/lacework/go-sdk/api
github.com/lacework/go-sdk/internal/array
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/alert_channel_service_now.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ The following arguments are supported:
* `instance_url` - (Required) The ServiceNow instance URL.
* `username` - (Required) The ServiceNow user name.
* `password` - (Required) The ServiceNow password.
* `custom_template_file` - (Optional) Populate fields in the new ServiceNow incidents with values from a custom template JSON file.
* `custom_template_file` - (Optional) Populate fields in the ServiceNow incident with values from a custom template JSON file.
* `issue_grouping` - (Optional) Defines how Lacework compliance events get grouped. Must be one of `Events` or `Resources`. Defaults to `Events`.
* `enabled` - (Optional) The state of the external integration. Defaults to `true`.

Expand Down

0 comments on commit a315965

Please sign in to comment.