'How can I use var in resource calling

I'm importing roles which already have been created in AWS console and unfortunately the names are strange. So in order to use those roles I am trying like this I've two IAM roles as follows

data "aws_iam_role" "reithera-rtcov201" {
  name = "exomcloudrosareitherartcov-YRX1M2GJKD6H"
}

data "aws_iam_role" "dompe-rlx0120" {
  name = "exomcloudrosadomperlx0120p-1SCGY0RG5JXFF"
}

In this file I have 2 variables as follows:

sponsor = ["reithera", "dompe"]
study   = ["rtcov201", "rlx0120"]

I'm trying in the following way, but terraform doesn't allow to use $.

data.aws_iam_role.${var.sponsor}-${var.study}.arn

Do you know any solution for this.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source