forked from cloudposse/terraform-aws-ec2-bastion-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iam.tf
130 lines (103 loc) · 2.66 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
resource "aws_iam_instance_profile" "default" {
count = module.this.enabled && local.create_instance_profile ? 1 : 0
name = module.this.id
role = aws_iam_role.default[0].name
tags = module.this.tags
}
resource "aws_iam_role" "default" {
count = module.this.enabled && local.create_instance_profile ? 1 : 0
name = module.this.id
path = "/"
tags = module.this.tags
assume_role_policy = data.aws_iam_policy_document.default.json
}
resource "aws_iam_role_policy_attachment" "existing_policies" {
count = module.this.enabled && length(var.existing_policy_arns) > 0 ? length(var.existing_policy_arns) : 0
role = aws_iam_role.default[0].name
policy_arn = var.existing_policy_arns[count.index]
}
resource "aws_iam_role_policy" "main" {
count = module.this.enabled && local.create_instance_profile ? 1 : 0
name = module.this.id
role = aws_iam_role.default[0].id
policy = data.aws_iam_policy_document.main.json
}
data "aws_iam_policy_document" "default" {
statement {
sid = ""
actions = [
"sts:AssumeRole",
]
principals {
type = "Service"
identifiers = ["ec2.amazonaws.com"]
}
effect = "Allow"
}
}
data "aws_iam_policy_document" "main" {
statement {
effect = "Allow"
actions = [
"ssm:DescribeAssociation",
"ssm:GetDeployablePatchSnapshotForInstance",
"ssm:GetDocument",
"ssm:DescribeDocument",
"ssm:GetManifest",
"ssm:GetParameter",
"ssm:GetParameters",
"ssm:ListAssociations",
"ssm:ListInstanceAssociations",
"ssm:PutInventory",
"ssm:PutComplianceItems",
"ssm:PutConfigurePackageResult",
"ssm:UpdateAssociationStatus",
"ssm:UpdateInstanceAssociationStatus",
"ssm:UpdateInstanceInformation"
]
resources = ["*"]
}
statement {
effect = "Allow"
actions = [
"ssmmessages:CreateControlChannel",
"ssmmessages:CreateDataChannel",
"ssmmessages:OpenControlChannel",
"ssmmessages:OpenDataChannel"
]
resources = ["*"]
}
statement {
effect = "Allow"
actions = [
"ec2messages:AcknowledgeMessage",
"ec2messages:DeleteMessage",
"ec2messages:FailMessage",
"ec2messages:GetEndpoint",
"ec2messages:GetMessages",
"ec2messages:SendReply"
]
resources = ["*"]
}
statement {
effect = "Allow"
actions = [
"s3:GetEncryptionConfiguration"
]
resources = ["*"]
}
statement {
effect = "Allow"
actions = [
"kms:Decrypt"
]
resources = [var.kms_key_arn]
}
statement {
effect = "Allow"
actions = [
"kms:GenerateDataKey"
]
resources = ["*"]
}
}