-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathmain.tf
More file actions
78 lines (65 loc) · 2.65 KB
/
main.tf
File metadata and controls
78 lines (65 loc) · 2.65 KB
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
locals {
architecture = var.architecture == "x86_64" ? "amd64" : "arm64"
}
resource "aws_lambda_layer_version" "sdk_layer" {
layer_name = var.sdk_layer_name
filename = "${path.module}/../../../../opentelemetry-lambda/python/src/build/layer.zip"
compatible_runtimes = ["python3.10", "python3.11", "python3.12", "python3.13"]
license_info = "Apache-2.0"
source_code_hash = filebase64sha256("${path.module}/../../../../opentelemetry-lambda/python/src/build/layer.zip")
}
resource "aws_lambda_layer_version" "collector_layer" {
count = var.enable_collector_layer ? 1 : 0
layer_name = var.collector_layer_name
filename = "${path.module}/../../../../opentelemetry-lambda/collector/build/opentelemetry-collector-layer-${local.architecture}.zip"
compatible_runtimes = ["nodejs16.x", "nodejs18.x", "nodejs20.x", "nodejs22.x"]
license_info = "Apache-2.0"
source_code_hash = filebase64sha256("${path.module}/../../../../opentelemetry-lambda/collector/build/opentelemetry-collector-layer-${local.architecture}.zip")
}
module "test-function" {
source = "terraform-aws-modules/lambda/aws"
version = "7.19.0"
architectures = compact([var.architecture])
function_name = var.function_name
handler = "lambda_function.lambda_handler"
runtime = var.runtime
create_package = false
local_existing_package = "${path.module}/../../../sample-apps/build/function.zip"
memory_size = 384
timeout = 20
layers = compact([
var.enable_collector_layer ? aws_lambda_layer_version.collector_layer[0].arn : null,
aws_lambda_layer_version.sdk_layer.arn
])
environment_variables = {
AWS_LAMBDA_EXEC_WRAPPER = "/opt/otel-instrument"
}
tracing_mode = var.tracing_mode
attach_policy_statements = true
policy_statements = {
s3 = {
effect = "Allow"
actions = [
"s3:ListAllMyBuckets"
]
resources = [
"*"
]
}
}
}
module "api-gateway" {
source = "../../../../opentelemetry-lambda/utils/terraform/api-gateway-proxy"
name = var.function_name
function_name = module.test-function.lambda_function_name
function_invoke_arn = module.test-function.lambda_function_invoke_arn
enable_xray_tracing = true
}
resource "aws_iam_role_policy_attachment" "hello-lambda-cloudwatch-insights" {
role = module.test-function.lambda_role_name
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
}
resource "aws_iam_role_policy_attachment" "test_xray" {
role = module.test-function.lambda_role_name
policy_arn = "arn:aws:iam::aws:policy/AWSXRayDaemonWriteAccess"
}