Terraform – list

In Terraform arguments can have a number of values assigned to it. These lists are surrounded by a couple of square brackets [] and are a sequence of comma-separated values. In the below example the destination_port_range in the network security group is a list of port numbers that are allowed inbound to a server.

# Create Network Security Group and rule
resource "azurerm_network_security_group" "nsg" {
  name                = "NSG"
  location            = "eastus"
  resource_group_name = azurerm_resource_group.rsg.name

  security_rule {
    name                       = "web"
    priority                   = 1001
    direction                  = "Inbound"
    access                     = "Allow"
    protocol                   = "Tcp"
    source_port_range          = "*"
    destination_port_range     = ["80","443"]
    source_address_prefix      = "*"
    destination_address_prefix = "*"
  }
}

Leave a Reply