Variables not allowed

Hello,

in vars.tf :

variable "iam_roles_policies_team" {
  description = "IAM Policy to be attached to role"
  type        = map(list(string))
  default = {
    "DS" : [
      aws_iam_policy.test.arn,
    ]
  }
}

in policy.tf:


resource "aws_iam_policy" "test" {
  description = "Allows IAM users to manage their own password ..."
  name = "UserSecurity"
  path = "/"
  policy = file("policy/usersecurity.json")
}

throws:
terraform apply

│ Error: Variables not allowed

│ on vars.tf line 57, in variable “iam_roles_policies_team”:
│ 57: aws_iam_policy.test.arn,

│ Variables may not be used here.

Question:
what is the proper way to build out policies and assign policies to the groups/roles if I can’t specify them (policies) in the vars ?

Thank you
AZ

You cannot use a resource within an input variable. You might have to set a different default (hardcoded) and add some logic in e.g. locals to switch it to test.arn.