For some reason a data lookup is being considered a variable and I get an error message that “variables may not be used here”
variables.tf
variable "permission_sets" {
description = "Map containing Permission Set names as keys."
default = ""
}
main.tf
module "sso" {
source = "../../../modules/permission-sets"
permission_sets = var.permission_sets
}
data.tf
data "aws_iam_policy_document" "default_nonprod_inline_policy" {
statement { #do not modify this statement
sid = "inlineadditional"
###delete permissions below allow roleback for CDK deployments###
actions = [
"iam:AttachRolePolicy",
"iam:DetachRolePolicy",
"iam:CreatePolicy",
"iam:CreateRole",
"iam:DeleteRole",
"iam:CreatePolicyVersion",
"iam:DeletePolicyVersion",
"iam:CreateRolePolicy",
"iam:DeleteRolePolicy",
"iam:PutRolePolicy",
"iam:TagRole",
"iam:TagPolicy",
"iam:PassRole",
]
resources = [
"*"
]
}
statement {
sid = "denyIdentityCenter"
effect = "Deny"
actions = [ "sso:*", "sso-directory:*" ]
resources = ["*"]
}
}
test.auto.tfvars
permission_sets = {
architecture-nonprod = {
description = "Provides read and write access to nonprod accounts for the domain.",
session_duration = "PT12H",
managed_policies = ["arn:aws:iam::aws:policy/PowerUserAccess", "arn:aws:iam::aws:policy/ReadOnlyAccess"]
inline_policy = data.aws_iam_policy_document.default_nonprod_inline_policy.json
principal_name = "App-AWS_SSO-SolutionArchitecture-nonprod"
principal_type = "GROUP"
account_names = ["removed"]
},
}
error
I currently have the variable set as above but i get the same when I have each strictly defined as below:
variable "permission_sets" {
description = "Map containing Permission Set names as keys."
type = map(object({
description = string
session_duration = string
managed_policies = list(string)
inline_policy = any
principal_name = string
principal_type = string
account_names = list(string)
}))
}
I am not trying to pass a variable but this is the message I get. I have tried putting the data source in “${data_source}” but that didn’t work either.
I have not format errors in my linting. I have browsed the forum but others have had similar issues when actually passing a variable into their variable. I am not trying to do this (that I am aware of). I am probably overlooking something simple but can’t see it at the moment. Would appreciate any help.