Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add datadog integration docker labels to app container instead #14

Merged
merged 2 commits into from
Dec 26, 2023
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 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
@@ -1,4 +1,4 @@
module "datadog_sidecar" {

Check failure on line 1 in dd-agent.tf

View workflow job for this annotation

GitHub Actions / build

CKV_TF_1: "Ensure Terraform module sources use a commit hash"
source = "cloudposse/ecs-container-definition/aws"
version = "v0.58.1"

Expand Down Expand Up @@ -61,13 +61,4 @@
},
]

# 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 @@
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 @@ -95,7 +99,7 @@

}

module "container_definition" {

Check failure on line 102 in ecs.tf

View workflow job for this annotation

GitHub Actions / build

CKV_TF_1: "Ensure Terraform module sources use a commit hash"
source = "cloudposse/ecs-container-definition/aws"
version = "v0.58.1"

Expand Down Expand Up @@ -152,10 +156,7 @@
}
] : 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,10 +167,9 @@
]
)) : 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"
#checkov:skip=CKV_AWS_97:
family = local.ecs_task_definition_family_name
execution_role_arn = var.create_default_role ? aws_iam_role.ecs_task_execution[0].arn : var.external_iam_role
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
Loading