Hello, I’m glad to join this community
Here is my issue, Im trying to deploy an ECS Service, using a task definition resource, to this task definition i am passing my container definitions as a templatefile from a JSON:
resource “aws_ecs_task_definition” “datadog” {
family = “gyn-${terraform.workspace}”
container_definitions = templatefile(“datadog_definitions.json”, {
workspace = terraform.workspace
repository_url = aws_ecr_repository.datadog_repo.repository_url
build_number = var.build_number
local = local.envVar.DD_API_KEY
})
memory = 512
network_mode = “bridge”
requires_compatibilities = [“EC2”]
}
This is my JSON:
{
“family”: “gyn-datadog-dev”,
“containerDefinitions”: [
{
“name”: “datadog-agent”,
“image”: “datadog/agent:latest”,
“cpu”: 10,
“memory”: 256,
“portMappings”: ,
“essential”: true,
“environment”: [
{
“name”: “DD_SITE”,
“value”: “datadoghq.com”
},
{
“name”: “DD_API_KEY”,
“value”: “${local}”
}
],
“mountPoints”: [
{
“sourceVolume”: “docker_sock”,
“containerPath”: “/var/run/docker.sock”,
“readOnly”: true
},
{
“sourceVolume”: “cgroup”,
“containerPath”: “/host/sys/fs/cgroup”,
“readOnly”: true
},
{
“sourceVolume”: “proc”,
“containerPath”: “/host/proc”,
“readOnly”: true
}
],
“volumesFrom”:
}
],
“volumes”: [
{
“name”: “docker_sock”,
“host”: {
“sourcePath”: “/var/run/docker.sock”
}
},
{
“name”: “proc”,
“host”: {
“sourcePath”: “/proc/”
}
},
{
“name”: “cgroup”,
“host”: {
“sourcePath”: “/sys/fs/cgroup/”
}
}
]
}
When i try to run it, I find the error:
│ Error: ECS Task Definition container_definitions is invalid: Error decoding JSON: json: cannot unmarshal string into Go value of type *ecs.ContainerDefinition
Thinking it was the JSON, i modified it according to some answers in other sites: ECS Task Definition Fails · Issue #5467 · hashicorp/terraform · GitHub, since this is the original one : https://docs.datadoghq.com/json/datadog-agent-ecs.json?_gl=1*1i8qkvq*_ga*OTQ3NzQxNTUxLjE2NzgyMjA0MDU.*_ga_KN80RDFSQK*MTY3ODM3MzIyMS41LjEuMTY3ODM3MzcxMC42MC4wLjA.&_ga=2.156307197.798254626.1678220406-947741551.1678220405
However, the problem continues.
Regardless of the JSON, I tried creating the resources manually in the AWS console, and they worked, So, I’m almost sure this is something related to the way i am passing the container definitions JSON to the task definition in terraform.
I would be glad if anyone could help me with this as fast as possible.
Thanks