title: Multiple aws_cloudformation_stack resources based on dynamic name values with Terraform
body: <p>This is a follow up to this <a href="https://stackoverflow.com/questions/63432105/create-multiple-aws-cloudformation-stack-based-on-parametrized-name-with-terrafo">question</a>
  I would like to create multiple <code>aws_cloudformation_stack</code> resources with names based on <code>git branch</code>. Git branches would be used to test different versions of <code>CloudFormation</code> stacks and can be deployed by several engineers (hence I would need to have the engineers access remote terraform state).
  I would like to ensure that each deployed branch has its stack, but when branches update code the stacks would get updated (stacks destroyed and recreated)
  One suggestion was to use <code>for_each</code> to create multiple resources.
  To do that I would probably need to write branch names to a file (before <code>terraform apply</code>, and then read it into a list variable so <code>for_each</code> could iterate over the list.</p>
  <p>However, I'd like to see if is there a better way to achieve this ?</p>
  <pre><code>resource &quot;aws_cloudformation_stack&quot; &quot;subscriptions_sam_stack&quot; {
    for_each = toset(split(&quot;,&quot;, file(&quot;deployed_git_hashes.txt&quot;)))
    name         = &quot;${var.app_name}---${var.app_env}--${each.value}&quot;
    capabilities = [&quot;CAPABILITY_NAMED_IAM&quot;, &quot;CAPABILITY_AUTO_EXPAND&quot;]
  
    template_url = &quot;https://${var.sam_bucket}.s3-${data.aws_region.current.name}.amazonaws.com/${aws_s3_bucket_object.sam_deploy_object.id}&quot;
  }
  </code></pre>
  <p><code>deployed_git_branches.txt</code> looks like this:</p>
  <pre><code>branch1, branch2, branch3
  </code></pre>