-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstance_profile.tf
More file actions
57 lines (51 loc) · 1.18 KB
/
instance_profile.tf
File metadata and controls
57 lines (51 loc) · 1.18 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
locals {
role_policy_arns = [
"arn:aws:iam::aws:policy/service-role/AmazonEC2RoleforSSM",
"arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy"
]
}
resource "aws_iam_instance_profile" "this" {
name = "EC2-Profile"
role = aws_iam_role.this.name
}
resource "aws_iam_role_policy_attachment" "this" {
count = length(local.role_policy_arns)
role = aws_iam_role.this.name
policy_arn = element(local.role_policy_arns, count.index)
}
resource "aws_iam_role_policy" "this" {
name = "EC2-Inline-Policy"
role = aws_iam_role.this.id
policy = jsonencode(
{
"Version" : "2012-10-17",
"Statement" : [
{
"Effect" : "Allow",
"Action" : [
"ssm:GetParameter"
],
"Resource" : "*"
}
]
}
)
}
resource "aws_iam_role" "this" {
name = "EC2-Role"
path = "/"
assume_role_policy = jsonencode(
{
"Version" : "2012-10-17",
"Statement" : [
{
"Action" : "sts:AssumeRole",
"Principal" : {
"Service" : "ec2.amazonaws.com"
},
"Effect" : "Allow"
}
]
}
)
}