title: Terraform - assigning one group to each created IAM user
body: <p>How can I assign during creation of IAM users with below code to one group existing alredy in AWS?</p>
  <pre><code>resource &quot;aws_iam_user&quot; &quot;developer-accounts&quot; {
    path          = &quot;/&quot;
    for_each      = toset(var.names)
    name          = each.value
    force_destroy = true
  }
  
  resource &quot;aws_iam_user_group_membership&quot; &quot;developers-membership&quot; {
  
    user   = values(aws_iam_user.developer-accounts)[*].name
    groups = [data.aws_iam_group.developers.group_name]
  }
  </code></pre>
  <p>With above code I’m getting</p>
  <blockquote>
  <p>inappropriate value for attribute “user”: string required.</p>
  </blockquote>
  <p>Users variable used:</p>
  <pre><code>variable &quot;names&quot; {
    description = &quot;account names&quot;
    type        = list(string)
    default     = [&quot;user-1&quot;, &quot;user-2&quot;, &quot;user-3&quot;,...etc]
  }
  </code></pre>
  <p>2nd part of question. With below I want to create passwords for each users:</p>
  <pre><code>resource &quot;aws_iam_user_login_profile&quot; &quot;devs_login&quot; {
    for_each                = toset(var.names)
    user                    = each.value
    pgp_key                 = &quot;keybase:macdrorepo&quot;
    password_reset_required = true
  }
  </code></pre>
  <p>Output:</p>
  <pre><code>output &quot;all_passwordas&quot; {
    value = values(aws_iam_user_login_profile.devs_login)[*].encrypted_password
  }
  </code></pre>
  <p>How can I decode the passwords? Below is not working as I'm sure missing some kind of loop...</p>
  <blockquote>
  <p>terraform output all_passwordas | base64 --decode | keybase pgp
  decrypt</p>
  </blockquote>