我使用terraform创建多个任务定义,其中一个任务定义有多个卷,但是当我尝试从这个错误中创建时,是否可以通过terraform在一个任务中创建多个卷?因为根据法律,这是可能的。但是地形显示了这个错误。
Error: ClientException:当指定卷参数时,只能使用一种卷配置类型
我搜索了整个互联网来找到这个问题,但没有找到答案,因为我已经在terraform文档中使用了等于这个的动态卷。
terraform {
required_version = ">= 0.13.0"
required_providers {
aws = "~> 3.0"
}
}
variable "task_definition_names" {
type = any
default = [
{
task_definition_name = "jenkins"
task_definition_file = "jenkins-task-definition.json"
shared_memory_size = 64
cpu = 0
memory_reservation = 3900
entrypoint = ""
ecr_repository_name = "jenkins:lts"
dns = "jenkins.com.br"
hosted_zone = ""
allowed_volumes = true
volume = [
{
name = "efs-jenkins"
host_path = "/var/jenkins_home"
efs_volume_configuration = [{
file_system_id = "fs-"
root_directory = "/"
transit_encryption = "ENABLED"
authorization_config = [{
access_point_id = "fsap-"
iam = "ENABLED"
}]
}]
},
{
name = "docker-sock"
host_path = "/var/run/docker.sock"
},
{
name = "docker-bin"
host_path = "/usr/bin/docker"
}
]
},
{
task_definition_name = "staging-api"
task_definition_file = "staging-api-task-definition.json"
shared_memory_size = 64
cpu = 0
memory_reservation = 900
entrypoint = ""
ecr_repository_name = "staging-api"
allowed_volumes = false
volume = []
}
]
}
resource "aws_ecs_task_definition" "main" {
count = length(var.task_definition_names)
family = var.task_definition_names[count.index].task_definition_name
container_definitions = templatefile("${path.module}/templates/${var.task_definition_names[count.index].task_definition_file}", var.task_definition_names[count.index])
dynamic "volume" {
for_each = var.task_definition_names[count.index].volume
content {
host_path = lookup(volume.value, "host_path", null)
name = volume.value.name
dynamic "efs_volume_configuration" {
for_each = lookup(volume.value, "efs_volume_configuration", [])
content {
file_system_id = lookup(efs_volume_configuration.value, "file_system_id", null)
root_directory = lookup(efs_volume_configuration.value, "root_directory", null)
transit_encryption = lookup(efs_volume_configuration.value, "transit_encryption", null)
transit_encryption_port = lookup(efs_volume_configuration.value, "transit_encryption_port", null)
dynamic "authorization_config" {
for_each = lookup(efs_volume_configuration.value, "authorization_config", [])
content {
access_point_id = lookup(authorization_config.value, "access_point_id", null)
iam = lookup(authorization_config.value, "iam", null)
}
}
}
}
}
}
}
此脚本用于创建多个任务定义。
我在使用awscli时遇到了同样的问题,但是在配置中删除对host
和host_path
的任何引用为我解决了这个问题。
不知道你想做什么,但你可以有只有一个efs_volume_configuration
。但是,您正在尝试创建efs_volume_configuration
的多个实例作为动态块:
dynamic "efs_volume_configuration"
此外,无论您在控制台中做什么,都必须与其他内容相关,否则AWS控制台使您看起来可以做到这一点。但是在底层,不能这样做.
失败的原因是您只能按照文档指定docker卷或绑定挂载:
https://docs.aws.amazon.com/AmazonECS/latest/developerguide/docker-volumes.html和
https://docs.aws.amazon.com/AmazonECS/latest/developerguide/bind-mounts.html在上面的例子中,我认为你不能将host_path
与动态块dynamic "efs_volume_configuration" {
结合在一起
如果您删除host_path
(这是绑定挂载特定的),它应该工作。