Skip to content

Commit

Permalink
Merge pull request #14 from lagerfeuer/master
Browse files Browse the repository at this point in the history
Add datadog integration docker labels to app container instead
  • Loading branch information
robertomoutinho authored Dec 26, 2023
2 parents b42f859 + a44f6cf commit f0c0ac7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ This repository contains Terraform infrastructure code which creates AWS resourc
| <a name="input_custom_environment_variables"></a> [custom\_environment\_variables](#input\_custom\_environment\_variables) | List of additional environment variables the container will use (list should contain maps with `name` and `value`) | <pre>list(object(<br> {<br> name = string<br> value = string<br> }<br> ))</pre> | `[]` | no |
| <a name="input_datadog_agent_container_essential"></a> [datadog\_agent\_container\_essential](#input\_datadog\_agent\_container\_essential) | Determines whether all other containers in a task are stopped, if this container fails or stops for any reason | `bool` | `false` | no |
| <a name="input_datadog_agent_container_image"></a> [datadog\_agent\_container\_image](#input\_datadog\_agent\_container\_image) | The datadog agent sidecar container image | `string` | `"datadog/agent:latest"` | no |
| <a name="input_datadog_agent_integrations"></a> [datadog\_agent\_integrations](#input\_datadog\_agent\_integrations) | The datadog agent integrations, see Docker (AD v2) at https://docs.datadoghq.com/containers/docker/integrations/?tab=dockeradv2 | <pre>list(object({<br> name = string<br> config = optional(list(string), [])<br> }))</pre> | `[]` | no |
| <a name="input_datadog_firelens_container_essential"></a> [datadog\_firelens\_container\_essential](#input\_datadog\_firelens\_container\_essential) | Determines whether all other containers in a task are stopped, if this container fails or stops for any reason | `bool` | `false` | no |
| <a name="input_datadog_firelens_container_image"></a> [datadog\_firelens\_container\_image](#input\_datadog\_firelens\_container\_image) | The datadog firelens sidecar container image | `string` | `"amazon/aws-for-fluent-bit:stable"` | no |
| <a name="input_datadog_service_name"></a> [datadog\_service\_name](#input\_datadog\_service\_name) | The datadog service name | `string` | `""` | no |
| <a name="input_datadog_tags"></a> [datadog\_tags](#input\_datadog\_tags) | Tags for datadog agent container. | `string` | `"env:default, service:default, region:default"` | no |
| <a name="input_docker_labels"></a> [docker\_labels](#input\_docker\_labels) | Docker labels to add to the container | `map(string)` | `{}` | no |
| <a name="input_ecs_capacity_provider"></a> [ecs\_capacity\_provider](#input\_ecs\_capacity\_provider) | Short name of the capacity provider | `string` | `"FARGATE"` | no |
| <a name="input_ecs_cluster_name"></a> [ecs\_cluster\_name](#input\_ecs\_cluster\_name) | The ECS cluster Name | `any` | n/a | yes |
| <a name="input_ecs_efs_volumes"></a> [ecs\_efs\_volumes](#input\_ecs\_efs\_volumes) | (Optional) A set of volume blocks that containers in your task may use | <pre>list(object({<br> name = string<br> efs_volume_configuration = object({<br> file_system_id = string<br> root_directory = string<br> })<br> authorization_config = object({<br> access_point_id = string<br> })<br> }))</pre> | `[]` | no |
Expand Down
9 changes: 0 additions & 9 deletions dd-agent.tf
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,4 @@ module "datadog_sidecar" {
},
]

# See https://docs.datadoghq.com/containers/docker/integrations/?tab=dockeradv2 for more information
docker_labels = {
"com.datadoghq.ad.checks" = jsonencode(
{
for entry in var.datadog_agent_integrations :
entry.name => { instances = entry.config }
}
)
}
}
10 changes: 5 additions & 5 deletions ecs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ locals {
container_image = data.external.current_image.result["image_tag"] == "not_found" ? "nginx:latest" : "${var.app_ecr_image_repo}:${data.external.current_image.result["image_tag"]}"
# container_image_version = data.external.current_image.result["image_tag"] == "not_found" ? "latest" : element(split(separator,data.external.current_image.result["image_tag"]),1)
latest_task_definition = "${aws_ecs_task_definition.app.family}:${max(aws_ecs_task_definition.app.revision, data.external.current_image.result["task_definition_revision"])}"
datadog_docker_labels = {
"com.datadoghq.tags.env" = var.environment,
"com.datadoghq.tags.service" = var.datadog_service_name == "" ? var.name : var.datadog_service_name
}
}

data "aws_ecs_cluster" "cluster" {
Expand Down Expand Up @@ -152,10 +156,7 @@ module "container_definition" {
}
] : null)

docker_labels = (var.enable_datadog_sidecar ? {
"com.datadoghq.tags.env" = var.environment,
"com.datadoghq.tags.service" = var.datadog_service_name == "" ? var.name : var.datadog_service_name
} : null)
docker_labels = var.enable_datadog_sidecar ? merge(local.datadog_docker_labels, var.docker_labels) : var.docker_labels

environment = var.enable_datadog_sidecar ? flatten(concat(var.custom_environment_variables,
[
Expand All @@ -166,7 +167,6 @@ module "container_definition" {
]
)) : var.custom_environment_variables
secrets = var.custom_environment_secrets

}

resource "aws_ecs_task_definition" "app" {

Check failure on line 172 in ecs.tf

View workflow job for this annotation

GitHub Actions / build

CKV_AWS_249: "Ensure that the Execution Role ARN and the Task Role ARN are different in ECS Task definitions"
Expand Down
15 changes: 6 additions & 9 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,12 @@ variable "service_discovery_failure_threshold" {
default = 1
}

variable "docker_labels" {
description = "Docker labels to add to the container"
type = map(string)
default = {}
}

## Datadog sidecar
variable "enable_datadog_sidecar" {
description = "Whether the datadog sidecar should be added to the task definition"
Expand Down Expand Up @@ -562,15 +568,6 @@ variable "datadog_service_name" {
default = ""
}

variable "datadog_agent_integrations" {
description = "The datadog agent integrations, see Docker (AD v2) at https://docs.datadoghq.com/containers/docker/integrations/?tab=dockeradv2"
type = list(object({
name = string
config = optional(list(map(string)), [])
}))
default = []
}

variable "datadog_tags" {
description = " Tags for datadog agent container."
type = string
Expand Down

0 comments on commit f0c0ac7

Please sign in to comment.