Reputation: 2812
Hi team when ever i do run terraform apply
it is not recreating the service task of ecs and not deploying it as well, even though i have added force deploy option as below,
resource "aws_ecs_task_definition" "pq-backend-task" {
family = "pq-backend-task"
container_definitions = jsonencode([
{
name = "pq-backend-container"
image = "${data.terraform_remote_state.infra.outputs.pq_backend_ecr_url}:latest"
cpu = 2
memory = 4096
essential = true
force_new_deployment = true
portMappings = [
{
containerPort = 80
hostPort = 0
}
]
environment : [
{
"name" : "DB_PASSWORD",
"value" : var.DB_PASSWORD
},
{
"name:" : "BUILD_NO",
"value" : var.BUILD_NO
},
]
}
])
}
In above example I have updated the environment variable of BUILD_NO, but terraform run always says as below,
No changes. Your infrastructure still matches the configuration.
, So how should I do force update? any workaround ?
Upvotes: 0
Views: 1660
Reputation: 1642
Instead of using the latest tag, use the image digest.
You can use a data block to retrieve image digest:
data "aws_ecr_image" "service_image" {
repository_name = "image-name"
image_tag = "latest"
}
Then update your container definition to: $ACCOUNT_NUMBER.dkr.ecr.$REGION.amazonaws.com/image-name:latest@${data.aws_ecr_image.service_image.image_digest}
.
Edit: You also have a typo in your container definition:
{
"name:" : "BUILD_NO",
"value" : var.BUILD_NO
},
There's an extra colon next to the name
attribute.
Upvotes: 1