Skip to content

Commit

Permalink
Merge pull request #32 from toluna-terraform/eventbridge-trigger
Browse files Browse the repository at this point in the history
fix pipeline trigger
  • Loading branch information
Eli-Meitner authored Jun 7, 2023
2 parents 68244a6 + f830c42 commit 9538329
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
13 changes: 7 additions & 6 deletions modules/ci-cd-codepipeline/data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ data "aws_iam_policy_document" "codepipeline_assume_role_policy" {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["codepipeline.amazonaws.com", "codedeploy.amazonaws.com" ]
identifiers = ["codepipeline.amazonaws.com", "codedeploy.amazonaws.com" , "events.amazonaws.com"]
}
}
}
Expand All @@ -31,6 +31,12 @@ data "aws_iam_policy_document" "codepipeline_role_policy" {
]
resources = ["*"]
}
statement {
actions = [
"codepipeline:StartPipelineExecution"
]
resources = ["*"]
}
statement {
actions = ["codestar-connections:UseConnection"]
resources = ["*"]
Expand All @@ -46,11 +52,6 @@ data "aws_iam_policy_document" "codepipeline_role_policy" {
statement {
actions = [
"codedeploy:*"
# "codedeploy:CreateDeployment",
# "codedeploy:GetApplicationRevision",
# "codedeploy:GetDeployment",
# "codedeploy:GetDeploymentConfig",
# "codedeploy:RegisterApplicationRevision"
]
resources = ["*"]
}
Expand Down
27 changes: 26 additions & 1 deletion modules/ci-cd-codepipeline/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ resource "aws_codepipeline" "codepipeline" {
configuration = {
S3Bucket = "${var.s3_bucket}"
S3ObjectKey = "${var.env_name}/source_artifacts.zip"
PollForSourceChanges = true
PollForSourceChanges = false
}
}
}
Expand Down Expand Up @@ -132,3 +132,28 @@ resource "aws_iam_role_policy" "codepipeline_policy" {
role = aws_iam_role.codepipeline_role.id
policy = data.aws_iam_policy_document.codepipeline_role_policy.json
}

resource "aws_cloudwatch_event_rule" "trigger_pipeline" {
name = "${local.codepipeline_name}-trigger"
description = "Trigger ${local.codepipeline_name}"

event_pattern = jsonencode({
"source" : ["aws.s3"],
"detail-type" : ["AWS API Call via CloudTrail"],
"detail" : {
"eventSource" : ["s3.amazonaws.com"],
"eventName" : ["PutObject", "CompleteMultipartUpload", "CopyObject"],
"requestParameters" : {
"bucketName" : ["${var.s3_bucket}"],
"key" : ["${var.env_name}/source_artifacts.zip"]
}
}
})
}

resource "aws_cloudwatch_event_target" "trigger_pipeline" {
rule = aws_cloudwatch_event_rule.trigger_pipeline.name
target_id = "${local.codepipeline_name}"
arn = aws_codepipeline.codepipeline.arn
role_arn = aws_iam_role.codepipeline_role.arn
}

0 comments on commit 9538329

Please sign in to comment.