-
Notifications
You must be signed in to change notification settings - Fork 0
/
asg-iam.tf
52 lines (45 loc) · 1.16 KB
/
asg-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
resource "aws_iam_role" "asg" {
assume_role_policy = data.aws_iam_policy_document.trust_ec2.json
}
data "aws_iam_policy_document" "trust_ec2" {
statement {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["ec2.amazonaws.com"]
}
}
}
resource "aws_iam_role_policy_attachment" "AmazonSSMManagedInstanceCore" {
role = aws_iam_role.asg.name
policy_arn = "arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore"
}
resource "aws_iam_role_policy_attachment" "CloudWatchAgentServerPolicy" {
role = aws_iam_role.asg.name
policy_arn = "arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy"
}
resource "aws_iam_role_policy" "ec2_base" {
name = "AllowBase"
role = aws_iam_role.asg.name
policy = <<-EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"logs:DescribeLogStreams",
"ssm:GetParameter"
],
"Effect": "Allow",
"Resource": "*"
}
]
}
EOF
}
resource "aws_iam_instance_profile" "asg" {
role = aws_iam_role.asg.name
}