Skip to content

Commit 2a28e23

Browse files
authored
1 parent 5c961bb commit 2a28e23

File tree

7 files changed

+117
-23
lines changed

7 files changed

+117
-23
lines changed

src/README.md

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ components:
2626
# 3. CloudWatch Log Group `RDSOSMetrics` exists (it will be created by AWS automatically when RDS Enhanced Monitoring is enabled)
2727
forwarder_rds_enabled: true
2828
forwarder_log_enabled: true
29-
forwarder_vpc_enabled: true
29+
forwarder_vpc_logs_enabled: true
3030
cloudwatch_forwarder_log_groups:
3131
rds-enhanced-monitoring:
3232
name: "RDSOSMetrics"
@@ -52,24 +52,34 @@ components:
5252
| Name | Version |
5353
|------|---------|
5454
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0.0 |
55-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.0 |
55+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.0 |
56+
| <a name="requirement_datadog"></a> [datadog](#requirement\_datadog) | >= 3.3.0 |
5657
5758
## Providers
5859
59-
No providers.
60+
| Name | Version |
61+
|------|---------|
62+
| <a name="provider_datadog"></a> [datadog](#provider\_datadog) | >= 3.3.0 |
6063
6164
## Modules
6265
6366
| Name | Source | Version |
6467
|------|--------|---------|
65-
| <a name="module_datadog_lambda_forwarder"></a> [datadog\_lambda\_forwarder](#module\_datadog\_lambda\_forwarder) | cloudposse/datadog-lambda-forwarder/aws | 0.12.0 |
68+
| <a name="module_datadog-integration"></a> [datadog-integration](#module\_datadog-integration) | cloudposse/stack-config/yaml//modules/remote-state | 1.3.1 |
69+
| <a name="module_datadog_configuration"></a> [datadog\_configuration](#module\_datadog\_configuration) | ../datadog-configuration/modules/datadog_keys | n/a |
70+
| <a name="module_datadog_lambda_forwarder"></a> [datadog\_lambda\_forwarder](#module\_datadog\_lambda\_forwarder) | cloudposse/datadog-lambda-forwarder/aws | 1.0.0 |
6671
| <a name="module_iam_roles"></a> [iam\_roles](#module\_iam\_roles) | ../account-map/modules/iam-roles | n/a |
6772
| <a name="module_log_group_prefix"></a> [log\_group\_prefix](#module\_log\_group\_prefix) | cloudposse/label/null | 0.25.0 |
6873
| <a name="module_this"></a> [this](#module\_this) | cloudposse/label/null | 0.25.0 |
6974
7075
## Resources
7176
72-
No resources.
77+
| Name | Type |
78+
|------|------|
79+
| [datadog_integration_aws_lambda_arn.log_collector](https://registry.terraform.io/providers/datadog/datadog/latest/docs/resources/integration_aws_lambda_arn) | resource |
80+
| [datadog_integration_aws_lambda_arn.rds_collector](https://registry.terraform.io/providers/datadog/datadog/latest/docs/resources/integration_aws_lambda_arn) | resource |
81+
| [datadog_integration_aws_lambda_arn.vpc_logs_collector](https://registry.terraform.io/providers/datadog/datadog/latest/docs/resources/integration_aws_lambda_arn) | resource |
82+
| [datadog_integration_aws_log_collection.main](https://registry.terraform.io/providers/datadog/datadog/latest/docs/resources/integration_aws_log_collection) | resource |
7383
7484
## Inputs
7585
@@ -81,17 +91,17 @@ No resources.
8191
| <a name="input_context"></a> [context](#input\_context) | Single object for setting entire context at once.<br>See description of individual variables for details.<br>Leave string and numeric variables as `null` to use default value.<br>Individual variable settings (non-null) override settings in context object,<br>except for attributes, tags, and additional\_tag\_map, which are merged. | `any` | <pre>{<br> "additional_tag_map": {},<br> "attributes": [],<br> "delimiter": null,<br> "descriptor_formats": {},<br> "enabled": true,<br> "environment": null,<br> "id_length_limit": null,<br> "label_key_case": null,<br> "label_order": [],<br> "label_value_case": null,<br> "labels_as_tags": [<br> "unset"<br> ],<br> "name": null,<br> "namespace": null,<br> "regex_replace_chars": null,<br> "stage": null,<br> "tags": {},<br> "tenant": null<br>}</pre> | no |
8292
| <a name="input_context_tags"></a> [context\_tags](#input\_context\_tags) | List of context tags to add to each monitor | `set(string)` | <pre>[<br> "namespace",<br> "tenant",<br> "environment",<br> "stage"<br>]</pre> | no |
8393
| <a name="input_context_tags_enabled"></a> [context\_tags\_enabled](#input\_context\_tags\_enabled) | Whether to add context tags to add to each monitor | `bool` | `true` | no |
94+
| <a name="input_datadog_forwarder_lambda_environment_variables"></a> [datadog\_forwarder\_lambda\_environment\_variables](#input\_datadog\_forwarder\_lambda\_environment\_variables) | Map of environment variables to pass to the Lambda Function | `map(string)` | `{}` | no |
8495
| <a name="input_dd_api_key_kms_ciphertext_blob"></a> [dd\_api\_key\_kms\_ciphertext\_blob](#input\_dd\_api\_key\_kms\_ciphertext\_blob) | CiphertextBlob stored in environment variable DD\_KMS\_API\_KEY used by the lambda function, along with the KMS key, to decrypt Datadog API key | `string` | `""` | no |
8596
| <a name="input_dd_api_key_source"></a> [dd\_api\_key\_source](#input\_dd\_api\_key\_source) | One of: ARN for AWS Secrets Manager (asm) to retrieve the Datadog (DD) api key, ARN for the KMS (kms) key used to decrypt the ciphertext\_blob of the api key, or the name of the SSM (ssm) parameter used to retrieve the Datadog API key | <pre>object({<br> resource = string<br> identifier = string<br> })</pre> | <pre>{<br> "identifier": "",<br> "resource": ""<br>}</pre> | no |
8697
| <a name="input_dd_artifact_filename"></a> [dd\_artifact\_filename](#input\_dd\_artifact\_filename) | The Datadog artifact filename minus extension | `string` | `"aws-dd-forwarder"` | no |
87-
| <a name="input_dd_forwarder_version"></a> [dd\_forwarder\_version](#input\_dd\_forwarder\_version) | Version tag of Datadog lambdas to use. https://github.com/DataDog/datadog-serverless-functions/releases | `string` | `"3.40.0"` | no |
98+
| <a name="input_dd_forwarder_version"></a> [dd\_forwarder\_version](#input\_dd\_forwarder\_version) | Version tag of Datadog lambdas to use. https://github.com/DataDog/datadog-serverless-functions/releases | `string` | `"3.61.0"` | no |
8899
| <a name="input_dd_module_name"></a> [dd\_module\_name](#input\_dd\_module\_name) | The Datadog GitHub repository name | `string` | `"datadog-serverless-functions"` | no |
89100
| <a name="input_dd_tags_map"></a> [dd\_tags\_map](#input\_dd\_tags\_map) | A map of Datadog tags to apply to all logs forwarded to Datadog | `map(string)` | `{}` | no |
90101
| <a name="input_delimiter"></a> [delimiter](#input\_delimiter) | Delimiter to be used between ID elements.<br>Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no |
91102
| <a name="input_descriptor_formats"></a> [descriptor\_formats](#input\_descriptor\_formats) | Describe additional descriptors to be output in the `descriptors` output map.<br>Map of maps. Keys are names of descriptors. Values are maps of the form<br>`{<br> format = string<br> labels = list(string)<br>}`<br>(Type is `any` so the map values can later be enhanced to provide additional options.)<br>`format` is a Terraform format string to be passed to the `format()` function.<br>`labels` is a list of labels, in order, to pass to `format()` function.<br>Label values will be normalized before being passed to `format()` so they will be<br>identical to how they appear in `id`.<br>Default is `{}` (`descriptors` output will be empty). | `any` | `{}` | no |
92103
| <a name="input_enabled"></a> [enabled](#input\_enabled) | Set to false to prevent the module from creating any resources | `bool` | `null` | no |
93104
| <a name="input_environment"></a> [environment](#input\_environment) | ID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no |
94-
| <a name="input_forwarder_lambda_datadog_host"></a> [forwarder\_lambda\_datadog\_host](#input\_forwarder\_lambda\_datadog\_host) | Datadog Site to send data to. Possible values are `datadoghq.com`, `datadoghq.eu`, `us3.datadoghq.com` and `ddog-gov.com` | `string` | `"datadoghq.com"` | no |
95105
| <a name="input_forwarder_lambda_debug_enabled"></a> [forwarder\_lambda\_debug\_enabled](#input\_forwarder\_lambda\_debug\_enabled) | Whether to enable or disable debug for the Lambda forwarder | `bool` | `false` | no |
96106
| <a name="input_forwarder_log_artifact_url"></a> [forwarder\_log\_artifact\_url](#input\_forwarder\_log\_artifact\_url) | The URL for the code of the Datadog forwarder for Logs. It can be a local file, URL or git repo | `string` | `null` | no |
97107
| <a name="input_forwarder_log_enabled"></a> [forwarder\_log\_enabled](#input\_forwarder\_log\_enabled) | Flag to enable or disable Datadog log forwarder | `bool` | `false` | no |
@@ -113,9 +123,11 @@ No resources.
113123
| <a name="input_label_order"></a> [label\_order](#input\_label\_order) | The order in which the labels (ID elements) appear in the `id`.<br>Defaults to ["namespace", "environment", "stage", "name", "attributes"].<br>You can omit any of the 6 labels ("tenant" is the 6th), but at least one must be present. | `list(string)` | `null` | no |
114124
| <a name="input_label_value_case"></a> [label\_value\_case](#input\_label\_value\_case) | Controls the letter case of ID elements (labels) as included in `id`,<br>set as tag values, and output by this module individually.<br>Does not affect values of tags passed in via the `tags` input.<br>Possible values: `lower`, `title`, `upper` and `none` (no transformation).<br>Set this to `title` and set `delimiter` to `""` to yield Pascal Case IDs.<br>Default value: `lower`. | `string` | `null` | no |
115125
| <a name="input_labels_as_tags"></a> [labels\_as\_tags](#input\_labels\_as\_tags) | Set of labels (ID elements) to include as tags in the `tags` output.<br>Default is to include all labels.<br>Tags with empty values will not be included in the `tags` output.<br>Set to `[]` to suppress all generated tags.<br>**Notes:**<br> The value of the `name` tag, if included, will be the `id`, not the `name`.<br> Unlike other `null-label` inputs, the initial setting of `labels_as_tags` cannot be<br> changed in later chained modules. Attempts to change it will be silently ignored. | `set(string)` | <pre>[<br> "default"<br>]</pre> | no |
126+
| <a name="input_lambda_arn_enabled"></a> [lambda\_arn\_enabled](#input\_lambda\_arn\_enabled) | Enable adding the Lambda Arn to this account integration | `bool` | `true` | no |
116127
| <a name="input_lambda_policy_source_json"></a> [lambda\_policy\_source\_json](#input\_lambda\_policy\_source\_json) | Additional IAM policy document that can optionally be passed and merged with the created policy document | `string` | `""` | no |
117128
| <a name="input_lambda_reserved_concurrent_executions"></a> [lambda\_reserved\_concurrent\_executions](#input\_lambda\_reserved\_concurrent\_executions) | Amount of reserved concurrent executions for the lambda function. A value of 0 disables Lambda from being triggered and -1 removes any concurrency limitations. Defaults to Unreserved Concurrency Limits -1 | `number` | `-1` | no |
118-
| <a name="input_lambda_runtime"></a> [lambda\_runtime](#input\_lambda\_runtime) | Runtime environment for Datadog Lambda | `string` | `"python3.7"` | no |
129+
| <a name="input_lambda_runtime"></a> [lambda\_runtime](#input\_lambda\_runtime) | Runtime environment for Datadog Lambda | `string` | `"python3.8"` | no |
130+
| <a name="input_log_collection_services"></a> [log\_collection\_services](#input\_log\_collection\_services) | List of log collection services to enable | `list(string)` | <pre>[<br> "apigw-access-logs",<br> "apigw-execution-logs",<br> "elbv2",<br> "elb",<br> "cloudfront",<br> "lambda",<br> "redshift",<br> "s3"<br>]</pre> | no |
119131
| <a name="input_name"></a> [name](#input\_name) | ID element. Usually the component or solution name, e.g. 'app' or 'jenkins'.<br>This is the only ID element not also included as a `tag`.<br>The "name" tag is set to the full `id` string. There is no tag with the value of the `name` input. | `string` | `null` | no |
120132
| <a name="input_namespace"></a> [namespace](#input\_namespace) | ID element. Usually an abbreviation of your organization name, e.g. 'eg' or 'cp', to help ensure generated IDs are globally unique | `string` | `null` | no |
121133
| <a name="input_regex_replace_chars"></a> [regex\_replace\_chars](#input\_regex\_replace\_chars) | Terraform regular expression (regex) string.<br>Characters matching the regex will be removed from the ID elements.<br>If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. | `string` | `null` | no |

src/main.tf

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
locals {
2+
enabled = module.this.enabled
3+
24
# If any keys contain name_suffix, then use a null label to get the label prefix, and create
35
# the appropriate input for the upstream module.
46
cloudwatch_forwarder_log_groups = {
@@ -38,7 +40,7 @@ module "log_group_prefix" {
3840

3941
module "datadog_lambda_forwarder" {
4042
source = "cloudposse/datadog-lambda-forwarder/aws"
41-
version = "0.12.0"
43+
version = "1.0.0"
4244

4345
cloudwatch_forwarder_log_groups = local.cloudwatch_forwarder_log_groups
4446
dd_api_key_kms_ciphertext_blob = var.dd_api_key_kms_ciphertext_blob
@@ -47,7 +49,7 @@ module "datadog_lambda_forwarder" {
4749
dd_forwarder_version = var.dd_forwarder_version
4850
dd_module_name = var.dd_module_name
4951
dd_tags_map = local.dd_tags_map
50-
forwarder_lambda_datadog_host = var.forwarder_lambda_datadog_host
52+
forwarder_lambda_datadog_host = module.datadog_configuration.datadog_site
5153
forwarder_lambda_debug_enabled = var.forwarder_lambda_debug_enabled
5254
forwarder_log_artifact_url = var.forwarder_log_artifact_url
5355
forwarder_log_enabled = var.forwarder_log_enabled
@@ -72,5 +74,35 @@ module "datadog_lambda_forwarder" {
7274
tracing_config_mode = var.tracing_config_mode
7375
vpclogs_cloudwatch_log_group = var.vpclogs_cloudwatch_log_group
7476

77+
datadog_forwarder_lambda_environment_variables = var.datadog_forwarder_lambda_environment_variables
78+
7579
context = module.this.context
7680
}
81+
82+
# Create a new Datadog - Amazon Web Services integration Lambda ARN
83+
resource "datadog_integration_aws_lambda_arn" "rds_collector" {
84+
count = var.lambda_arn_enabled && var.forwarder_rds_enabled ? 1 : 0
85+
86+
account_id = module.datadog-integration.outputs.aws_account_id
87+
lambda_arn = module.datadog_lambda_forwarder.lambda_forwarder_rds_function_arn
88+
}
89+
90+
resource "datadog_integration_aws_lambda_arn" "vpc_logs_collector" {
91+
count = var.lambda_arn_enabled && var.forwarder_vpc_logs_enabled ? 1 : 0
92+
93+
account_id = module.datadog-integration.outputs.aws_account_id
94+
lambda_arn = module.datadog_lambda_forwarder.lambda_forwarder_vpc_log_function_arn
95+
}
96+
97+
resource "datadog_integration_aws_lambda_arn" "log_collector" {
98+
count = var.lambda_arn_enabled && var.forwarder_log_enabled ? 1 : 0
99+
100+
account_id = module.datadog-integration.outputs.aws_account_id
101+
lambda_arn = module.datadog_lambda_forwarder.lambda_forwarder_log_function_arn
102+
}
103+
104+
resource "datadog_integration_aws_log_collection" "main" {
105+
count = var.lambda_arn_enabled ? 1 : 0
106+
account_id = module.datadog-integration.outputs.aws_account_id
107+
services = var.log_collection_services
108+
}

src/provider-datadog.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module "datadog_configuration" {
2+
source = "../datadog-configuration/modules/datadog_keys"
3+
region = var.region
4+
context = module.this.context
5+
}
6+
7+
provider "datadog" {
8+
api_key = module.datadog_configuration.datadog_api_key
9+
app_key = module.datadog_configuration.datadog_app_key
10+
api_url = module.datadog_configuration.datadog_api_url
11+
validate = local.enabled
12+
}

src/providers.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ provider "aws" {
22
region = var.region
33

44
profile = module.iam_roles.profiles_enabled ? coalesce(var.import_profile_name, module.iam_roles.terraform_profile_name) : null
5+
56
dynamic "assume_role" {
67
for_each = module.iam_roles.profiles_enabled ? [] : ["role"]
78
content {

src/remote-state.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module "datadog-integration" {
2+
source = "cloudposse/stack-config/yaml//modules/remote-state"
3+
version = "1.3.1"
4+
5+
component = "datadog-integration"
6+
7+
environment = "gbl"
8+
context = module.this.context
9+
}

src/variables.tf

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ variable "lambda_reserved_concurrent_executions" {
2525
variable "lambda_runtime" {
2626
type = string
2727
description = "Runtime environment for Datadog Lambda"
28-
default = "python3.7"
28+
default = "python3.8"
2929
}
3030

3131
variable "tracing_config_mode" {
@@ -92,7 +92,7 @@ variable "dd_module_name" {
9292
variable "dd_forwarder_version" {
9393
type = string
9494
description = "Version tag of Datadog lambdas to use. https://github.com/DataDog/datadog-serverless-functions/releases"
95-
default = "3.40.0"
95+
default = "3.61.0"
9696
}
9797

9898
variable "forwarder_log_enabled" {
@@ -181,16 +181,6 @@ variable "lambda_policy_source_json" {
181181
default = ""
182182
}
183183

184-
variable "forwarder_lambda_datadog_host" {
185-
type = string
186-
description = "Datadog Site to send data to. Possible values are `datadoghq.com`, `datadoghq.eu`, `us3.datadoghq.com` and `ddog-gov.com`"
187-
default = "datadoghq.com"
188-
validation {
189-
condition = contains(["datadoghq.com", "datadoghq.eu", "us3.datadoghq.com", "ddog-gov.com"], var.forwarder_lambda_datadog_host)
190-
error_message = "Invalid host: possible values are `datadoghq.com`, `datadoghq.eu`, `us3.datadoghq.com` and `ddog-gov.com`."
191-
}
192-
}
193-
194184
variable "forwarder_log_layers" {
195185
type = list(string)
196186
description = "List of Lambda Layer Version ARNs (maximum of 5) to attach to Datadog log forwarder lambda function"
@@ -238,3 +228,37 @@ variable "context_tags" {
238228
description = "List of context tags to add to each monitor"
239229
default = ["namespace", "tenant", "environment", "stage"]
240230
}
231+
232+
variable "lambda_arn_enabled" {
233+
type = bool
234+
description = "Enable adding the Lambda Arn to this account integration"
235+
default = true
236+
}
237+
238+
# No Datasource for this (yet?)
239+
/**
240+
curl -X GET "${DD_API_URL}/api/v1/integration/aws/logs/services" \
241+
-H "Accept: application/json" \
242+
-H "DD-API-KEY: ${DD_API_KEY}" \
243+
-H "DD-APPLICATION-KEY: ${DD_APP_KEY}"
244+
**/
245+
variable "log_collection_services" {
246+
type = list(string)
247+
description = "List of log collection services to enable"
248+
default = [
249+
"apigw-access-logs",
250+
"apigw-execution-logs",
251+
"elbv2",
252+
"elb",
253+
"cloudfront",
254+
"lambda",
255+
"redshift",
256+
"s3"
257+
]
258+
}
259+
260+
variable "datadog_forwarder_lambda_environment_variables" {
261+
type = map(string)
262+
default = {}
263+
description = "Map of environment variables to pass to the Lambda Function"
264+
}

src/versions.tf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 3.0"
7+
version = ">= 4.0"
8+
}
9+
datadog = {
10+
source = "datadog/datadog"
11+
version = ">= 3.3.0"
812
}
913
}
1014
}

0 commit comments

Comments
 (0)