Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/antonbabenko/pre-commit-terraform
rev: v1.96.2
rev: v1.99.5
hooks:
- id: terraform_fmt
- id: terraform_docs
Expand Down
24 changes: 12 additions & 12 deletions README.md

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions examples/complete/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,27 @@ Note that this example may create resources which will incur monetary charges on

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.0 |
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.5.7 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 6.0 |
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 2.0 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.0 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 6.0 |
| <a name="provider_random"></a> [random](#provider\_random) | >= 2.0 |

## Modules

| Name | Source | Version |
|------|--------|---------|
| <a name="module_default"></a> [default](#module\_default) | ../../ | n/a |
| <a name="module_log_bucket_1"></a> [log\_bucket\_1](#module\_log\_bucket\_1) | terraform-aws-modules/s3-bucket/aws | ~> 4.0 |
| <a name="module_log_bucket_2"></a> [log\_bucket\_2](#module\_log\_bucket\_2) | terraform-aws-modules/s3-bucket/aws | ~> 4.0 |
| <a name="module_log_bucket_1"></a> [log\_bucket\_1](#module\_log\_bucket\_1) | terraform-aws-modules/s3-bucket/aws | ~> 5.0 |
| <a name="module_log_bucket_2"></a> [log\_bucket\_2](#module\_log\_bucket\_2) | terraform-aws-modules/s3-bucket/aws | ~> 5.0 |
| <a name="module_security_group"></a> [security\_group](#module\_security\_group) | terraform-aws-modules/security-group/aws | ~> 5.0 |
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 5.0 |
| <a name="module_vpc_endpoints"></a> [vpc\_endpoints](#module\_vpc\_endpoints) | terraform-aws-modules/vpc/aws//modules/vpc-endpoints | ~> 5.0 |
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 6.0 |
| <a name="module_vpc_endpoints"></a> [vpc\_endpoints](#module\_vpc\_endpoints) | terraform-aws-modules/vpc/aws//modules/vpc-endpoints | ~> 6.0 |

## Resources

Expand Down
8 changes: 4 additions & 4 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ resource "aws_kms_alias" "datadog" {

module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "~> 5.0"
version = "~> 6.0"

name = local.name
cidr = local.vpc_cidr
Expand All @@ -254,7 +254,7 @@ module "vpc" {

module "vpc_endpoints" {
source = "terraform-aws-modules/vpc/aws//modules/vpc-endpoints"
version = "~> 5.0"
version = "~> 6.0"

vpc_id = module.vpc.vpc_id
security_group_ids = [module.security_group.security_group_id]
Expand Down Expand Up @@ -306,7 +306,7 @@ module "security_group" {

module "log_bucket_1" {
source = "terraform-aws-modules/s3-bucket/aws"
version = "~> 4.0"
version = "~> 5.0"

bucket_prefix = "logs-1-"
force_destroy = true
Expand All @@ -328,7 +328,7 @@ module "log_bucket_1" {

module "log_bucket_2" {
source = "terraform-aws-modules/s3-bucket/aws"
version = "~> 4.0"
version = "~> 5.0"

bucket_prefix = "logs-2-"
force_destroy = true
Expand Down
4 changes: 2 additions & 2 deletions examples/complete/versions.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
terraform {
required_version = ">= 1.3"
required_version = ">= 1.5.7"

required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 5.0"
version = ">= 6.0"
}
random = {
source = "hashicorp/random"
Expand Down
6 changes: 3 additions & 3 deletions examples/simple/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ Note that this example may create resources which will incur monetary charges on

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.0 |
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.5.7 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 6.0 |
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 2.0 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.0 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 6.0 |
| <a name="provider_random"></a> [random](#provider\_random) | >= 2.0 |

## Modules
Expand Down
4 changes: 2 additions & 2 deletions examples/simple/versions.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
terraform {
required_version = ">= 1.3"
required_version = ">= 1.5.7"

required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 5.0"
version = ">= 6.0"
}
random = {
source = "hashicorp/random"
Expand Down
14 changes: 7 additions & 7 deletions modules/log_forwarder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,22 @@ module "datadog_log_forwarder" {

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.0 |
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.5.7 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 6.0 |
| <a name="requirement_null"></a> [null](#requirement\_null) | >= 3.0 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.0 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 6.0 |
| <a name="provider_null"></a> [null](#provider\_null) | >= 3.0 |

## Modules

| Name | Source | Version |
|------|--------|---------|
| <a name="module_this_s3_bucket"></a> [this\_s3\_bucket](#module\_this\_s3\_bucket) | terraform-aws-modules/s3-bucket/aws | v3.6.1 |
| <a name="module_this_s3_bucket"></a> [this\_s3\_bucket](#module\_this\_s3\_bucket) | terraform-aws-modules/s3-bucket/aws | v5.2.0 |

## Resources

Expand All @@ -79,7 +79,7 @@ module "datadog_log_forwarder" {

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_architectures"></a> [architectures](#input\_architectures) | Instruction set architecture for your Lambda function. Valid values are `["x86_64"]` and `["arm64"]`. Default is `["x86_64"]` | `list(string)` | <pre>[<br/> "x86_64"<br/>]</pre> | no |
| <a name="input_architectures"></a> [architectures](#input\_architectures) | Instruction set architecture for your Lambda function. Valid values are `["x86_64"]` and `["arm64"]`. Default is `["arm64"]` | `list(string)` | <pre>[<br/> "arm64"<br/>]</pre> | no |
| <a name="input_bucket_attach_deny_insecure_transport_policy"></a> [bucket\_attach\_deny\_insecure\_transport\_policy](#input\_bucket\_attach\_deny\_insecure\_transport\_policy) | Controls if S3 bucket should have deny non-SSL transport policy attacheds | `bool` | `false` | no |
| <a name="input_bucket_encryption_settings"></a> [bucket\_encryption\_settings](#input\_bucket\_encryption\_settings) | S3 bucket server side encryption settings | `map(string)` | <pre>{<br/> "sse_algorithm": "AES256"<br/>}</pre> | no |
| <a name="input_bucket_name"></a> [bucket\_name](#input\_bucket\_name) | Forwarder S3 bucket name | `string` | `""` | no |
Expand All @@ -93,7 +93,7 @@ module "datadog_log_forwarder" {
| <a name="input_dd_api_key_secret_arn"></a> [dd\_api\_key\_secret\_arn](#input\_dd\_api\_key\_secret\_arn) | The ARN of the Secrets Manager secret storing the Datadog API key, if you already have it stored in Secrets Manager | `string` | `""` | no |
| <a name="input_dd_site"></a> [dd\_site](#input\_dd\_site) | Define your Datadog Site to send data to. For the Datadog EU site, set to datadoghq.eu | `string` | `"datadoghq.com"` | no |
| <a name="input_environment_variables"></a> [environment\_variables](#input\_environment\_variables) | A map of environment variables for the forwarder lambda function | `map(string)` | `{}` | no |
| <a name="input_forwarder_version"></a> [forwarder\_version](#input\_forwarder\_version) | Forwarder version - see https://github.com/DataDog/datadog-serverless-functions/releases | `string` | `"3.130.0"` | no |
| <a name="input_forwarder_version"></a> [forwarder\_version](#input\_forwarder\_version) | Forwarder version - see https://github.com/DataDog/datadog-serverless-functions/releases | `string` | `"4.12.0"` | no |
| <a name="input_kms_key_arn"></a> [kms\_key\_arn](#input\_kms\_key\_arn) | KMS key that is used to encrypt environment variables. If this configuration is not provided when environment variables are in use, AWS Lambda uses a default service key | `string` | `null` | no |
| <a name="input_lambda_tags"></a> [lambda\_tags](#input\_lambda\_tags) | A map of tags to apply to the forwarder lambda function | `map(string)` | `{}` | no |
| <a name="input_layers"></a> [layers](#input\_layers) | List of Lambda Layer Version ARNs (maximum of 5) to attach to the forwarder lambda | `list(string)` | `[]` | no |
Expand All @@ -112,7 +112,7 @@ module "datadog_log_forwarder" {
| <a name="input_role_path"></a> [role\_path](#input\_role\_path) | Forwarder role path | `string` | `null` | no |
| <a name="input_role_permissions_boundary"></a> [role\_permissions\_boundary](#input\_role\_permissions\_boundary) | The ARN of the policy that is used to set the permissions boundary for the forwarder role | `string` | `null` | no |
| <a name="input_role_tags"></a> [role\_tags](#input\_role\_tags) | A map of tags to apply to the forwarder role | `map(string)` | `{}` | no |
| <a name="input_runtime"></a> [runtime](#input\_runtime) | Lambda function runtime | `string` | `"python3.11"` | no |
| <a name="input_runtime"></a> [runtime](#input\_runtime) | Lambda function runtime | `string` | `"python3.12"` | no |
| <a name="input_s3_log_bucket_arns"></a> [s3\_log\_bucket\_arns](#input\_s3\_log\_bucket\_arns) | S3 log buckets for forwarder to read and forward logs to Datadog | `list(string)` | `[]` | no |
| <a name="input_s3_zip_kms_key_id"></a> [s3\_zip\_kms\_key\_id](#input\_s3\_zip\_kms\_key\_id) | The AWS KMS Key ARN to use for object encryption | `string` | `null` | no |
| <a name="input_s3_zip_metadata"></a> [s3\_zip\_metadata](#input\_s3\_zip\_metadata) | A map of keys/values to provision metadata (will be automatically prefixed by `x-amz-meta-` | `map(string)` | `{}` | no |
Expand Down
32 changes: 21 additions & 11 deletions modules/log_forwarder/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
locals {
bucket_name = var.bucket_name != "" ? var.bucket_name : "datadog-forwarder-${data.aws_caller_identity.current.account_id}-${data.aws_region.current.name}"
bucket_name = var.bucket_name != "" ? var.bucket_name : "datadog-forwarder-${data.aws_caller_identity.current[0].account_id}-${data.aws_region.current[0].region}"

dd_api_key = var.dd_api_key != "" ? { DD_API_KEY = var.dd_api_key } : {}
dd_api_key_secret_arn = var.dd_api_key_secret_arn != "" ? { DD_API_KEY_SECRET_ARN = var.dd_api_key_secret_arn } : {}
Expand All @@ -15,16 +15,20 @@ locals {
forwarder_zip = "${path.module}/${local.zip_name}"
}

data "aws_caller_identity" "current" {}
data "aws_region" "current" {}
data "aws_caller_identity" "current" {
count = var.create ? 1 : 0
}
data "aws_region" "current" {
count = var.create ? 1 : 0
}

################################################################################
# Forwarder Bucket
################################################################################

module "this_s3_bucket" {
source = "terraform-aws-modules/s3-bucket/aws"
version = "v3.6.1"
version = "v5.2.0"

create_bucket = var.create && var.create_bucket
bucket = local.bucket_name
Expand Down Expand Up @@ -54,7 +58,13 @@ module "this_s3_bucket" {
# Forwarder IAM Role
################################################################################

locals {
create_role = var.create && var.create_role
}

data "aws_iam_policy_document" "this" {
count = local.create_role ? 1 : 0

statement {
actions = [
"sts:AssumeRole",
Expand All @@ -68,14 +78,14 @@ data "aws_iam_policy_document" "this" {
}

resource "aws_iam_role" "this" {
count = var.create && var.create_role ? 1 : 0
count = local.create_role ? 1 : 0

name = var.use_role_name_prefix ? null : local.role_name
name_prefix = var.use_role_name_prefix ? "${local.role_name}-" : null
description = local.description
path = var.role_path

assume_role_policy = data.aws_iam_policy_document.this.json
assume_role_policy = data.aws_iam_policy_document.this[0].json
max_session_duration = var.role_max_session_duration
permissions_boundary = var.role_permissions_boundary
force_detach_policies = true
Expand All @@ -84,7 +94,7 @@ resource "aws_iam_role" "this" {
}

resource "aws_iam_policy" "this" {
count = var.create && var.create_role_policy ? 1 : 0
count = local.create_role && var.create_role_policy ? 1 : 0

name = var.use_policy_name_prefix ? null : local.policy_name
name_prefix = var.use_policy_name_prefix ? "${local.policy_name}-" : null
Expand All @@ -106,7 +116,7 @@ resource "aws_iam_policy" "this" {
}

resource "aws_iam_role_policy_attachment" "this" {
count = var.create && var.create_role ? 1 : 0
count = local.create_role ? 1 : 0

role = aws_iam_role.this[0].id
policy_arn = var.create_role_policy ? aws_iam_policy.this[0].id : var.policy_arn
Expand Down Expand Up @@ -205,8 +215,8 @@ resource "aws_lambda_permission" "cloudwatch" {
statement_id = "datadog-forwarder-CloudWatchLogsPermission"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.this[0].function_name
principal = "logs.${data.aws_region.current.name}.amazonaws.com"
source_account = data.aws_caller_identity.current.account_id
principal = "logs.${data.aws_region.current[0].region}.amazonaws.com"
source_account = data.aws_caller_identity.current[0].account_id
}

resource "aws_lambda_permission" "s3" {
Expand All @@ -216,7 +226,7 @@ resource "aws_lambda_permission" "s3" {
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.this[0].function_name
principal = "s3.amazonaws.com"
source_account = data.aws_caller_identity.current.account_id
source_account = data.aws_caller_identity.current[0].account_id
}

resource "aws_cloudwatch_log_group" "this" {
Expand Down
8 changes: 4 additions & 4 deletions modules/log_forwarder/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ variable "s3_log_bucket_arns" {
variable "forwarder_version" {
description = "Forwarder version - see https://github.com/DataDog/datadog-serverless-functions/releases"
type = string
default = "3.130.0"
default = "4.12.0"
}

variable "name" {
Expand All @@ -206,7 +206,7 @@ variable "name" {
variable "runtime" {
description = "Lambda function runtime"
type = string
default = "python3.11"
default = "python3.12"
}

variable "layers" {
Expand Down Expand Up @@ -234,9 +234,9 @@ variable "publish" {
}

variable "architectures" {
description = "Instruction set architecture for your Lambda function. Valid values are `[\"x86_64\"]` and `[\"arm64\"]`. Default is `[\"x86_64\"]`"
description = "Instruction set architecture for your Lambda function. Valid values are `[\"x86_64\"]` and `[\"arm64\"]`. Default is `[\"arm64\"]`"
type = list(string)
default = ["x86_64"]
default = ["arm64"]
}

variable "reserved_concurrent_executions" {
Expand Down
4 changes: 2 additions & 2 deletions modules/log_forwarder/versions.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
terraform {
required_version = ">= 1.3"
required_version = ">= 1.5.7"

required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 5.0"
version = ">= 6.0"
}
null = {
source = "hashicorp/null"
Expand Down
Loading