Skip to content

Commit

Permalink
harmonise creation of notifications for replication bucket, add outpu…
Browse files Browse the repository at this point in the history
…ts and test to confirm notifications resource creates successfully
  • Loading branch information
dms1981 committed Oct 13, 2023
1 parent 0512c77 commit eba17af
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ data "aws_iam_policy_document" "default" {
}

resource "aws_s3_bucket_notification" "bucket_notification_replication" {
count = var.replication_enabled && var.notification_events != [""] ? 1 : 0
count = var.replication_enabled && var.notification_enabled ? 1 : 0
bucket = aws_s3_bucket.replication[count.index]

topic {
Expand Down
4 changes: 4 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ output "bucket_server_side_encryption" {
value = aws_s3_bucket_server_side_encryption_configuration.default
description = "Bucket server-side encryption configuration"
}

output "bucket_notifications" {
value = [for i in aws_s3_bucket_notification.bucket_notification : i]
}
8 changes: 3 additions & 5 deletions test/s3_bucket_creation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ func TestS3Creation(t *testing.T) {
expectedStatus := "Enabled"
assert.Equal(t, expectedStatus, actualStatus)

// Verify bucket notification is created
//bucketNotification := terraform.Output(t, terraformOptions, "bucket_notification")
//if bucketNotification != "" {
// fmt.Println("OK")
//} else {fmt.Println("NOOOO")}
// Verify that a bucket notification outputs a bucket name
bucketNotification := terraform.Output(t, terraformOptions, "bucket_notifications")
assert.Regexp(t, regexp.MustCompile(`unit-test-bucket*`), bucketNotification)
}
8 changes: 4 additions & 4 deletions test/unit-test/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ module "s3_with_notification" {
providers = {
aws.bucket-replication = aws
}
bucket_prefix = "unit-test-bucket"
force_destroy = true
bucket_prefix = "unit-test-bucket"
force_destroy = true
notification_enabled = true
notification_events = ["s3:ObjectCreated:*"]
notification_events = ["s3:ObjectCreated:*"]
notification_sns_arn = aws_sns_topic.topic.arn
tags = local.tags
tags = local.tags
}
5 changes: 5 additions & 0 deletions test/unit-test/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,8 @@ output "bucket_aes256" {
value = element(module.s3_with_AES256.bucket_server_side_encryption.rule[*].apply_server_side_encryption_by_default[0].sse_algorithm, 0)
description = "SSE Algorithm"
}

output "bucket_notifications" {
value = element(module.s3_with_notification.bucket_notifications, 0).bucket
description = "Retrieve name of bucket with notifications enabled"
}

0 comments on commit eba17af

Please sign in to comment.