我目前正在使用 AWS ECS 进行服务部署。对于共享卷,我绑定了一些 EFS 卷。
这是我的任务定义:
resource "aws_ecs_task_definition" "ecs-fargate" {
family = var.ecs_task_definition_name
container_definitions = var.container_definitions
requires_compatibilities = ["FARGATE"]
network_mode = "awsvpc"
cpu = var.ecs_task_cpu
memory = var.ecs_task_memory
execution_role_arn = var.ecs_task_execution_role_arn
task_role_arn = var.ecs_task_role_arn
dynamic "volume" {
for_each = var.volumes
content {
name = volume.value["name"]
efs_volume_configuration {
file_system_id = volume.value["file_system_id"]
}
}
}
}
var "volumes" {
default = [
{
name = "vol1"
file_system_id = "fs-xxxxxxxx"
},
{
name = "vol2"
file_system_id = "fs-xxxxxxxx"
}
]
}
上面的 Terraform 代码也可以正常工作。
但是当我terraform apply每次都这样做时,任务定义首先分离 EFS 卷并再次重新附加相同的卷。这是问题的屏幕截图:
- volume {
- name = "vol1" -> null
- efs_volume_configuration {
- file_system_id = "fs-xxxxxxx" -> null
- root_directory = "/" -> null
}
}
+ volume {
+ name = "vol1"
+ efs_volume_configuration {
+ file_system_id = "fs-xxxxxx"
+ root_directory = "/"
}
}
对于上述问题,我是否在这里遗漏了一些额外的 Terraform 配置?