title: How do I create multiple Security rules using Terraform in Azure?
body: <p>I am trying to create a Network security group with multiple security rules in it. The idea is to create a list variable (of port ranges)  and interpolate the list items in .tf file. The below script throws an error that "priority.</p>
  
  <pre><code>"Error: azurerm_network_security_group.k8hway: security_rule.0: invalid or unknown key: count"
  </code></pre>
  
  <p>Below is the Terraform code:</p>
  
  <pre><code>resource "azurerm_network_security_group" "NSG" {
    name     = "NSG-Demo"
    location = "${azurerm_resource_group.main.location}"
    resource_group_name  = "${azurerm_resource_group.main.name}"
  
    security_rule  {
        count = "${length(var.inbound_port_ranges)}"
        name                       = "sg-rule-${count.index}"
        direction                  = "Inbound"
        access                     = "Allow"
        priority                   = "(100 * (${count.index} + 1))"
        source_address_prefix      = "*"
        source_port_range          = "*"
        destination_address_prefix = "*"
        destination_port_range     = "${element(var.inbound_port_ranges, count.index)}"
        protocol                   = "TCP"
      }
  }
  </code></pre>