# Error: argument value is unsuitable : the "for\_each" argument

**URL:** <https://discuss.hashicorp.com/t/error-argument-value-is-unsuitable-the-for-each-argument/40101>\
**Category:** Terraform\
**Tags:** vault\
**Created:** [May 27, 2022, 1:23pm UTC](https://discuss.hashicorp.com/t/error-argument-value-is-unsuitable-the-for-each-argument/40101 "2022-05-27T13:23:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ahmad.x.aftab](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/ahmad.x.aftab/32/27200_2.png) [@ahmad.x.aftab](https://discuss.hashicorp.com/u/ahmad.x.aftab)\
**Post date:** [May 27, 2022, 1:23pm UTC](https://discuss.hashicorp.com/t/error-argument-value-is-unsuitable-the-for-each-argument/40101/1 "2022-05-27T13:23:24Z")

</div>

Error: Invalid for\_each argument  
│  
│ on secret\_manager.tf 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

> jsondecode(“[{"user1":"global/dev/tf-secrets/additional\_user1"},{"user2":"global/dev/tf-secrets/additional\_user2"}]”)  
> [  
> {  
> “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.

---

<div class="post-metadata">

**Author:** ![jbardin](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/jbardin/32/3325_2.png) [@jbardin](https://discuss.hashicorp.com/u/jbardin)\
**Post date:** [May 27, 2022, 1:56pm UTC](https://discuss.hashicorp.com/t/error-argument-value-is-unsuitable-the-for-each-argument/40101/2 "2022-05-27T13:56:36Z")

</div>

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:

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

```

---

<div class="post-metadata">

**Author:** ![ahmad.x.aftab](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/ahmad.x.aftab/32/27200_2.png) [@ahmad.x.aftab](https://discuss.hashicorp.com/u/ahmad.x.aftab)\
**Post date:** [May 27, 2022, 2:49pm UTC](https://discuss.hashicorp.com/t/error-argument-value-is-unsuitable-the-for-each-argument/40101/3 "2022-05-27T14:49:00Z")

</div>

thanks it worked

merge(jsondecode("[{“user1”:“global/dev/tf-secrets/additional\_user1”},{“user2”:“global/dev/tf-secrets/additional\_user2”}]")…)  
{  
“user1” = “global/dev/tf-secrets/additional\_user1”  
“user2” = “global/dev/tf-secrets/additional\_user2”  
}

---

<div class="post-metadata">

**Author:** ![jbardin](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/jbardin/32/3325_2.png) [@jbardin](https://discuss.hashicorp.com/u/jbardin)\
**Post date:** [May 27, 2022, 3:05pm UTC](https://discuss.hashicorp.com/t/error-argument-value-is-unsuitable-the-for-each-argument/40101/4 "2022-05-27T15:05:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ahmad.x.aftab](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/ahmad.x.aftab/32/27200_2.png) [@ahmad.x.aftab](https://discuss.hashicorp.com/u/ahmad.x.aftab)\
**Post date:** [May 27, 2022, 3:10pm UTC](https://discuss.hashicorp.com/t/error-argument-value-is-unsuitable-the-for-each-argument/40101/5 "2022-05-27T15:10:47Z")

</div>

thank you yes it works!

---

<div class="post-metadata">

**Author:** ![ahmad.x.aftab](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/ahmad.x.aftab/32/27200_2.png) [@ahmad.x.aftab](https://discuss.hashicorp.com/u/ahmad.x.aftab)\
**Post date:** [May 27, 2022, 3:30pm UTC](https://discuss.hashicorp.com/t/error-argument-value-is-unsuitable-the-for-each-argument/40101/6 "2022-05-27T15:30:54Z")

</div>

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