title: Terraform conditionally create AWS CloudFormation StackSet instances
body: <p>I have following <code>stask_set_instance</code> module and it works pretty will when we passes <code>var.accounts</code> from my root module.</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>instance_data = flatten([
      for account in var.accounts : [
        for region in var.regions : {
          account = account.id
          region  = region
        }
      ]
    ])
  
  resource "aws_cloudformation_stack_set_instance" "stack" {
    for_each = {
      for stack_instance in local.instance_data
    }
    account_id          = each.value.account
    region              = each.value.region
    parameter_overrides = {}
    stack_set_name      = aws_cloudformation_stack_set.stackset.name
  }</code></pre>
  </div>
  </div>
  </p>
  <p>Now I want to conditionally handle from my child module to override <code>var.stackset_parameter_overrides</code> depends on my AWS account type (You can consider type as an environment DEV | STG | PROD ).</p>
  <p>For that, now I have updated my locals variables as below. Where <code>type</code> will have the account Tag to identify the AWS account type (Environment). (I used <code>Try</code> to set type null because there is another resource block in my root module, which I cannot pass type as it use different input). But in this example, we can assume the module always get a value for type.</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>accounts = [
    {
      "id" = "11111111111"
      "status" = "ACTIVE"
      "type" = "DEV" 
    },
    {
      "id" = "222222222222"
      "status" = "ACTIVE"
      "type" = "PROD"
    }
  ]
  
  region = ["us-east-1", "us-west-2"]
  
  instance_data = flatten([
      for account in var.accounts : [
        for region in var.regions : {
          account = account.id
          type    = try(length(account.type), 0) &gt; 0 ? account.type : null
          region  = region
        }
      ]
    ])</code></pre>
  </div>
  </div>
  </p>
  <p>Now I want to know how can I conditionally override my <code>parameter_overrides</code> variable values based on the <code>type</code> varialbe. (I can pass <code>parameter_overrides</code> from a different variable from my root module). What I want to know is how to handle <code>aws_cloudformation_stack_set_instance</code> module to change this behaviour depends on the account type.</p>
  <p>We can assume <code>type</code> is equivalent to <code>DEV</code> | <code>STG</code> | <code>PROD</code>. Therefore, depends on the type, I will have to change the <code>parameter_overrides</code> values.</p>