-
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.
feat(resource): New lacework_report_rule (#237)
- Loading branch information
1 parent
c92b8da
commit c2928b6
Showing
43 changed files
with
2,147 additions
and
143 deletions.
There are no files selected for viewing
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,122 @@ | ||
terraform { | ||
required_providers { | ||
lacework = { | ||
source = "lacework/lacework" | ||
} | ||
} | ||
} | ||
|
||
resource "lacework_alert_channel_email" "email_alerts" { | ||
name = "Used for Report Rules Testing" | ||
recipients = ["foo@example.com"] | ||
|
||
// 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 | ||
} | ||
|
||
resource "lacework_resource_group_aws" "aws_group" { | ||
name = var.resource_group_name | ||
accounts = ["*"] | ||
} | ||
|
||
resource "lacework_report_rule" "example" { | ||
name = var.name | ||
description = var.description | ||
enabled = true | ||
severities = var.severities | ||
resource_groups = [lacework_resource_group_aws.aws_group.id] | ||
email_alert_channels = [lacework_alert_channel_email.email_alerts.id] | ||
|
||
aws_compliance_reports { | ||
pci = var.aws_pci | ||
cis_s3 = true | ||
} | ||
|
||
gcp_compliance_reports { | ||
pci = var.gcp_pci | ||
cis = true | ||
} | ||
|
||
daily_compliance_reports { | ||
aws_cloudtrail = var.daily_cloudtrail | ||
} | ||
|
||
weekly_snapshot = var.snapshot | ||
} | ||
|
||
variable "name" { | ||
type = string | ||
default = "Terraform Report Rule" | ||
} | ||
|
||
variable "description" { | ||
type = string | ||
default = "Report Rule created by Terraform" | ||
} | ||
|
||
variable "severities" { | ||
type = list(string) | ||
default = ["High", "Medium"] | ||
} | ||
|
||
variable "resource_groups" { | ||
type = list(string) | ||
default = ["TECHALLY_8416B4ADCED28565254842AA5906B729174653E1725F107"] | ||
} | ||
|
||
variable "channels" { | ||
type = list(string) | ||
default = ["TECHALLY_2F0C086E17AB64BEC84F4A5FF8A3F068CF2CE15847BCBCA"] | ||
} | ||
|
||
variable "aws_pci" { | ||
type = bool | ||
default = true | ||
} | ||
|
||
variable "gcp_pci" { | ||
type = bool | ||
default = true | ||
} | ||
|
||
variable "daily_cloudtrail" { | ||
type = bool | ||
default = true | ||
} | ||
|
||
variable "snapshot" { | ||
type = bool | ||
default = true | ||
} | ||
|
||
variable "resource_group_name" { | ||
type = string | ||
default = "Used for Report Rules Testing" | ||
} | ||
|
||
output "name" { | ||
value = lacework_report_rule.example.name | ||
} | ||
|
||
output "description" { | ||
value = lacework_report_rule.example.description | ||
} | ||
|
||
output "severities" { | ||
value = lacework_report_rule.example.severities | ||
} | ||
|
||
output "resource_groups" { | ||
value = lacework_report_rule.example.resource_groups | ||
} | ||
|
||
output "channels" { | ||
value = lacework_report_rule.example.email_alert_channels | ||
} | ||
|
||
output "aws_pci" { | ||
value = lacework_report_rule.example.aws_compliance_reports.0.pci | ||
} |
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
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,77 @@ | ||
package integration | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
"time" | ||
|
||
"github.com/lacework/go-sdk/api" | ||
|
||
"github.com/gruntwork-io/terratest/modules/terraform" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
// TestReportRuleCreate applies integration terraform: | ||
// => '../examples/resource_lacework_report_rule' | ||
// | ||
// It uses the go-sdk to verify the created report rule, | ||
// applies an update and destroys it | ||
func TestReportRuleCreate(t *testing.T) { | ||
name := fmt.Sprintf("Report Rule - %s", time.Now()) | ||
resourceGroupName := fmt.Sprintf("Used for Report Rule Test - %s", time.Now()) | ||
terraformOptions := terraform.WithDefaultRetryableErrors(t, &terraform.Options{ | ||
TerraformDir: "../examples/resource_lacework_report_rule", | ||
Vars: map[string]interface{}{ | ||
"name": name, | ||
"description": "Report Rule created by Terraform", | ||
"severities": []string{"Critical"}, | ||
"aws_pci": true, | ||
"resource_group_name": resourceGroupName, | ||
}, | ||
}) | ||
defer terraform.Destroy(t, terraformOptions) | ||
|
||
// Create new Report Rule | ||
terraformOptions.TimeBetweenRetries = 2 * time.Second | ||
create := terraform.InitAndApplyAndIdempotent(t, terraformOptions) | ||
createProps := GetReportRuleProps(create) | ||
|
||
actualDescription := terraform.Output(t, terraformOptions, "description") | ||
actualChannels := terraform.Output(t, terraformOptions, "channels") | ||
actualSeverities := terraform.Output(t, terraformOptions, "severities") | ||
actualAwsNotifications := terraform.Output(t, terraformOptions, "aws_pci") | ||
|
||
assert.Equal(t, "Report Rule created by Terraform", createProps.Data.Filter.Description) | ||
assert.Equal(t, []string{"Critical"}, api.NewReportRuleSeveritiesFromIntSlice(createProps.Data.Filter.Severity).ToStringSlice()) | ||
assert.Equal(t, actualAwsNotifications, "true") | ||
assert.True(t, createProps.Data.ReportNotificationTypes.AwsPci) | ||
assert.Equal(t, "Report Rule created by Terraform", actualDescription) | ||
assert.Equal(t, string("[Critical]"), actualSeverities) | ||
assert.NotEmpty(t, actualChannels) | ||
assert.NotEmpty(t, createProps.Data.EmailAlertChannels) | ||
|
||
// Update Report Rule | ||
terraformOptions.Vars = map[string]interface{}{ | ||
"name": name, | ||
"description": "Updated Report Rule created by Terraform", | ||
"severities": []string{"High", "Medium"}, | ||
"aws_pci": false, | ||
"resource_group_name": resourceGroupName, | ||
} | ||
|
||
update := terraform.ApplyAndIdempotent(t, terraformOptions) | ||
updateProps := GetReportRuleProps(update) | ||
actualDescription = terraform.Output(t, terraformOptions, "description") | ||
actualChannels = terraform.Output(t, terraformOptions, "channels") | ||
actualSeverities = terraform.Output(t, terraformOptions, "severities") | ||
actualAwsNotifications = terraform.Output(t, terraformOptions, "aws_pci") | ||
|
||
assert.Equal(t, "Updated Report Rule created by Terraform", updateProps.Data.Filter.Description) | ||
assert.Equal(t, []string{"High", "Medium"}, api.NewReportRuleSeveritiesFromIntSlice(updateProps.Data.Filter.Severity).ToStringSlice()) | ||
assert.Equal(t, "Updated Report Rule created by Terraform", actualDescription) | ||
assert.Equal(t, "[High Medium]", actualSeverities) | ||
assert.Equal(t, actualAwsNotifications, "false") | ||
assert.False(t, updateProps.Data.ReportNotificationTypes.AwsPci) | ||
assert.NotEmpty(t, actualChannels) | ||
assert.NotEmpty(t, updateProps.Data.EmailAlertChannels) | ||
} |
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.