forked from moritzzimmer/terraform-aws-lambda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trigger_ecr.tf
41 lines (37 loc) · 1003 Bytes
/
trigger_ecr.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
resource "aws_cloudwatch_event_rule" "this" {
count = var.ecr_repository_name != "" ? 1 : 0
name = "${var.function_name}-ecr-trigger"
description = "Amazon CloudWatch Events rule to automatically start the pipeline when a change occurs in the Elastic Container Registry."
tags = var.tags
event_pattern = <<PATTERN
{
"detail-type": [
"ECR Image Action"
],
"source": [
"aws.ecr"
],
"detail": {
"action-type": [
"PUSH"
],
"image-tag": [
"${var.ecr_image_tag}"
],
"repository-name": [
"${var.ecr_repository_name}"
],
"result": [
"SUCCESS"
]
}
}
PATTERN
}
resource "aws_cloudwatch_event_target" "trigger" {
count = var.ecr_repository_name != "" ? 1 : 0
arn = aws_codepipeline.this.arn
role_arn = aws_iam_role.trigger.arn
rule = aws_cloudwatch_event_rule.this[count.index].name
target_id = "CodePipeline"
}