I am getting the error - Inappropriate value for attribute “policy” : string required. Can you please help me.
main.tf
locals {
vendor = toset(["vendor1","vendor2"])
}
data "template_file" "landing_policy_template" {
template = file("landing_policy.json")
for_each = local.vendor
vars = {
vendor = each.key
}
}
resource "aws_iam_policy" "landing_policy" {
for_each = toset(local.vendor)
name = "vendor-${each.value}-policy"
policy = "${data.template_file.landing_policy_template[each.value]}"
}
output "policy_op" {
value = {
for k, v in data.template_file.landing_policy_template : k => v
}
}
landing_policy.json
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "ListingObjects",
"Action": [
"s3:ListBucket"
],
"Effect": "Allow",
"Resource": [
"arn:aws:s3:::test_bucket"
],
"Condition": {
"StringEquals": {
"s3:prefix": [
"${vendor}/"
],
"s3:delimiter": [
"/"
]
}
}
}
]
}