How to use a Resource created in another module?

Hi nmarchini,

My apologies, you are totally right. Here is the config file for the IAM role:

resource "aws_iam_role" "schengenRefugeeClouddynamicsIAMRole" {
  name = var.iamRoleName
  assume_role_policy = <<EOF
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Action": "sts:AssumeRole",
      "Principal": {
        "Service": "lambda.amazonaws.com"
      },
      "Effect": "Allow",
      "Sid": ""
    }
  ]
}
EOF
}

Resuming, my module Lambda is under folder 2_lambda, while my module IAM is under folder 3_iam. All of this is in my main config file at the root level:

module "lambda"{
    source = "./2_lambda"
    lambdaFunctionName = var.lambdaFunctionName
    role = module.iam.??????????????????
    depends_on = [module.iam, module.dynamoDB]
}

module "iam"{
    source = "./3_iam"
    iamRoleName = var.iamRoleName
    depends_on = [module.dynamoDB]
}

What do I need to pass at the root level above? And how can I use it inside my Lambda module below?

resource "aws_lambda_function" "schengenRefugeeClouddynamicsLambda" {
  function_name = var.lambdaFunctionName
  role          = ?????????????????????????????
  handler       = "exports.test"
  runtime = "nodejs12.x"
  environment {
    variables = {
      foo = "bar"
    }
  }
}

Thanks again for your help.
Peter