forked from getpima/terraform-aws-datadog-log-forwarder
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.tf
65 lines (55 loc) · 1.79 KB
/
main.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
locals {
output_file = "${path.module}/files/lambda/package.zip"
}
data "http" "datadog_forwarder" {
url = var.url
}
data "aws_region" "current" {
}
data "archive_file" "datadog_forwarder" {
type = "zip"
output_path = local.output_file
source {
filename = "lambda_function.py"
content = data.http.datadog_forwarder.body
}
}
data "aws_iam_policy_document" "lambda_execution_role" {
statement {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = [
"lambda.amazonaws.com",
"edgelambda.amazonaws.com",
"events.amazonaws.com"
]
}
}
}
resource "aws_iam_role" "lambda_execution_role" {
name_prefix = "lambda.datadog_forwarder"
assume_role_policy = data.aws_iam_policy_document.lambda_execution_role.json
}
resource "aws_iam_role_policy_attachment" "lambda_execution_basic" {
role = aws_iam_role.lambda_execution_role.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
}
resource "aws_lambda_function" "datadog_forwarder" {
description = "AWS Lambda to forward logs to Datadog"
filename = local.output_file
source_code_hash = data.archive_file.datadog_forwarder.output_base64sha256
function_name = "datadog-log-monitoring-function"
role = aws_iam_role.lambda_execution_role.arn
handler = "lambda_function.lambda_handler"
runtime = "python2.7"
publish = true
reserved_concurrent_executions = var.reserved_concurrent_executions
environment {
variables = {
DD_API_KEY = var.datadog_key,
REDACT_IP = var.redact_ip,
REDACT_EMAIL = var.redact_email
}
}
}