Skip to content

Instantly share code, notes, and snippets.

View damscott's full-sized avatar

David Scott damscott

View GitHub Profile
@damscott
damscott / ecs-service.tf
Created June 19, 2018 16:41
Using CI/CD for deployment of ECS task definitions and images causes drift between the tfstate and AWS. Using a bash script in a Terraform External Data Source to pull the current task definition revision and container image tag from AWS keeps the state in sync with changes from CI. This does not currently support multiple containers in a single…
resource "aws_ecs_service" "service" {
name = "${var.app}"
cluster = "${var.cluster}"
# Use task revision in AWS if it is greater than task revision in tfstate
# Prevents rolling back revision when it has been incremented by CI
task_definition = "${aws_ecs_task_definition.app.family}:${data.external.task_definition.result["task_definition_revision"] > aws_ecs_task_definition.app.revision ? data.external.task_definition.result["task_definition_revision"] : aws_ecs_task_definition.app.revision }"
desired_count = "${var.task_count}"
depends_on = [
"aws_ecs_task_definition.app"