forked from GSA/grace-ansible-lambda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iam.tf
117 lines (112 loc) · 2.65 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
data "aws_iam_policy_document" "role" {
statement {
effect = "Allow"
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = [
"ec2.amazonaws.com",
"lambda.amazonaws.com"
]
}
}
}
resource "aws_iam_role" "role" {
name = "${local.app_name}-ec2"
description = "Allows EC2 to call ${local.app_name}"
assume_role_policy = data.aws_iam_policy_document.role.json
}
data "aws_iam_policy_document" "policy" {
statement {
effect = "Allow"
actions = ["lambda:InvokeFunction"]
resources = [aws_lambda_function.lambda.arn]
}
statement {
effect = "Allow"
actions = [
"s3:GetBucketLocation",
"s3:ListBucket"
]
resources = [aws_s3_bucket.bucket.arn]
}
statement {
effect = "Allow"
actions = [
"s3:PutObject",
"s3:GetObject",
"s3:DeleteObject"
]
resources = [
"${aws_s3_bucket.bucket.arn}/*",
"arn:aws:s3:::packages.*.amazonaws.com/*",
"arn:aws:s3:::repo.*.amazonaws.com/*",
"arn:aws:s3:::amazonlinux.*.amazonaws.com/*"
]
}
statement {
effect = "Allow"
actions = [
"kms:Encrypt",
"kms:Decrypt",
"kms:ReEncrypt*",
"kms:GenerateDataKey*",
"kms:DescribeKey"
]
resources = [aws_kms_key.kms.arn]
}
statement {
effect = "Allow"
actions = [
"ec2:DescribeImages",
"ec2:DescribeInstances",
"ec2:DescribeInstanceStatus",
"ec2:RunInstances",
"ec2:TerminateInstances",
"ec2:AssociateIamInstanceProfile",
"iam:GetRole",
"iam:PassRole",
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"s3:ListAllMyBuckets"
]
resources = ["*"]
}
statement {
effect = "Allow"
actions = [
"cloudwatch:PutMetricData",
"ec2:DescribeVolumes",
"ec2:DescribeTags",
"logs:PutLogEvents",
"logs:DescribeLogStreams",
"logs:DescribeLogGroups",
"logs:CreateLogStream",
"logs:CreateLogGroup"
]
resources = ["*"]
}
statement {
effect = "Allow"
actions = [
"ssm:GetParameter"
]
resources = [
"arn:aws:ssm:*:*:parameter/AmazonCloudWatch-*"
]
}
}
resource "aws_iam_policy" "policy" {
name = "${local.app_name}-ec2"
description = "Policy to allow EC2 to invoke ${local.app_name}"
policy = data.aws_iam_policy_document.policy.json
}
resource "aws_iam_role_policy_attachment" "attach" {
role = aws_iam_role.role.name
policy_arn = aws_iam_policy.policy.arn
}
resource "aws_iam_instance_profile" "profile" {
name = local.app_name
role = aws_iam_role.role.name
}