title: Terraform iterate over list
body: <p>I would like to replace the 3 indepedent variables (dev_id, prod_id, stage_id), for a single list containing all the three variables, and iterate over them, applying them to the policy.</p>
  
  <p>Is this something terraform can do?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>data "aws_iam_policy_document" "iam_policy_document_dynamodb" {
    statement {
      effect    = "Allow"
      resources = ["arn:aws:dynamodb:${var.region}:${var.account_id}:table:${var.dynamodb_table_name}"]
  
      actions = [
        "dynamodb:GetItem",
        "dynamodb:PutItem",
        "dynamodb:DeleteItem",
      ]
  
      principals {
        type = "AWS"
  
        identifiers = [
          "arn:aws:iam::${var.dev_id}:root",
          "arn:aws:iam::${var.prod_id}:root",
          "arn:aws:iam::${var.stage_id}:root"
        ]
      }
    }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>I looked into cycles and interpolation, but It seems that 99% of the time the interpolation is done with "count" which only works for the creation of multiple resources (I hope I am not saying a big lie).</p>
  
  <p>For example, I used </p>
  
  <pre><code>principals {
     count = "${length(var.list)}"
     identifiers = ["arn:aws:iam::${var.list[count.index]}"]
  }
  </code></pre>
  
  <p>but that was unsuccessful. </p>
  
  <p>Is there some way of achieving the final goal of replacing those 3 variables by a single list (or map) and iterate over them?</p>