-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathecs-role.tf
65 lines (55 loc) · 1.66 KB
/
ecs-role.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
# create iam policy document. this policy allows the ecs service to assume a role
data "aws_iam_policy_document" "assume_role_policy" {
statement {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["ecs-tasks.amazonaws.com"]
}
}
}
# create iam policy document
data "aws_iam_policy_document" "ecs_task_execution_policy_document" {
statement {
actions = [
"ecr:GetAuthorizationToken",
"ecr:BatchCheckLayerAvailability",
"ecr:GetDownloadUrlForLayer",
"ecr:BatchGetImage",
"logs:CreateLogStream",
"logs:PutLogEvents"
]
resources = ["*"]
}
statement {
actions = [
"s3:GetObject"
]
resources = [
"arn:aws:s3:::${var.project_name}-${var.env_file_bucket_name}/*"
]
}
statement {
actions = [
"s3:GetBucketLocation"
]
resources = [
"arn:aws:s3:::${var.project_name}-${var.env_file_bucket_name}"
]
}
}
# create iam policy
resource "aws_iam_policy" "ecs_task_execution_policy" {
name = "${var.project_name}-${var.environment}-ecs-task-execution-role-policy"
policy = data.aws_iam_policy_document.ecs_task_execution_policy_document.json
}
# create an iam role
resource "aws_iam_role" "ecs_task_execution_role" {
name = "${var.project_name}-${var.environment}-ecs-task-execution-role"
assume_role_policy = data.aws_iam_policy_document.assume_role_policy.json
}
# attach ecs task execution policy to the iam role
resource "aws_iam_role_policy_attachment" "ecs_task_execution_role" {
role = aws_iam_role.ecs_task_execution_role.name
policy_arn = aws_iam_policy.ecs_task_execution_policy.arn
}