-
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 AWS Cloudwatch alert channel to API v2 (#186)
* refactor: Add name to cloudwatch schema * refactor: Add missing files * refactor: fix schema and reformat code * refactor: fix tests and how environment variable is read * refactor: add missing dependency * refactor: Apply suggestions from code review * refactor: address pr feedback
- Loading branch information
Showing
11 changed files
with
180 additions
and
245 deletions.
There are no files selected for viewing
32 changes: 28 additions & 4 deletions
32
examples/resource_lacework_alert_channel_aws_cloudwatch/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,7 +1,31 @@ | ||
terraform { | ||
required_providers { | ||
lacework = { | ||
source = "lacework/lacework" | ||
} | ||
} | ||
} | ||
|
||
provider "lacework" {} | ||
|
||
resource "lacework_alert_channel_aws_cloudwatch" "example" { | ||
name = "My AWS CloudWatch Alert Channel Example" | ||
event_bus_arn = "arn:aws:events:us-west-2:1234567890:event-bus/default" | ||
group_issues_by = "Resources" | ||
variable "event_bus_arn" { | ||
description = "The ARN for the event bus" | ||
type = string | ||
sensitive = true | ||
} | ||
|
||
variable "name" { | ||
description = "The name of the alert channel" | ||
type = string | ||
} | ||
|
||
resource "lacework_alert_channel_aws_cloudwatch" "example" { | ||
name = var.name | ||
event_bus_arn = var.event_bus_arn | ||
group_issues_by = "Events" | ||
// 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 | ||
} |
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
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,9 @@ | ||
package integration | ||
|
||
import ( | ||
"os" | ||
) | ||
|
||
func cloudwatchEnvVarsDefault() string { | ||
return os.Getenv("CLOUDWATCH_EVENT_BUS_ARN") | ||
} |
38 changes: 38 additions & 0 deletions
38
integration/resource_lacework_alert_channel_aws_cloudwatch_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,38 @@ | ||
package integration | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/gruntwork-io/terratest/modules/terraform" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
// TestAlertChannelCloudWatchCreate applies integration terraform: | ||
// => '../examples/resource_lacework_alert_channel_aws_cloudwatch' | ||
// | ||
// It uses the go-sdk to verify the created integration, | ||
// applies an update with new alert channel name and destroys it | ||
func TestAlertChannelCloudWatchCreate(t *testing.T) { | ||
eventBusArn := cloudwatchEnvVarsDefault() | ||
terraformOptions := terraform.WithDefaultRetryableErrors(t, &terraform.Options{ | ||
TerraformDir: "../examples/resource_lacework_alert_channel_aws_cloudwatch", | ||
Vars: map[string]interface{}{ | ||
"name": "AWS Cloudwatch Alert Channel Example", | ||
}, | ||
EnvVars: map[string]string{ | ||
"TF_VAR_event_bus_arn": eventBusArn, | ||
}, | ||
}) | ||
defer terraform.Destroy(t, terraformOptions) | ||
|
||
// Create new CloudwatchEb Alert Channel | ||
create := terraform.InitAndApply(t, terraformOptions) | ||
assert.Equal(t, "AWS Cloudwatch Alert Channel Example", GetIntegrationName(create)) | ||
|
||
// Update CloudwatchEb Alert Channel | ||
terraformOptions.Vars = map[string]interface{}{ | ||
"name": "AWS Cloudwatch Alert Channel Updated"} | ||
|
||
update := terraform.Apply(t, terraformOptions) | ||
assert.Equal(t, "AWS Cloudwatch Alert Channel Updated", GetIntegrationName(update)) | ||
} |
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.