CodexBloom - Programming Q&A Platform

Terraform AWS ECS task definition not updating with new container image version

👀 Views: 34 💬 Answers: 1 📅 Created: 2025-06-06
terraform aws ecs HCL

Hey everyone, I'm running into an issue that's driving me crazy. I'm encountering an issue where my Terraform configuration for an AWS ECS task definition isn't updating the container image version as expected. I have the following code snippet: ```hcl resource "aws_ecs_task_definition" "my_task" { family = "my-task-def" requires_compatibilities = ["FARGATE"] network_mode = "awsvpc" cpu = "256" memory = "512" container_definitions = jsonencode([ { name = "my-container" image = "myrepo/myimage:${var.image_tag}" essential = true portMappings = [ { containerPort = 80 hostPort = 80 protocol = "tcp" } ] } ]) } ``` I've tried updating the `image_tag` variable to a new value, but when I run `terraform apply`, it doesn't seem to recognize the change. The output indicates that no changes are required: ``` Terraform will perform the following actions: # aws_ecs_task_definition.my_task will be updated in-place ~ resource "aws_ecs_task_definition" "my_task" { id = "my-task-def:1" # (other existing attributes) # This attribute will be updated: ~ container_definitions = "..." } } Plan: 0 to add, 1 to change, 0 to destroy. ``` The resource is showing as needing an update, but the container image is not actually changing when I apply the plan. I’ve confirmed that the new value of `var.image_tag` is set correctly in my `terraform.tfvars`. I also tried changing the name of the image or the family name, but the result is the same. Is there something I'm missing about how Terraform detects changes in ECS task definitions, or is there a specific AWS limitation I should be aware of? Any guidance would be greatly appreciated! Any ideas how to fix this?