-
Notifications
You must be signed in to change notification settings - Fork 6
/
data.tf
154 lines (135 loc) · 3.47 KB
/
data.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#This solution, non-production-ready template describes AWS Codepipeline based CICD Pipeline for terraform code deployment.
#© 2024 Amazon Web Services, Inc. or its affiliates. All Rights Reserved.
#This AWS Content is provided subject to the terms of the AWS Customer Agreement available at
#http://aws.amazon.com/agreement or other written agreement between Customer and either
#Amazon Web Services, Inc. or Amazon Web Services EMEA SARL or both.
data "aws_caller_identity" "current" {}
data "aws_region" "current" {}
data "aws_iam_policy_document" "ecs-assume-role-policy" {
statement {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["ecs-tasks.amazonaws.com"]
}
}
}
data "aws_iam_policy_document" "ecs_task_role_policy" {
statement {
effect = "Allow"
actions = ["ecr:GetAuthorizationToken"]
resources = ["*"]
}
statement {
actions = [
"ecr:BatchCheckLayerAvailability",
"ecr:GetDownloadUrlForLayer",
"ecr:BatchGetImage",
]
resources = [module.ecr.arn]
}
statement {
actions = [
"logs:CreateLogStream",
"logs:PutLogEvents"
]
resources = [
"${aws_cloudwatch_log_group.ecs_log_group.arn}:log-stream:*/*/*"
]
}
statement {
actions = [
"secretsmanager:GetSecretValue"
]
resources = [aws_secretsmanager_secret.ecs_ado_pat.arn]
}
}
# Lambda roles and policies
data "aws_iam_policy_document" "lambda-assume-role-policy" {
statement {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["lambda.amazonaws.com"]
}
}
}
data "aws_iam_policy_document" "lambda_create_task_role_policy" {
statement {
actions = [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
]
resources = ["arn:aws:logs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:*"]
}
statement {
actions = [
"ec2:Describe*"
]
resources = ["*"]
}
statement {
actions = [
"ecs:RunTask"
]
resources = [module.ecs.ecs_task_def_arn]
}
statement {
actions = [
"iam:PassRole"
]
resources = [
"${module.iam_ecs_task_exec_role.aws_iam_role_arn}",
"${module.iam_ecs_task_role.aws_iam_role_arn}"
]
}
statement {
actions = [
"lambda:InvokeFunction"
]
resources = [
"${module.get_task_lambda.lambda_function_arn}",
]
}
}
data "aws_iam_policy_document" "lambda_get_task_role_policy" {
statement {
actions = [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"logs:GetLogEvents",
"logs:FilterLogEvents"
]
resources = ["arn:aws:logs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:*"]
}
statement {
actions = [
"ec2:Describe*"
]
resources = ["*"]
}
statement {
actions = [
"ecs:GetTask"
]
resources = [module.ecs.ecs_task_def_arn]
}
#arn:aws:ecs:eu-west-1:443307475174:task/ecs-ado-ecs-cluster-dev/
statement {
actions = [
"ecs:DescribeTasks"
]
resources = ["arn:aws:ecs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:task/${local.prefix}-ecs-cluster-${var.environment}/*"]
}
statement {
actions = [
"iam:PassRole"
]
resources = [
"${module.iam_ecs_task_exec_role.aws_iam_role_arn}",
"${module.iam_ecs_task_role.aws_iam_role_arn}"
]
}
}