-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiam.tf
More file actions
98 lines (81 loc) · 2.12 KB
/
iam.tf
File metadata and controls
98 lines (81 loc) · 2.12 KB
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
# Allow list/read of any bucket
# Allow full access only to result bucket
resource "aws_iam_policy" "ecs_s3_access" {
name = "ecs_s3_policy"
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:Get*",
"S3:List*"
],
"Resource": ["*"]
},
{
"Effect": "Allow",
"Action": [
"s3:*"
],
"Resource": [
"${aws_s3_bucket.results.arn}",
"${aws_s3_bucket.results.arn}/*"
]
}
]
}
EOF
}
resource "aws_iam_role" "ecs_instance" {
name = "${local.common_tags.Name}-ecs-instance-role"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": "ec2.amazonaws.com"
}
}
]
}
EOF
}
resource "aws_iam_role_policy_attachment" "ecs_for_ec2" {
role = aws_iam_role.ecs_instance.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role"
}
resource "aws_iam_role_policy_attachment" "ecs_s3_access" {
role = aws_iam_role.ecs_instance.name
policy_arn = aws_iam_policy.ecs_s3_access.arn
}
resource "aws_iam_instance_profile" "ecs_instance" {
name = "${local.common_tags.Name}-ecs-instance-role"
role = aws_iam_role.ecs_instance.name
}
#####################################################################################################
resource "aws_iam_role" "aws_batch_service" {
name = "${local.common_tags.Name}-batch-service-role"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": "batch.amazonaws.com"
}
}
]
}
EOF
}
resource "aws_iam_role_policy_attachment" "batch_service" {
role = aws_iam_role.aws_batch_service.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSBatchServiceRole"
}