-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiam.tf
57 lines (51 loc) · 1.67 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
# EC2 Role for ECS
data "aws_iam_policy_document" "tflearning-ec2-iam-policy-document" {
statement {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["ec2.amazonaws.com"]
}
}
}
resource "aws_iam_role" "tflearning-ec2-iam-role" {
name = "tflearning-ec2-iam-role"
path = "/"
assume_role_policy = data.aws_iam_policy_document.tflearning-ec2-iam-policy-document.json
tags = {
name = "tflearning"
env = "development"
createdBy = "sky"
}
}
resource "aws_iam_instance_profile" "tflearning-iam-instance-profile" {
role = aws_iam_role.tflearning-ec2-iam-role.name
tags = {
name = "tflearning"
env = "development"
createdBy = "sky"
}
}
resource "aws_iam_role_policy_attachment" "tflearning-ec2-iam-role-policy-attachment" {
role = aws_iam_role.tflearning-ec2-iam-role.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role"
}
# ECS Task Role
data "aws_iam_policy_document" "tflearning-ecs-iam-policy-document" {
statement {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["ecs-tasks.amazonaws.com"]
}
}
}
resource "aws_iam_role" "tflearning-ecs-iam-role" {
name = "tflearning-ecs-iam-role"
path = "/"
assume_role_policy = data.aws_iam_policy_document.tflearning-ecs-iam-policy-document.json
}
resource "aws_iam_role_policy_attachment" "tflearning-ecs-iam-role-policy-attachment" {
role = aws_iam_role.tflearning-ecs-iam-role.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy"
}