Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix s3 alert channel integration test #224

Merged
merged 4 commits into from
Nov 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions examples/resource_lacework_alert_channel_aws_s3/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,26 @@ variable "channel_name" {
default = "AwsS3 Alert Channel Example"
}

variable "bucket_arn" {
type = string
sensitive = true
}

variable "external_id" {
type = string
sensitive = true
}

variable "role_arn" {
type = string
}

resource "lacework_alert_channel_aws_s3" "example" {
name = var.channel_name
bucket_arn = "arn:aws:s3:::bucket_name/key_name"
bucket_arn = var.bucket_arn
credentials {
external_id = "12345"
role_arn = "arn:aws:iam::1234567890:role/lacework_iam_example_role"
external_id = var.external_id
role_arn = var.role_arn
}

// test_integration input is used in this example only for testing
Expand Down
45 changes: 31 additions & 14 deletions integration/resource_lacework_alert_channel_aws_s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,38 @@ import (
//
// It uses the go-sdk to verify the created integration,
// applies an update with new alert channel name and destroys it
//nolint
func _TestAlertChannelAwsS3Create(t *testing.T) {
terraformOptions := terraform.WithDefaultRetryableErrors(t, &terraform.Options{
TerraformDir: "../examples/resource_lacework_alert_channel_aws_s3",
})
defer terraform.Destroy(t, terraformOptions)
func TestAlertChannelAwsS3Create(t *testing.T) {
awsCreds, err := s3LoadCredentials("AWS_S3")
s3BucketArn := s3LoadBucketArn()
if assert.Nil(t, err, "this test requires you to set AWS_S3 environment variable") {
terraformOptions := terraform.WithDefaultRetryableErrors(t, &terraform.Options{
TerraformDir: "../examples/resource_lacework_alert_channel_aws_s3",
Vars: map[string]interface{}{
"role_arn": awsCreds.RoleArn,
"external_id": awsCreds.ExternalID,
},
EnvVars: map[string]string{
"TF_VAR_bucket_arn": s3BucketArn,
},
})
defer terraform.Destroy(t, terraformOptions)

// Create new AwsS3 Alert Channel
create := terraform.InitAndApply(t, terraformOptions)
assert.Equal(t, "AwsS3 Alert Channel Example", GetIntegrationName(create))
// Create new AwsS3 Alert Channel
create := terraform.InitAndApplyAndIdempotent(t, terraformOptions)
assert.Equal(t, "AwsS3 Alert Channel Example", GetIntegrationName(create))

// Update AwsS3 Alert Channel
terraformOptions.Vars = map[string]interface{}{
"channel_name": "AwsS3 Alert Channel Updated"}
// Update AwsS3 Alert Channel
terraformOptions.Vars = map[string]interface{}{
"channel_name": "AwsS3 Alert Channel Updated",
"role_arn": awsCreds.RoleArn,
"external_id": awsCreds.ExternalID,
}

update := terraform.Apply(t, terraformOptions)
assert.Equal(t, "AwsS3 Alert Channel Updated", GetIntegrationName(update))
terraformOptions.EnvVars = map[string]string{
"TF_VAR_bucket_arn": s3BucketArn,
}

update := terraform.ApplyAndIdempotent(t, terraformOptions)
assert.Equal(t, "AwsS3 Alert Channel Updated", GetIntegrationName(update))
}
}
20 changes: 20 additions & 0 deletions integration/s3_alert_channel_env_vars.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package integration

import (
"encoding/json"
"os"
)

type s3CredentialsFile struct {
RoleArn string `json:"role_arn"`
ExternalID string `json:"external_id"`
}

func s3LoadBucketArn() string {
return os.Getenv("S3_BUCKET_ARN")
}

func s3LoadCredentials(envVar string) (s s3CredentialsFile, err error) {
err = json.Unmarshal([]byte(os.Getenv(envVar)), &s)
return
}