Skip to content

Instantly share code, notes, and snippets.

@melvinkcx
Created September 16, 2020 08:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save melvinkcx/b0f2086a777c067b1ac54d673458e36e to your computer and use it in GitHub Desktop.
Save melvinkcx/b0f2086a777c067b1ac54d673458e36e to your computer and use it in GitHub Desktop.
ECS Task Definition With SSM Params Injected Into `container_definition.tmpl`
[
{
"name": "your_app",
"image": "${image_repo_arn}:${image_tag}",
"essential": true,
"memoryReservation": 300,
"portMappings": [
{
"hostPort": 80,
"containerPort": 8000,
"protocol": "tcp"
}
],
"environment": ${environments}
}
]
// ...
variable "environment_variables" {
description = "Environment variables"
type = map(string)
}
resource "aws_ecs_task_definition" "cocoon" {
family = "your_app_${var.environment}"
# Ref: https://www.terraform.io/docs/configuration/functions/templatefile.html
container_definitions = templatefile("${path.module}/container_definitions.tmpl", {
image_repo_arn = data.aws_ecr_repository.your_app_repo.arn
image_tag = data.aws_ecr_image.your_app.image_tag
environments = jsonencode([for key, value in var.environment_variables: {
name: key,
value: value
}])
})
requires_compatibilities = [
"EC2"]
volume {
// ...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment