-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathiam_role.tf
119 lines (107 loc) · 2.79 KB
/
iam_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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
################################
# IAM Role Bastion
################################
# ec2-bastion
resource "aws_iam_role" "ec2-bastion" {
name = "ec2-bastion"
path = "/"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": [
"ec2.amazonaws.com"
]
},
"Action": "sts:AssumeRole"
}
]
}
EOF
}
resource "aws_iam_instance_profile" "ec2-bastion" {
name = "ec2-bastion"
role = "${aws_iam_role.ec2-bastion.name}"
}
resource "aws_iam_role_policy_attachment" "ec2-bastion-ro" {
role = "${aws_iam_role.ec2-bastion.name}"
policy_arn = "arn:aws:iam::aws:policy/ReadOnlyAccess"
}
resource "aws_iam_role_policy_attachment" "ec2-bastion-ssm" {
role = "${aws_iam_role.ec2-bastion.name}"
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonEC2RoleforSSM"
}
################################
# IAM Role AMI Build
################################
# ami builder
resource "aws_iam_role" "ami-build" {
name = "ami-build"
path = "/"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": [
"ec2.amazonaws.com"
]
},
"Action": "sts:AssumeRole"
}
]
}
EOF
}
resource "aws_iam_instance_profile" "ami-build" {
name = "ami-build"
role = "${aws_iam_role.ami-build.name}"
}
resource "aws_iam_role_policy_attachment" "ami-build-ro" {
role = "${aws_iam_role.ami-build.name}"
policy_arn = "arn:aws:iam::aws:policy/ReadOnlyAccess"
}
resource "aws_iam_role_policy_attachment" "ami-build-ssm" {
role = "${aws_iam_role.ami-build.name}"
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonEC2RoleforSSM"
}
################################
# IAM Role Dev EC2
################################
resource "aws_iam_role" "ec2-dev" {
name = "ec2-dev"
path = "/"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": [
"ec2.amazonaws.com"
]
},
"Action": "sts:AssumeRole"
}
]
}
EOF
}
resource "aws_iam_instance_profile" "ec2-dev" {
name = "ec2-dev"
role = "${aws_iam_role.ec2-dev.name}"
}
resource "aws_iam_role_policy_attachment" "ec2-dev-ro" {
role = "${aws_iam_role.ec2-dev.name}"
policy_arn = "arn:aws:iam::aws:policy/ReadOnlyAccess"
}
resource "aws_iam_role_policy_attachment" "ec2-dev-ssm" {
role = "${aws_iam_role.ec2-dev.name}"
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonEC2RoleforSSM"
}