【发布时间】:2021-11-05 06:02:26
【问题描述】:
我目前正在使用 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 配置?
【问题讨论】:
-
每次运行的文件系统 ID 是否完全相同?您不需要对此进行审查,但这样做会给您的问题增加一些歧义。
-
嗨@ydaetskcoR,我已经检查并确认它们在每次申请时都是相同的。
标签: amazon-web-services terraform amazon-ecs terraform-provider-aws amazon-efs