<p>I am new to Terraform and learning.
I have to provide two roles in a resource block(builtin and custom), is this supported in terraform?</p>
<pre><code>variable &quot;role_definition_id&quot; {
  type = list(string)
  description = &quot;Role definition id&quot;
  default = [&quot;READER&quot;, &quot;Custom_role&quot;]
}

resource &quot;azurerm_role_assignment&quot; &quot;example&quot; {
  for_each = toset(local.principal_ids)
  scope = data.azurerm_subscription.primary.id
  role_definition_name = var.role_definition_id
  principal_id = each.key
}
</code></pre>
<p>error:</p>
<pre><code> Error: Incorrect attribute value type
│
│   on namespace/main.tf line 109, in resource &quot;azurerm_role_assignment&quot; &quot;example&quot;:
│  109:   role_definition_name = var.role_definition_id
│     ├────────────────
│     │ var.role_definition_id is a list of dynamic, known only after apply
│
│ Inappropriate value for attribute &quot;role_definition_name&quot;: string required.
</code></pre>
<p>I am already using for_each to pull in a list of principal_ids within the resource block, so I am wondering if there is a way to set this in a loop, so both the roles are applicable to the concerned principal_id.</p>
<p>I am unable to see any good example where there are multiple roles in a resource block..
Any suggestions?</p>

<p><code>role_definition_name</code> should be <strong>string</strong>,not a list. You can try the following:</p>
<pre><code>resource &quot;azurerm_role_assignment&quot; &quot;example&quot; {
  for_each = {for idx, value in toset(local.principal_ids): idx=&gt;value}
  scope = data.azurerm_subscription.primary.id
  role_definition_name = element(var.role_definition_id, each.key)
  principal_id = each.value.id
}
</code></pre>
<p>The exact form depends on how <code>local.principal_ids</code> defined, but sadly you are not providing such information in the question.</p>
