Send data ( id) between modules output.tf does not work

hi, I have 2 modules, efs module, and a farget module. at farget module ( to use an efs fs) I send efs id, using:

output “aws_efs_file_system_efs_system_id” {

value = “$(aws_efs_file_system.efs_system.id)”

}

in the main tf I am using:

module “fargate” {

source = “…/…/source/modulos/fargate”

EFS_ID= "${module.instancias_efs.aws_efs_file_system_efs_system_id}"

in the farget module, I request this value using:

efs_volume_configuration {

    file_system_id = var.EFS_ID

but it does not work:
error:

Error: ClientException: fileSystemId is not valid: $(aws_efs_file_system.efs_system.id).

if I put the value by “hand” fs-d4b0bc25 it works fine.

like workaround i am sent it to a file doing:

resource “local_file” “filecomprivate1_aza” {

content     = <<EOF

${aws_subnet.private1_aza.id}

EOF

filename = "filecomprivate1_aza2"

}

data “local_file” “foo” {

filename = "filecomprivate1_aza2"

}

and to read I am doing:

chomp(file(“filecomprivate1_aza2”)).

but it not the best solution, I would like to use EFS_ID= “${module.instancias_efs.aws_efs_file_system_efs_system_id}”

but it does not work properly, can some on helping me, please.
thanks, in advance

There are a couple of issues here that should be a quick fix!

First, it looks like you’re trying to use string interpolation here ("${some.value}"), but you have the wrong bracket. HCL interpolation uses {} brackets, not ().

Second, you don’t actually need to use interpolation here at all! You can instead directly pass the value:

output “aws_efs_file_system_efs_system_id” {
  value = aws_efs_file_system.efs_system.id
}

ok, i have change {}, thanks.

but file_system_id = var.EFS_ID

I will get

the fisrt issue was fixed:

2021-02-26T16:28:52.693Z [WARN] plugin.stdio: received EOF, stopping recv loop: err=“rpc error: code = Unavailable desc = transport is closing”
Error: ClientException: fileSystemId is not valid: 1389.

if i replace by hand variable value

file_system_id = “fs-d4b0bc25”

will work properlly, so it is not a task definition issue

My resource

resource “aws_ecs_task_definition” “ldap” {

family = var.nometaskdefenition

network_mode = “awsvpc”

requires_compatibilities = [“FARGATE”]

cpu = “256”

memory = “512”

task_role_arn = “arn:aws:iam::920768381054:role/ecs-task-definition-role”

execution_role_arn = “arn:aws:iam::920768381054:role/ecs-task-definition-role”

container_definitions = <<DEFINITION

[

  {

    "cpu": ${var.fargate_cpu},

    "memory": ${var.fargate_memory},

    "name": "jenkins-agent",

    "image": "${var.app_image}",

    "essential": true,

    "logConfiguration": {

      "logDriver": "awslogs",

      "options": {

        "awslogs-group": "/ecs/jenkins-agent",

        "awslogs-region": "us-west-1",

        "awslogs-stream-prefix": "ecs"

      }

    },

    "mountPoints": [

      {

        "sourceVolume": "efs_temp",

        "containerPath": "/efs",

        "readOnly": false

      }

    ]

  }

]

DEFINITION

volume {

  name = "efs_temp"

  efs_volume_configuration {

    file_system_id = var.EFS_ID

    root_directory = "/"

  }

}

}

module “fargate” {

source = “…/…/source/modulos/fargate”

EFS_ID= "${module.instancias_efs.aws_efs_file_system_efs_system_id}"

com_mount = 0

sem_mount = 1

nometaskdefenition = “ldap_cross”

vpc_ldap_id_p = “${module.redes.vpc_cross_id}”

fargate_cpu = “2”

fargate_memory = “512”

app_image = “920768381054.dkr.ecr.eu-west-2.amazonaws.com/opendj-ldap:1.0.2

subnet_id = “${module.redes.aws_subnet_publica_aza_id}”

}

thanks, in advance

problably the issue, it is in call the module, because if i do:(see EFS_ID= “fs-d4b0bc25”)

module “fargate” {

source = “…/…/source/modulos/fargate”

EFS_ID= “fs-d4b0bc25”

com_mount = 0

sem_mount = 1

nometaskdefenition = “ldap_cross”

vpc_ldap_id_p = “${module.redes.vpc_cross_id}”

fargate_cpu = “2”

fargate_memory = “512”

app_image = “920768381054.dkr.ecr.eu-west-2.amazonaws.com/opendj-ldap:1.0.2

subnet_id = “${module.redes.aws_subnet_publica_aza_id}”

}

the issue it is
2021-02-26T17:02:30.054Z [WARN] plugin.stdio: received EOF, stopping recv loop: err=“rpc error: code = Unavailable desc = transport is closing”
Error: ClientException: fileSystemId is not valid: 1389.

but if i replace directly in the resource, it will work properlly:
so the problem it is

( just to check the issue)
because I will do
EFS_ID= “${module.instancias_efs.aws_efs_file_system_efs_system_id}”

module “fargate” {

source = “…/…/source/modulos/fargate”

EFS_ID= “fs-d4b0bc25”

for a reason some thin it is nort work properlly using EFS_ID= “fs-d4b0bc25”

resource “aws_ecs_task_definition” “ldap” {
(…)

volume {

  name = "efs_temp"

  efs_volume_configuration {

    file_system_id = " fs-d4b0bc25"

            root_directory = "/"

  }

}

}

It’s hard to follow what the problem is. Can you reformat your posts to use code blocks?

Try removing the interpolation altogether.

EFS_ID=module.instancias_efs.aws_efs_file_system_efs_system_id

ok,

##########
begin main.tf file
#############(…)

module “instancias_efs” {
source = “…/…/source/modulos/efs”
subnet_a = 1
vpc_ldap_id_p = “{module.redes.vpc_cross_id}" subnet_ID = "{module.redes.aws_subnet_publica_aza_id}”
}

#######output.tf inside efs module
output “aws_efs_file_system_efs_system_id” {
value = “${aws_efs_file_system.efs_system.id}”
}

#######################################

module “fargate” {
source = “…/…/source/modulos/fargate”

EFS_ID= “${module.instancias_efs.aws_efs_file_system_efs_system_id}”

com_mount = 0
sem_mount = 1
nometaskdefenition = “ldap_cross”
vpc_ldap_id_p = “{module.redes.vpc_cross_id}" fargate_cpu = "2" fargate_memory = "512" app_image = "920768381054.dkr.ecr.eu-west-2.amazonaws.com/opendj-ldap:1.0.2" subnet_id = "{module.redes.aws_subnet_publica_aza_id}”

}

(…)
########################
##End

inside source = “…/…/source/modulos/fargate”

######################################

resource “aws_ecs_task_definition” “ldap” {
family = var.nometaskdefenition
network_mode = “awsvpc”
requires_compatibilities = [“FARGATE”]
cpu = “256”
memory = “512”
task_role_arn = “arn:aws:iam::920768381054:role/ecs-task-definition-role”
execution_role_arn = “arn:aws:iam::920768381054:role/ecs-task-definition-role”

container_definitions = <<DEFINITION
[…
]
DEFINITION

volume {
name = “efs_temp”
efs_volume_configuration {

    file_system_id = var.EFS_ID
            root_directory = "/"
  }

}
}

######################################

issue in terraform apply:

2021/02/26 21:45:41 [DEBUG] [aws-sdk-go]
2021-02-26T21:45:41.366Z [WARN] plugin.stdio: received EOF, stopping recv loop: err=“rpc error: code = Unavailable desc = transport is closing”

Error: InvalidParameter: 1 validation error(s) found.

  • missing required field, RegisterTaskDefinitionInput.Volumes[0].EfsVolumeConfiguration.FileSystemId.

thanks a lot

I have done troubleshooting because in my opinion could be a terraform bug, or a Jose bug :slight_smile:

troubleshooting

##############################
instead of have a dynamic value i have replaced EFS_ID= “${module.instancias_efs.aws_efs_file_system_efs_system_id}”

i am going to use existing values

EFS_ID= “fs-ca141b3b”

#################################

module “fargate” {
source = “…/…/source/modulos/fargate”
EFS_ID= "fs-ca141b3b"

com_mount = 0
sem_mount = 1
nometaskdefenition = “ldap_cross”
vpc_ldap_id_p = “{module.redes.vpc_cross_id}" fargate_cpu = "2" fargate_memory = "512" app_image = "920768381054.dkr.ecr.eu-west-2.amazonaws.com/opendj-ldap:1.0.2" subnet_id = "{module.redes.aws_subnet_publica_aza_id}”

}

the error still the same

fications complete after 1s [id=arn:aws:ecs:eu-west-2:920768381054:service/80/ldap_cross]

Error: InvalidParameter: 1 validation error(s) found.

  • missing required field, RegisterTaskDefinitionInput.Volumes[0].EfsVolumeConfiguration.FileSystemId.

#############################
other approach just to troubleshooting, if i replace the EFS id directly in the resource.
so instead of var.EFS_ID, i will put
( i had replaced var by a real value)

file_system_id = fs-ca141b3b
#################

resource “aws_ecs_task_definition” “ldap” {
family = var.nometaskdefenition
network_mode = “awsvpc”
requires_compatibilities = [“FARGATE”]
cpu = “256”
memory = “512”
task_role_arn = “arn:aws:iam::920768381054:role/ecs-task-definition-role”
execution_role_arn = “arn:aws:iam::920768381054:role/ecs-task-definition-role”

container_definitions = <<DEFINITION
[…]
DEFINITION

volume {
name = “efs_temp”
efs_volume_configuration {

    file_system_id = var.EFS_ID
            root_directory = "/"
  }

}
}

So if i put way a variable, it works.

working solution but not desirable solution ( i replace manual the real values instead of have a variable

############################
working solution without variable ( not desirable )
##################################

resource “aws_ecs_task_definition” “ldap” {
family = var.nometaskdefenition
network_mode = “awsvpc”
requires_compatibilities = [“FARGATE”]
cpu = “256”
memory = “512”
task_role_arn = “arn:aws:iam::920768381054:role/ecs-task-definition-role”
execution_role_arn = “arn:aws:iam::920768381054:role/ecs-task-definition-role”

container_definitions = <<DEFINITION
[…]
DEFINITION

volume {
name = “efs_temp”
efs_volume_configuration {

    file_system_id = "fs-ca141b3b"
            root_directory = "/"
  }

}
}

Apply complete! Resources: 3 added, 1 changed, 0 destroyed.

but is is funny, because if i put ( without “”) file_system_id = fs-ca141b3b, it does not work we should put file_system_id = “fs-ca141b3b”

So my question it is:
file_system_id = var.EFS_ID should be used “” file_system_id = “var.EFS_ID”. it does not work like this.

So have you an solution ?

thanks a lot