-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Migrate ServiceNow alert channel(v2) (#206)
- Loading branch information
1 parent
7cc2d5e
commit 09a413e
Showing
3 changed files
with
203 additions
and
116 deletions.
There are no files selected for viewing
64 changes: 58 additions & 6 deletions
64
examples/resource_lacework_alert_channel_service_now/main.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,66 @@ | ||
provider "lacework" {} | ||
terraform { | ||
required_providers { | ||
lacework = { | ||
source = "lacework/lacework" | ||
} | ||
} | ||
} | ||
|
||
resource "lacework_alert_channel_service_now" "example" { | ||
name = "Service Now Channel Alert Example" | ||
instance_url = "snow-lacework.com" | ||
username = "snow-user" | ||
password = "snow-pass" | ||
custom_template_file = <<TEMPLATE | ||
name = var.channel_name | ||
instance_url = var.instance_url | ||
username = var.username | ||
password = var.password | ||
custom_template_file = var.custom_template_file | ||
// test_integration input is used in this example only for testing | ||
// purposes, it help us avoid sending a "test" request to the | ||
// system we are integrating to. In production, this should remain | ||
// turned on ("true") which is the default setting | ||
test_integration = false | ||
} | ||
|
||
variable "channel_name" { | ||
type = string | ||
default = "Service Now Channel Alert Example" | ||
} | ||
|
||
variable "instance_url" { | ||
type = string | ||
default = "https://dev123.service-now.com" | ||
} | ||
|
||
variable "username" { | ||
type = string | ||
default = "snow-user" | ||
} | ||
|
||
variable "password" { | ||
type = string | ||
default = "snow-pass" | ||
} | ||
|
||
variable "custom_template_file" { | ||
type = string | ||
default = <<TEMPLATE | ||
{ | ||
"description" : "Generated by Lacework:", | ||
"approval" : "Approved" | ||
} | ||
TEMPLATE | ||
} | ||
|
||
output "channel_name" { | ||
value = lacework_alert_channel_service_now.example.name | ||
} | ||
|
||
output "instance_url" { | ||
value = lacework_alert_channel_service_now.example.instance_url | ||
} | ||
|
||
output "username" { | ||
value = lacework_alert_channel_service_now.example.username | ||
} | ||
|
||
output "custom_template_file" { | ||
value = lacework_alert_channel_service_now.example.custom_template_file | ||
} |
78 changes: 78 additions & 0 deletions
78
integration/resource_lacework_integration_service_now_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package integration | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/gruntwork-io/terratest/modules/terraform" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
// TestServiceNowRestAlertChannelCreate applies integration terraform '../examples/resource_lacework_alert_channel_service_now' | ||
// Uses the go-sdk to verify the created integration | ||
// Applies an update with new channel name and Terraform destroy | ||
func TestServiceNowRestAlertChannelCreate(t *testing.T) { | ||
terraformOptions := terraform.WithDefaultRetryableErrors(t, &terraform.Options{ | ||
TerraformDir: "../examples/resource_lacework_alert_channel_service_now", | ||
Vars: map[string]interface{}{ | ||
"channel_name": "Service Now Alert Channel Example", | ||
"instance_url": "https://dev123.service-now.com", | ||
"username": "snow-user", | ||
"password": "snow-pass", | ||
"custom_template_file": customTemplate, | ||
}, | ||
}) | ||
defer terraform.Destroy(t, terraformOptions) | ||
|
||
// Create new ServiceNowRest Alert Channel | ||
create := terraform.InitAndApplyAndIdempotent(t, terraformOptions) | ||
created := GetAlertChannelProps(create) | ||
if data, ok := created.Data.Data.(map[string]interface{}); ok { | ||
assert.True(t, ok) | ||
|
||
actualName := terraform.Output(t, terraformOptions, "channel_name") | ||
actualUrl := terraform.Output(t, terraformOptions, "instance_url") | ||
actualUsername := terraform.Output(t, terraformOptions, "username") | ||
actualTemplate := terraform.Output(t, terraformOptions, "custom_template_file") | ||
|
||
assert.Equal(t, "Service Now Alert Channel Example", created.Data.Name) | ||
assert.Equal(t, "https://dev123.service-now.com", data["instanceUrl"]) | ||
assert.Equal(t, templateEncoded, | ||
data["customTemplateFile"]) | ||
assert.Equal(t, "snow-user", data["userName"]) | ||
|
||
assert.Equal(t, "Service Now Alert Channel Example", actualName) | ||
assert.Equal(t, "https://dev123.service-now.com", actualUrl) | ||
assert.Equal(t, "snow-user", actualUsername) | ||
assert.Equal(t, customTemplate, actualTemplate) | ||
} | ||
// Update ServiceNowRest Alert Channel | ||
terraformOptions.Vars = map[string]interface{}{ | ||
"channel_name": "Service Now Alert Channel Updated", | ||
"instance_url": "https://dev321.service-now.com", | ||
"username": "snow-user-updated", | ||
} | ||
|
||
update := terraform.Apply(t, terraformOptions) | ||
updated := GetAlertChannelProps(update) | ||
if data, ok := updated.Data.Data.(map[string]interface{}); ok { | ||
assert.True(t, ok) | ||
|
||
actualName := terraform.Output(t, terraformOptions, "channel_name") | ||
actualUrl := terraform.Output(t, terraformOptions, "instance_url") | ||
actualUsername := terraform.Output(t, terraformOptions, "username") | ||
actualTemplate := terraform.Output(t, terraformOptions, "custom_template_file") | ||
|
||
assert.Equal(t, "Service Now Alert Channel Updated", updated.Data.Name) | ||
assert.Equal(t, "https://dev321.service-now.com", data["instanceUrl"]) | ||
assert.Equal(t, templateEncoded, data["customTemplateFile"]) | ||
assert.Equal(t, "snow-user-updated", data["userName"]) | ||
|
||
assert.Equal(t, "Service Now Alert Channel Updated", actualName) | ||
assert.Equal(t, "https://dev321.service-now.com", actualUrl) | ||
assert.Equal(t, "snow-user-updated", actualUsername) | ||
assert.Equal(t, customTemplate, actualTemplate) | ||
} | ||
} | ||
|
||
var customTemplate = " {\n \"description\" : \"Generated by Lacework:\",\n \"approval\" : \"Approved\"\n }\n" | ||
var templateEncoded = "data:application/json;name=i.json;base64,ICB7CiAgICAiZGVzY3JpcHRpb24iIDogIkdlbmVyYXRlZCBieSBMYWNld29yazoiLAogICAgImFwcHJvdmFsIiA6ICJBcHByb3ZlZCIKICB9Cg==" |
Oops, something went wrong.