-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathiam.tf
86 lines (68 loc) · 1.98 KB
/
iam.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
data "aws_iam_policy_document" "task_assume" {
statement {
effect = "Allow"
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["ecs-tasks.amazonaws.com"]
}
}
}
data "aws_iam_policy_document" "task_permissions" {
statement {
effect = "Allow"
resources = [
aws_cloudwatch_log_group.airflow.arn,
]
actions = [
"logs:CreateLogStream",
"logs:PutLogEvents",
]
}
statement {
effect = "Allow"
resources = [
"arn:aws:s3:::*"
]
actions = ["s3:ListBucket", "s3:ListAllMyBuckets"]
}
statement {
effect = "Allow"
resources = ["arn:aws:s3:::${local.s3_bucket_name}", "arn:aws:s3:::${local.s3_bucket_name}/*"]
actions = ["s3:ListBucket", "s3:GetObject"]
}
}
data "aws_iam_policy_document" "task_execution_permissions" {
statement {
effect = "Allow"
resources = [
"*",
]
actions = [
"logs:CreateLogStream",
"logs:PutLogEvents",
]
}
}
# role for ecs to create the instance
resource "aws_iam_role" "execution" {
name = "${var.resource_prefix}-airflow-task-execution-role-${var.resource_suffix}"
assume_role_policy = data.aws_iam_policy_document.task_assume.json
tags = local.common_tags
}
# role for the airflow instance itself
resource "aws_iam_role" "task" {
name = "${var.resource_prefix}-airflow-task-role-${var.resource_suffix}"
assume_role_policy = data.aws_iam_policy_document.task_assume.json
tags = local.common_tags
}
resource "aws_iam_role_policy" "task_execution" {
name = "${var.resource_prefix}-airflow-task-execution-${var.resource_suffix}"
role = aws_iam_role.execution.id
policy = data.aws_iam_policy_document.task_execution_permissions.json
}
resource "aws_iam_role_policy" "log_agent" {
name = "${var.resource_prefix}-airflow-log-permissions-${var.resource_suffix}"
role = aws_iam_role.task.id
policy = data.aws_iam_policy_document.task_permissions.json
}