title: Exclude list of numbers from Range function in Terraform
body: <p>I am trying to create a number of VMs in Azure using the for_each loop. Let's say VMs 1-100. However, there will be requests to delete i.e. VM number 50.</p>
  <p>I have 2 problems with this:</p>
  <pre><code>terraform_azure&gt; terraform state list
  module.edit_vms.azurerm_linux_virtual_machine.test_seat[&quot;test-vm-1&quot;]
  
  terraform state rm module.edit_vms.azurerm_linux_virtual_machine.test_seat[&quot;test-vm-1&quot;]
  zsh: no matches found: module.edit_vms.azurerm_linux_virtual_machine.test_seat[test-vm-1]
  </code></pre>
  <ol>
  <li><p>When I try to delete the VM 50 from Terraform state I get the error above. I don't understand why am I seeing no matches found when the resource was listed under <strong>terraform state list</strong> command</p>
  </li>
  <li><p>Is there a way to delete the VM number 50 and set the VM count from 1 -&gt; 101 and to prevent terraform from re-creating VM number 50? If deleting the VM from state file is not a good practice it would be even better if I could specify in the code that I want it destroyed and not recreated on future apply.</p>
  </li>
  </ol>
  <p>This is my variables.tf</p>
  <pre><code>variable &quot;edit_seat_spec&quot; {
      description = &quot;VM details&quot;
      type = list
      default = [{
          resource_group_name = &quot;my_rg&quot;
          server_name = &quot;test-vm&quot;
          server_size = &quot;Standard_B2s&quot;
          location = &quot;East US&quot;
          vnet = &quot;test_vnet&quot;
          subnet_name = &quot;default&quot;
          username = &quot;username&quot;
          password = &quot;password&quot;
          vm_count = &quot;4&quot;
      }]
  }
  </code></pre>
  <p>And main.tf</p>
  <pre><code>locals{
        edit_seat = [
          for edit in var.edit_seat_spec : [
            for i in range(1, edit.vm_count) : {
              name = &quot;${edit.server_name}-${i}&quot;
              resource_group = edit.resource_group_name
              vnet = edit.vnet
              nic = &quot;${edit.server_name}-${i}-nic&quot;
              location            = edit.location
              subnet_name = edit.subnet_name
              size                = edit.server_size
              admin_username      = edit.username
              admin_password = edit.password
              }
          ]
        ]
      }
      
  locals {
      edit_vm = flatten(local.edit_seat)
    }
  
      resource &quot;azurerm_linux_virtual_machine&quot; &quot;vm&quot; {
      for_each = {for edit in local.edit_vm: edit.name =&gt; edit}
              name = each.value.name
              resource_group_name = each.value.resource_group
              location            = each.value.location
              size                = each.value.size
              admin_username      = each.value.admin_username
              admin_password = each.value.admin_password
              disable_password_authentication = false
              network_interface_ids = [azurerm_network_interface.edit_seat_nic[each.key].id]
      os_disk {
      caching              = &quot;ReadWrite&quot;
      storage_account_type = &quot;Standard_LRS&quot;
      }
      
        source_image_reference {
          publisher = &quot;Canonical&quot;
          offer     = &quot;UbuntuServer&quot;
          sku       = &quot;16.04-LTS&quot;
          version   = &quot;latest&quot;
        }
      }
  </code></pre>