嗨,团队,当我运行terraform apply
时,它不会重新创建ecs的服务任务,也不会部署它,尽管我添加了如下的强制部署选项,
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
},
]
}
])
}
在上面的例子中,我已经更新了BUILD_NO的环境变量,但terraform运行总是如下所示,
No changes. Your infrastructure still matches the configuration.
,那么我应该如何进行强制更新?有什么变通办法吗?
不要使用最新的标记,而是使用图像摘要。
您可以使用数据块来检索图像摘要:
data "aws_ecr_image" "service_image" {
repository_name = "image-name"
image_tag = "latest"
}
然后将容器定义更新为:$ACCOUNT_NUMBER.dkr.ecr.$REGION.amazonaws.com/image-name:latest@${data.aws_ecr_image.service_image.image_digest}
。
编辑:您的容器定义中也有一个拼写错误:
{
"name:" : "BUILD_NO",
"value" : var.BUILD_NO
},
name
属性旁边有一个额外的冒号。