forked from outerbounds/terraform-aws-metaflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iam-ecs-execution.tf
55 lines (47 loc) · 1.54 KB
/
iam-ecs-execution.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
data "aws_iam_policy_document" "ecs_execution_role_assume_role" {
statement {
actions = [
"sts:AssumeRole"
]
effect = "Allow"
principals {
identifiers = [
"ec2.amazonaws.com",
"ecs.amazonaws.com",
"ecs-tasks.amazonaws.com",
"batch.amazonaws.com"
]
type = "Service"
}
}
}
resource "aws_iam_role" "ecs_execution_role" {
name = local.ecs_execution_role_name
# Read more about ECS' `task_role` and `execution_role` here https://stackoverflow.com/a/49947471
description = "This role is passed to our AWS ECS' task definition as the `execution_role`. This allows things like the correct image to be pulled and logs to be stored."
assume_role_policy = data.aws_iam_policy_document.ecs_execution_role_assume_role.json
tags = var.standard_tags
}
data "aws_iam_policy_document" "ecs_task_execution_policy" {
statement {
effect = "Allow"
actions = [
"ecr:GetAuthorizationToken",
"ecr:BatchCheckLayerAvailability",
"ecr:GetDownloadUrlForLayer",
"ecr:BatchGetImage",
"logs:CreateLogStream",
"logs:PutLogEvents"
]
# The `"Resource": "*"` is not a concern and the policy that Amazon suggests using
# https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_execution_IAM_role.html
resources = [
"*"
]
}
}
resource "aws_iam_role_policy" "grant_ecs_access" {
name = "ecs_access"
role = aws_iam_role.ecs_execution_role.name
policy = data.aws_iam_policy_document.ecs_task_execution_policy.json
}