diff --git a/codebase-pipelines/eventbridge.tf b/codebase-pipelines/eventbridge.tf index 63f26a0c..757da703 100644 --- a/codebase-pipelines/eventbridge.tf +++ b/codebase-pipelines/eventbridge.tf @@ -8,7 +8,7 @@ resource "aws_cloudwatch_event_rule" "ecr_image_publish" { detail-type : ["ECR Image Action"], detail : { action-type : ["PUSH"], - image-tag : [coalesce(each.value.tag, false) ? "tag-latest" : "branch-${each.value.branch}"], + image-tag : [var.requires_image_build ? coalesce(each.value.tag, false) ? "tag-latest" : "branch-${each.value.branch}" : "latest"], repository-name : [local.ecr_name], result : ["SUCCESS"], } diff --git a/codebase-pipelines/tests/unit.tftest.hcl b/codebase-pipelines/tests/unit.tftest.hcl index a26815b7..f94ae0e3 100644 --- a/codebase-pipelines/tests/unit.tftest.hcl +++ b/codebase-pipelines/tests/unit.tftest.hcl @@ -321,6 +321,14 @@ run "test_codebuild_images_not_required" { condition = length(aws_codebuild_webhook.codebuild_webhook) == 0 error_message = "Should be: 0" } + assert { + condition = aws_cloudwatch_event_rule.ecr_image_publish[0].event_pattern == "{\"detail\":{\"action-type\":[\"PUSH\"],\"image-tag\":[\"latest\"],\"repository-name\":[\"my-app/my-codebase\"],\"result\":[\"SUCCESS\"]},\"detail-type\":[\"ECR Image Action\"],\"source\":[\"aws.ecr\"]}" + error_message = "Event pattern is incorrect ${jsonencode(aws_cloudwatch_event_rule.ecr_image_publish[0].event_pattern)}" + } + assert { + condition = aws_cloudwatch_event_rule.ecr_image_publish[1].event_pattern == "{\"detail\":{\"action-type\":[\"PUSH\"],\"image-tag\":[\"latest\"],\"repository-name\":[\"my-app/my-codebase\"],\"result\":[\"SUCCESS\"]},\"detail-type\":[\"ECR Image Action\"],\"source\":[\"aws.ecr\"]}" + error_message = "Event pattern is incorrect" + } } run "test_main_branch_filter" {