-
-
Notifications
You must be signed in to change notification settings - Fork 40
/
eventbridge.tf
53 lines (46 loc) · 2.28 KB
/
eventbridge.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
42
43
44
45
46
47
48
49
50
51
52
53
////////////////////////////////////////////////////////[ EVENTBRIDGE RULES ]/////////////////////////////////////////////
# # ---------------------------------------------------------------------------------------------------------------------#
# Create EventBridge service role
# # ---------------------------------------------------------------------------------------------------------------------#
data "aws_iam_policy_document" "eventbridge_assume_role" {
statement {
effect = "Allow"
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["events.amazonaws.com"]
}
}
}
resource "aws_iam_role" "eventbridge_service_role" {
name = "${local.project}-EventBridgeServiceRole"
description = "Provides EventBridge manage events on your behalf."
assume_role_policy = data.aws_iam_policy_document.eventbridge_assume_role.json
}
# # ---------------------------------------------------------------------------------------------------------------------#
# Create policy for EventBridge role to start CodePipeline
# # ---------------------------------------------------------------------------------------------------------------------#
data "aws_iam_policy_document" "eventbridge_start_pipeline" {
statement {
sid = "eventspolicy"
actions = ["codepipeline:StartPipelineExecution"]
resources = ["${aws_codepipeline.this.arn}"]
}
}
resource "aws_iam_policy" "eventbridge_start_pipeline" {
name = "${local.project}-eventbridge-start-pipeline"
description = "EventBridge can start pipeline"
policy = data.aws_iam_policy_document.eventbridge_start_pipeline.json
}
# # ---------------------------------------------------------------------------------------------------------------------#
# Attach policies to EventBridge role
# # ---------------------------------------------------------------------------------------------------------------------#
resource "aws_iam_role_policy_attachment" "eventbridge_policy" {
for_each = var.eventbridge_policy
role = aws_iam_role.eventbridge_service_role.name
policy_arn = each.value
}
resource "aws_iam_role_policy_attachment" "eventbridge_start_pipeline" {
role = aws_iam_role.eventbridge_service_role.name
policy_arn = aws_iam_policy.eventbridge_start_pipeline.arn
}