I use terraform to create multiple tasks definitions and one of these tasks definitions has multiple volumes but when I try to create from this error, is it possible to create multiple volumes in a task by terraform? because by aws it is possible. But the terraform shows this error.
Error: ClientException: When the volume parameter is specified, only one volume configuration type should be used
I searched the entire internet to find this problem and didn't find an answer, as I'm already using the dynamic volume equal to this in the terraform documentation.
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)
}
}
}
}
}
}
}
This script is for create multiple task-definitions.