-
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 Cisco webex alert channel to API v2 (#193)
***Issue***: https://lacework.atlassian.net/browse/ALLY-638?atlOrigin=eyJpIjoiZWQwNzA2NTc0OTc5NGEwMWIzNDYwMzNkYWNhZmQ4MTUiLCJwIjoiaiJ9 ***Description:*** Migrate the cisco webex alert channel to use API v2 ***Additional Info:*** #147
- Loading branch information
Showing
10 changed files
with
197 additions
and
241 deletions.
There are no files selected for viewing
37 changes: 35 additions & 2 deletions
37
examples/resource_lacework_alert_channel_cisco_webex/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,6 +1,39 @@ | ||
terraform { | ||
required_providers { | ||
lacework = { | ||
source = "lacework/lacework" | ||
} | ||
} | ||
} | ||
|
||
provider "lacework" {} | ||
|
||
variable "channel_name" { | ||
type = string | ||
default = "My Cisco Webex Channel Alert Example" | ||
} | ||
|
||
variable "webhook_url" { | ||
type = string | ||
sensitive = true | ||
} | ||
|
||
|
||
resource "lacework_alert_channel_cisco_webex" "example" { | ||
name = "My Cisco Webex Channel Alert Example" | ||
webhook_url = "https://webexapis.com/v1/webhooks/incoming/api-token" | ||
name = var.channel_name | ||
webhook_url = var.webhook_url | ||
// 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 | ||
} | ||
|
||
output "channel_name" { | ||
value = var.channel_name | ||
} | ||
|
||
output "webhook_url" { | ||
value = var.webhook_url | ||
sensitive = true | ||
} |
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
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
50 changes: 50 additions & 0 deletions
50
integration/resource_lacework_alert_channel_cisco_webex_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,50 @@ | ||
package integration | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/gruntwork-io/terratest/modules/terraform" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
// TestAlertChannelCiscoWebexCreate applies integration terraform: | ||
// => '../examples/resource_lacework_alert_channel_cisco_webex' | ||
// | ||
// It uses the go-sdk to verify the created integration, | ||
// applies an update with new alert channel name and destroys it | ||
func TestAlertChannelCiscoWebexCreate(t *testing.T) { | ||
terraformOptions := terraform.WithDefaultRetryableErrors(t, &terraform.Options{ | ||
TerraformDir: "../examples/resource_lacework_alert_channel_cisco_webex", | ||
Vars: map[string]interface{}{ | ||
"channel_name": "Cisco Webex Alert Channel Example", | ||
"webhook_url": "https://webexapis.com/v1/webhooks/incoming/api-token", | ||
}, | ||
}) | ||
defer terraform.Destroy(t, terraformOptions) | ||
|
||
// Create new Cisco webex Alert Channel | ||
create := terraform.InitAndApplyAndIdempotent(t, terraformOptions) | ||
assert.Equal(t, "Cisco Webex Alert Channel Example", GetIntegrationName(create)) | ||
|
||
// Update Cisco Alert Channel | ||
terraformOptions.Vars = map[string]interface{}{ | ||
"channel_name": "Cisco Webex Alert Channel Example Updated", | ||
"webhook_url": "https://webexapis.com/v1/webhooks/incoming/api-token", | ||
} | ||
|
||
update := terraform.Apply(t, terraformOptions) | ||
|
||
// Verify that the lacework integration was created with the correct information | ||
updateProps := GetAlertChannelProps(update) | ||
if data, ok := updateProps.Data.Data.(map[string]interface{}); ok { | ||
assert.True(t, ok) | ||
assert.Equal(t, "Cisco Webex Alert Channel Example Updated", updateProps.Data.Name) | ||
assert.Equal(t, "https://webexapis.com/v1/webhooks/incoming/api-token", data["webhook"]) | ||
} | ||
|
||
// Verify that the terraform resource has the correct information as expected | ||
actualChannelName := terraform.Output(t, terraformOptions, "channel_name") | ||
actualWebhookUrl := terraform.Output(t, terraformOptions, "webhook_url") | ||
assert.Equal(t, "Cisco Webex Alert Channel Example Updated", actualChannelName) | ||
assert.Equal(t, "https://webexapis.com/v1/webhooks/incoming/api-token", actualWebhookUrl) | ||
} |
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
Oops, something went wrong.