-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpermissions.tf
70 lines (66 loc) · 1.86 KB
/
permissions.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
resource "aws_iam_role" "this" {
name = "${local.lambda_function_name}_AllowLambdaExec"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
EOF
}
# This policy has 3 parts, which allow the TerraformMonitorLambda to:
# 1. Write logs from its execution to CloudWatch (this is usually the case for any Lambda)
# 2. Write custom CloudWatch metrics (because TerraformMonitorLambda supports both CloudWatch and InfluxDB as metrics sinks)
# 3. Read (and only read, not write) the Terraform state in S3
# Importantly, you'll note that even though our Terraform setup uses DynamoDB for state locking, we grant no DynamoDB permissions here, not even read-only ones.
# That's because the TerraformMonitorLambda doesn't need to lock the Terraform state when it runs its "terraform plan", so it doesn't need any DynamoDB access, so let's not give it any.
resource "aws_iam_policy" "this" {
name = "${local.lambda_function_name}"
path = "/"
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "arn:aws:logs:*:*:*",
"Effect": "Allow"
},
{
"Action": [
"cloudwatch:PutMetricData"
],
"Resource": "*",
"Effect": "Allow"
},
{
"Action": [
"s3:Get*",
"s3:List*"
],
"Resource": [
"arn:aws:s3:::${var.terraform_monitor_s3_bucket}",
"arn:aws:s3:::${var.terraform_monitor_s3_bucket}/*"
],
"Effect": "Allow"
}
]
}
EOF
}
resource "aws_iam_role_policy_attachment" "this" {
role = "${aws_iam_role.this.name}"
policy_arn = "${aws_iam_policy.this.arn}"
}