-
Notifications
You must be signed in to change notification settings - Fork 0
/
iam.tf
94 lines (82 loc) · 2.02 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
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
resource "aws_iam_role" "aws_ec2_custom_role" {
name = "ec2-custom-iam-role"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRole"
Effect = "Allow"
Sid = ""
Principal = {
Service = "ec2.amazonaws.com"
}
},
]
})
tags = {
"Name" = "ec2-custom-iam-role"
}
}
resource "aws_iam_policy" "allow_secrets_manager" {
name = "secrets-manager-policy"
path = "/"
description = "Secrets Manager Policy"
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Action = [
"secretsmanager:GetSecretValue",
"secretsmanager:UpdateSecret",
"secretsmanager:DeleteSecret",
"secretsmanager:DescribeSecret",
"secretsmanager:ListSecrets",
"secretsmanager:CreateSecret",
"secretsmanager:PutSecretValue",
],
Resource = [
"*"
]
}
]
})
tags = {
"Name" = "secrets-manager-policy"
}
}
resource "aws_iam_policy" "allow_elastic_ip" {
name = "elastic-ip-policy"
path = "/"
description = "Elastic IP Policy"
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Action = [
"ec2:AssociateAddress",
"ec2:DisassociateAddress",
],
Resource = [
"*"
]
}
]
})
tags = {
"Name" = "elastic-ip-policy"
}
}
resource "aws_iam_role_policy_attachment" "attach_allow_secrets_manager_policy" {
role = aws_iam_role.aws_ec2_custom_role.name
policy_arn = aws_iam_policy.allow_secrets_manager.arn
}
resource "aws_iam_role_policy_attachment" "attach_allow_elastic_ip_policy" {
role = aws_iam_role.aws_ec2_custom_role.name
policy_arn = aws_iam_policy.allow_elastic_ip.arn
}
resource "aws_iam_instance_profile" "e2_custom_profile" {
name = "e2-custom-profile"
role = aws_iam_role.aws_ec2_custom_role.name
}