-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathiam.tf
43 lines (38 loc) · 1.08 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
data "template_file" "policy" {
template = file("${path.module}/files/es_policy.json")
vars = {
s3_bucket_arn = var.s3_bucket_arn
}
}
resource "aws_iam_policy" "policy" {
name = "${var.prefix}alb-logs-to-elasticsearch"
path = "/"
description = "Policy for ${var.prefix}alb-logs-to-elasticsearch Lambda function"
policy = data.template_file.policy.rendered
}
resource "aws_iam_role" "role" {
name = "${var.prefix}alb-logs-to-elasticsearch"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
EOF
}
resource "aws_iam_role_policy_attachment" "policy_attachment" {
role = aws_iam_role.role.name
policy_arn = aws_iam_policy.policy.arn
}
resource "aws_iam_role_policy_attachment" "policy_attachment_vpc" {
count = length(var.subnet_ids) > 0 ? 1 : 0
role = aws_iam_role.role.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole"
}