I’m trying to get my terraform for perform a for_each argument, but getting the below error;
The given "for_each" argument value is unsuitable: the "for_each" argument must be a map, or set of strings, and you have provided a value of type tuple.
My code looks like;
sns.tf
resource "aws_sns_topic" "jobs-sns" {
for_each = local.sns-topic
sqs_success_feedback_sample_rate = "100"
}
locals.tf
locals {
sns-topic = [
"jobs-sns00",
"jobs-sns01",
"jobs-sns02",
"jobs-sns03",
"jobs-sns04"
]
Almost there with the code, feels like a real simple thing I’m missing
Thanks
2
Answers
I ended up changing the for_each in the sns.tf to;
Worked ok and picked up the correct values
There are two options. The first one is probably the one to make your code work faster. You would only need to do the following:
Note that the built-in
toset
function is used [1] (set mentioned in the error). Alternatively, you could change your local variable a bit. Instead of this:You would do something like (map mentioned in the error):
This is because the
for_each
meta-argument [1] is working with variables which are key value pairs. The one you have is a list of values. Make sure to understand howfor_each
works before using it.[1] https://www.terraform.io/language/functions/toset
[2] https://www.terraform.io/language/meta-arguments/for_each