title: Creating multiple Alias records in Terraform with for_each
body: <p>I am trying to create multiple alias DNS records in terraform using for_each. I am getting an error when specifying the name and zone ID of the Alias name. My question is how do I read from a variable defined as a set of strings? Below is my code block and variables defined:</p>
  <pre><code>    resource &quot;aws_route53_record&quot; &quot;alias_records&quot; {
        for_each = var.alias_names
        zone_id  = aws_route53_zone.zone.zone_id
        name     = each.key
        type     = &quot;A&quot;
      
        alias {
          name                   = var.alias_dns_names[each.key]
          zone_id                = var.alias_zone_ids[each.key]
          evaluate_target_health = false
        }
      }
  
      variable &quot;alias_names&quot; {
        type = set(string)
      }
      variable &quot;alias_dns_names&quot; {
        type = set(string)
      }
      variable &quot;alias_zone_ids&quot; {
        type = set(string)
      }
  </code></pre>
  <pre><code>    Error: Invalid index
  
        on alias.tf line 8, in resource &quot;aws_route53_record&quot; &quot;alias_records&quot;:
         8:     name                   = var.alias_dns_names[each.key]
      
      This value does not have any indices.
      
      
      Error: Invalid index
      
        on alias.tf line 9, in resource &quot;aws_route53_record&quot; &quot;alias_records&quot;:
         9:     zone_id                = var.alias_zone_ids[each.key]
      
      This value does not have any indices.
  </code></pre>
  <pre><code>    alias_names = [
        &quot;alias1&quot;,
        &quot;alias2&quot;,
        &quot;alias3&quot;
      }
  
      alias_dns_names = [
        &quot;alias_dns_1&quot;,
        &quot;alias_dns_2&quot;,
        &quot;alias_dns_3&quot;
      }
  
      alias_zone_ids = [
        &quot;alias_zone_1&quot;,
        &quot;alias_zone_2&quot;,
        &quot;alias_zone_3&quot;
      }
  </code></pre>