Created
September 16, 2020 08:55
-
-
Save melvinkcx/b0f2086a777c067b1ac54d673458e36e to your computer and use it in GitHub Desktop.
ECS Task Definition With SSM Params Injected Into `container_definition.tmpl`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"name": "your_app", | |
"image": "${image_repo_arn}:${image_tag}", | |
"essential": true, | |
"memoryReservation": 300, | |
"portMappings": [ | |
{ | |
"hostPort": 80, | |
"containerPort": 8000, | |
"protocol": "tcp" | |
} | |
], | |
"environment": ${environments} | |
} | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
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