-
Notifications
You must be signed in to change notification settings - Fork 0
/
ec2_iam.tf
53 lines (47 loc) · 1.17 KB
/
ec2_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
# Create EC2 service role
resource "aws_iam_role" "o4bproject_ec2_iam_role" {
name = "AmpDevO4b-ec2-iam-role"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRole"
Effect = "Allow"
Sid = ""
Principal = {
Service = ["ec2.amazonaws.com", "application-autoscaling.amazonaws.com"]
}
},
]
})
tags = {
Name = "AmpDevO4b-ec2-iam-role"
Environment = "dev"
}
}
# Create EC2 IAM role policy
resource "aws_iam_role_policy" "o4bproject_ec2_iam_role_policy" {
name = "AmpDevO4b-ec2-iam-policy"
role = aws_iam_role.o4bproject_ec2_iam_role.id
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = [
"ec2:*",
"elasticloadbalancing:*",
"cloudwatch:*",
"autoscalinggroup:*",
"logs:*"
]
Effect = "Allow"
Resource = "*"
},
]
})
}
# Create EC2 IAM Instance profile
resource "aws_iam_instance_profile" "o4bproject_ec2_iam_instance_profile" {
name = "AmpDevO4b-ec2-iam-instance-profile"
role = aws_iam_role.o4bproject_ec2_iam_role.id
}