We will config ECS Task through this json template file. It contains necessary variables for ECS Task. All of them will be tranfered through Terraform variables. Our purpose is making Terraform controlling everything:
We only just to copy and save it into ./templates/ecs_container.json.tpl
file, if you want to modify the variable name, please change inside Terraform resources data.template_file.container_template too:
[
{
"name": "${container_name}",
"image": "${app_image}",
"essential": true,
"cpu": ${fargate_cpu},
"memory": ${fargate_memory},
"networkMode": "awsvpc",
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "/ecs/web-app-logs",
"awslogs-create-group": "true",
"awslogs-region": "${aws_region}",
"awslogs-stream-prefix": "ecs"
}
},
"portMappings": [
{
"containerPort": ${container_port},
"hostPort": ${host_port},
"protocol": "tcp"
}
]
}
]
More on AWS documents:
Finally, we completely prepare stage for Terraform. Please save it and go to next step.