-
Notifications
You must be signed in to change notification settings - Fork 4
/
iam.tf
61 lines (51 loc) · 1.24 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
58
59
60
61
data "aws_iam_policy_document" "policy" {
statement {
actions = [
"secretsmanager:GetSecretValue"
]
resources = [
aws_secretsmanager_secret.secret.arn,
]
}
}
resource "aws_iam_policy" "policy" {
name = "${local.prefix}-policy"
path = "/"
policy = data.aws_iam_policy_document.policy.json
}
data "aws_iam_policy_document" "assume" {
statement {
actions = [
"sts:AssumeRole",
]
principals {
type = "Service"
identifiers = [
"ec2.amazonaws.com",
]
}
}
}
resource "aws_iam_role" "role" {
name = "${local.prefix}-role"
description = "${local.prefix}-role"
assume_role_policy = data.aws_iam_policy_document.assume.json
tags = merge(
local.common_tags,
{
"Name" = "${local.prefix}-role"
},
)
}
resource "aws_iam_role_policy_attachment" "attach_policy" {
policy_arn = "arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore"
role = aws_iam_role.role.name
}
resource "aws_iam_role_policy_attachment" "attach_policy2" {
policy_arn = aws_iam_policy.policy.arn
role = aws_iam_role.role.name
}
resource "aws_iam_instance_profile" "profile" {
name = "${local.prefix}-profile"
role = aws_iam_role.role.name
}