-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiam.tf
74 lines (68 loc) · 1.62 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
data "aws_iam_policy_document" "assume_lambda_role_policy" {
statement {
actions = [
"sts:AssumeRole"
]
effect = "Allow"
principals {
type = "Service"
identifiers = [
"ec2.amazonaws.com",
"lambda.amazonaws.com",
]
}
}
}
data "aws_iam_policy_document" "ec2_start_permissions" {
statement {
sid = "1"
actions = [
"ec2:StartInstances",
"ec2:StopInstances",
]
resources = ["arn:aws:ec2:*:*:instance/*"]
condition {
test = "StringEquals"
variable = "aws:ResourceTag/Name"
values = ["Satisfactory"]
}
}
statement {
sid = "2"
actions = [
"ec2:DescribeInstances",
"ec2:DescribeInstanceStatus",
]
resources = ["*"]
}
statement {
sid = "3"
actions = [
"s3:GetObject",
"s3:PutObject",
"s3:GetBucketLocation",
"s3:ListBucket"
]
resources = [
"arn:aws:s3:::satisfactoryserversaves",
"arn:aws:s3:::satisfactoryserversaves/*"
]
}
}
resource "aws_iam_policy" "lambda" {
name = "StartSatisfactory"
path = "/"
policy = data.aws_iam_policy_document.ec2_start_permissions.json
}
resource "aws_iam_role" "satisfactory_lambda" {
name = "Satisfactory"
assume_role_policy = data.aws_iam_policy_document.assume_lambda_role_policy.json
}
resource "aws_iam_role_policy_attachment" "satisfactory_lambda" {
role = aws_iam_role.satisfactory_lambda.name
policy_arn = aws_iam_policy.lambda.arn
}
resource "aws_iam_instance_profile" "satisfactory" {
name = "satisfactory"
role = aws_iam_role.satisfactory_lambda.name
}