title: How do we append multiple policies in IAM policy
body: <p>I wanted to attach a couple of policies to a role, but noticed that the role can have only 10 policies attached. The below is the existing code i used to create the policies.</p>
  <pre><code>variable &quot;usernames&quot; {
    type    = list(string)
    default = [&quot;xxx&quot;,&quot;yyyy&quot;,&quot;zzz&quot;]
  }
  
  variable &quot;account_id&quot; {
    description = &quot;AWS staging account id&quot;
    type        = string
    default     = &quot;1234567890&quot;
  }
  
  data &quot;aws_iam_policy_document&quot; &quot;iam_authentication&quot; {
    for_each = toset(var.usernames)
    statement {
      effect = &quot;Allow&quot;
      actions = [
        &quot;rds-db:connect&quot;
      ]
      resources = flatten(formatlist(&quot;arn:aws:rds-db:us-east-1:%s:dbuser:%s/%s&quot;, var.account_id, module.rds.yy_resource_id, each.value))
    }
    statement {
      sid    = &quot;1&quot;
      effect = &quot;Allow&quot;
      actions = [
        &quot;rds-db:connect&quot;
      ]
      resources = flatten(formatlist(&quot;arn:aws:rds-db:us-east-1:%s:dbuser:%s/team&quot;, var.account_id, module.rds.yy_resource_id))
    }
  }
  
  resource &quot;aws_iam_policy&quot; &quot;iam_policy&quot; {
    for_each = toset(var.usernames)
    name     = &quot;iam_authentication_dev_${each.value}&quot;
    path     = &quot;/&quot;
    policy   = data.aws_iam_policy_document.iam_authentication[each.key].json
  }
  
  resource &quot;aws_iam_role_policy_attachment&quot; &quot;iam_policy_attach_to_role&quot; {
    policy_arn = aws_iam_policy.iam_policy[each.key].arn
    for_each   = toset(var.usernames)
    role       = &quot;ABC&quot;
  }
  </code></pre>
  <p>I wanted to append all the polices for all the users to a single policy and then add it to the role, in that way i can avoid the 10 limit error. How can i append / merge all policies to one policy?</p>