Error: argument value is unsuitable : the "for_each" argument

Error: Invalid for_each argument

│ on line 8, in data “vault_generic_secret” “vault_additional_users_path”:
│ 8: for_each = jsondecode(var.vault_additional_users_path)
│ ├────────────────
│ │ var.vault_additional_users_path is “[{“user1”:“global/dev/tf-secrets/additional_user1”},{“user2”:“global/dev/tf-secrets/additional_user2”}]”

│ 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.

here is jscondecode output

“user1” = “global/dev/tf-secrets/additional_user1”
“user2” = “global/dev/tf-secrets/additional_user2”

The problem is that number of users are not known, also we cannot predict key names, currently it is ‘user1’, user2 but this might change.

Can you show a more complete example of what you are trying to do? The data given does show precisely how many values there are, and has hard-coded keys which could be used for instance keys. The error is explaining that the provided type is not valid, and you must convert the data to an acceptable type with which individual instances can be mapped.

If the json object values are all strings, and the keys are all unique, then these can be merged into a single map:

for_each = merge(jsondecode(var.vault_additional_users_path)...)

thanks it worked

“user1” = “global/dev/tf-secrets/additional_user1”
“user2” = “global/dev/tf-secrets/additional_user2”

You removed the ... operator from my example. That is required to expand the tuple into the individual objects in order to pass them to the merge function.

thank you yes it works!

I have started new discussion to seek help with the related issue