Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ locals {
)
}

data "aws_lambda_layer_version" "this" {
layer_version_arn = local.default_layer_arn
}

# Deprecation warnings for conflicting API key configurations.
# These will become hard validation errors in a future major release.
check "dd_api_key_not_used_with_secret_arn" {
Expand Down
2 changes: 1 addition & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ resource "aws_lambda_function" "forwarder" {
description = "Pushes logs, metrics and traces from AWS to Datadog."
role = local.iam_role_arn
handler = "lambda_function.lambda_handler"
runtime = var.layer_version == "latest" ? "python3.14" : (can(tonumber(var.layer_version)) && tonumber(var.layer_version) >= 94 ? "python3.14" : "python3.13")
runtime = reverse(sort(tolist(data.aws_lambda_layer_version.this.compatible_runtimes)))[0]
architectures = ["arm64"]
memory_size = var.memory_size
timeout = var.timeout
Expand Down
8 changes: 8 additions & 0 deletions tests/create_api_key_secret_flag.tftest.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ mock_provider "aws" {
dns_suffix = "amazonaws.com"
}
}

mock_data "aws_lambda_layer_version" {
defaults = {
compatible_runtimes = [
"python3.14",
]
}
}
}

variables {
Expand Down
9 changes: 8 additions & 1 deletion tests/default_config.tftest.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ mock_provider "aws" {
partition = "aws"
}
}

mock_data "aws_lambda_layer_version" {
defaults = {
compatible_runtimes = [
"python3.14",
]
}
}
}

variables {
Expand Down Expand Up @@ -188,4 +196,3 @@ run "environment_variables_test" {
error_message = "DD_API_KEY_SSM_NAME should not be present when using Secrets Manager"
}
}

8 changes: 8 additions & 0 deletions tests/enhanced_features.tftest.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ mock_provider "aws" {
partition = "aws"
}
}

mock_data "aws_lambda_layer_version" {
defaults = {
compatible_runtimes = [
"python3.14",
]
}
}
}

variables {
Expand Down
8 changes: 8 additions & 0 deletions tests/enrich_fetch_variables.tftest.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ mock_provider "aws" {
arn = "arn:aws:s3:::existing-datadog-bucket"
}
}

mock_data "aws_lambda_layer_version" {
defaults = {
compatible_runtimes = [
"python3.14",
]
}
}
}

variables {
Expand Down
8 changes: 8 additions & 0 deletions tests/existing_iam_role_without_bucket.tftest.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ mock_provider "aws" {
partition = "aws"
}
}

mock_data "aws_lambda_layer_version" {
defaults = {
compatible_runtimes = [
"python3.14",
]
}
}
}

# Test: existing IAM role with SSM parameter (no bucket specified) - should work
Expand Down
8 changes: 8 additions & 0 deletions tests/existing_resources.tftest.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ mock_provider "aws" {
partition = "aws"
}
}

mock_data "aws_lambda_layer_version" {
defaults = {
compatible_runtimes = [
"python3.14",
]
}
}
}

variables {
Expand Down
32 changes: 31 additions & 1 deletion tests/forwarder_version_tag.tftest.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ mock_provider "aws" {
partition = "aws"
}
}

mock_data "aws_lambda_layer_version" {
defaults = {
compatible_runtimes = [
"python3.12",
"python3.14",
"python3.13"
]
}
}
}

variables {
Expand Down Expand Up @@ -45,6 +55,12 @@ run "version_tag_with_latest" {
condition = local.forwarder_version != null
error_message = "local.forwarder_version should be set when using latest"
}

# Layer runtime should be set to the latest version of compatible_runtimes
assert {
condition = aws_lambda_function.forwarder.runtime == "python3.14"
error_message = "Lambda runtime should be python3.14"
}
}

# Test with specific layer_version
Expand All @@ -55,6 +71,15 @@ run "version_tag_with_specific_layer" {
layer_version = "92"
}

override_data {
target = data.aws_lambda_layer_version.this
values = {
compatible_runtimes = [
"python3.13",
]
}
}

# Lambda should have dd_forwarder_version tag
assert {
condition = contains(keys(aws_lambda_function.forwarder.tags), "dd_forwarder_version")
Expand All @@ -72,6 +97,12 @@ run "version_tag_with_specific_layer" {
condition = can(regex(":92$", aws_lambda_function.forwarder.layers[0]))
error_message = "Lambda layer ARN should end with :92"
}

# Runtime should match the compatible_runtimes returned by the layer data source
assert {
condition = aws_lambda_function.forwarder.runtime == "python3.13"
error_message = "Lambda runtime should be python3.13"
}
}

# Test that user tags are preserved alongside dd_forwarder_version
Expand Down Expand Up @@ -102,4 +133,3 @@ run "version_tag_with_user_tags" {
error_message = "dd_forwarder_version tag should be added alongside user tags"
}
}

8 changes: 8 additions & 0 deletions tests/multi_region.tftest.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ mock_provider "aws" {
partition = "aws"
}
}

mock_data "aws_lambda_layer_version" {
defaults = {
compatible_runtimes = [
"python3.14",
]
}
}
}

variables {
Expand Down
8 changes: 8 additions & 0 deletions tests/optional_env_vars.tftest.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ mock_provider "aws" {
partition = "aws"
}
}

mock_data "aws_lambda_layer_version" {
defaults = {
compatible_runtimes = [
"python3.14",
]
}
}
}

variables {
Expand Down
8 changes: 8 additions & 0 deletions tests/s3_log_bucket_arns.tftest.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ mock_provider "aws" {
partition = "aws"
}
}

mock_data "aws_lambda_layer_version" {
defaults = {
compatible_runtimes = [
"python3.14",
]
}
}
}

# Test: Default behavior - s3:GetObject should allow all buckets for backward compatibility
Expand Down
8 changes: 8 additions & 0 deletions tests/secrets_management.tftest.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ mock_provider "aws" {
partition = "aws"
}
}

mock_data "aws_lambda_layer_version" {
defaults = {
compatible_runtimes = [
"python3.14",
]
}
}
}

# Path 1: dd_api_key only (auto-create secret)
Expand Down
8 changes: 8 additions & 0 deletions tests/sqs_failed_events.tftest.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ mock_provider "aws" {
partition = "aws"
}
}

mock_data "aws_lambda_layer_version" {
defaults = {
compatible_runtimes = [
"python3.14",
]
}
}
}

# Test: SQS URL auto-enables DD_STORE_FAILED_EVENTS and skips S3 bucket creation
Expand Down
8 changes: 8 additions & 0 deletions tests/vpc_config.tftest.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ mock_provider "aws" {
partition = "aws"
}
}

mock_data "aws_lambda_layer_version" {
defaults = {
compatible_runtimes = [
"python3.14",
]
}
}
}

variables {
Expand Down