# Error: Invalid Index, is empty tuple, The given key does not identify an element in this collection value

**URL:** <https://discuss.hashicorp.com/t/error-invalid-index-is-empty-tuple-the-given-key-does-not-identify-an-element-in-this-collection-value/22526>\
**Category:** Terraform\
**Tags:** azure\
**Created:** [March 25, 2021, 11:55pm UTC](https://discuss.hashicorp.com/t/error-invalid-index-is-empty-tuple-the-given-key-does-not-identify-an-element-in-this-collection-value/22526 "2021-03-25T23:55:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![premal-acharya](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/premal-acharya/32/17977_2.png) [@premal-acharya](https://discuss.hashicorp.com/u/premal-acharya)\
**Post date:** [March 25, 2021, 11:55pm UTC](https://discuss.hashicorp.com/t/error-invalid-index-is-empty-tuple-the-given-key-does-not-identify-an-element-in-this-collection-value/22526/1 "2021-03-25T23:55:20Z")

</div>

Hi I am working on terrafrom verion 0.14.5 and facing error of Invalid Index followed by empty tuple. This is my code.

resource “azurerm\_lb” “lb\_app\_primary” {  
count = var.instances\_count \>= 1 ? 1 : 0  
name = “LB1”  
sku = “standard”  
location = var.location  
resource\_group\_name = var.resourcegroup  
}

resource “azurerm\_lb\_probe” “lb\_sql\_probe\_primary” {  
resource\_group\_name = var.resourcegroup  
loadbalancer\_id = azurerm\_lb.lb\_sql\_primary[0].id  
name = “SQLEndPointProbe”  
port = 1433  
interval\_in\_seconds = 10  
number\_of\_probes = 3  
}

**Variable var.instances\_count is of type number.**

When initial value of var.instances\_count is set to 0 in relevant tfvars file and I execute terraform plan -var-file=setenv.tfvars it fails with below error.

**Error: Invalid index**

\*\* on modules\CMS\loadbalancers.tf line 176, in resource “azurerm\_lb\_probe” “lb\_sql\_probe\_primary”:\*\*  
\*\* 176: loadbalancer\_id = azurerm\_lb.lb\_sql\_primary[0].id\*\*  
\*\* |----------------\*\*  
\*\* | azurerm\_lb.lb\_sql\_primary is empty tuple\*\*

**The given key does not identify an element in this collection value.**

When initial value of var.instances\_count is set to 1 in relevant tfvars file and I execute terraform plan -var-file=setenv.tfvars, everything works fine and the plan is executed.

I have a requirement to make var.instances to 0 in the tfvars file and terraform plan should execute because we don’t need certain resources to be created for every environment.

I have explored earlier posts with this forum and also tried to apply the solutions provided there but nothing has worked so far. Can you please suggest how do I eliminate this error and have my plan executed with valur ‘0’ in tfvars file.

---

<div class="post-metadata">

**Author:** ![tbugfinder](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/tbugfinder/32/12689_2.png) [@tbugfinder](https://discuss.hashicorp.com/u/tbugfinder)\
**Post date:** [March 27, 2021, 6:05pm UTC](https://discuss.hashicorp.com/t/error-invalid-index-is-empty-tuple-the-given-key-does-not-identify-an-element-in-this-collection-value/22526/2 "2021-03-27T18:05:47Z")

</div>

> [@premal-acharya](#):
>
> resource “azurerm\_lb\_probe” “lb\_sql\_probe\_primary” {

You’d have to also create this resource conditionally. So, e.g. you have to add the same count parameter.
