# Reference variable value with a local variable using cidrhost

**URL:** <https://discuss.hashicorp.com/t/reference-variable-value-with-a-local-variable-using-cidrhost/61935>\
**Category:** Packer\
**Created:** [January 20, 2024, 8:20pm UTC](https://discuss.hashicorp.com/t/reference-variable-value-with-a-local-variable-using-cidrhost/61935 "2024-01-20T20:20:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lethargosapatheia](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/lethargosapatheia/32/13120_2.png) [@lethargosapatheia](https://discuss.hashicorp.com/u/lethargosapatheia)\
**Post date:** [January 20, 2024, 8:20pm UTC](https://discuss.hashicorp.com/t/reference-variable-value-with-a-local-variable-using-cidrhost/61935/1 "2024-01-20T20:20:25Z")

</div>

Hello,

I’m not sure what I’m doing wrong here. At the top of `template.pkr.hcl` (main config file that I’m running with packer) I have the following:

```auto
locals {
        internal_01_gw = cidrhost(var.internal_01, 1)
}

```

In `variables.pkr.hcl` (inside the same directory) I have this:

```auto
variable "internal_01" {
	default = "10.10.111.0/24"
	type = string
}

```

I’m running packer as follows:

```auto
 packer build -var-file="secrets.pkrvars.hcl" -var-file="values.pkrvars.hcl" template.pkr.hcl

```

But I keep getting this error:

```auto
Error: Unsupported attribute

  on template.pkr.hcl line 2:
  (source code not available)

This object does not have an attribute named "internal_01".

```

In the documentation related to variables, I see that packer is supposed to read all files ending in pkr.hcl: [Input and Local Variables guide | Packer | HashiCorp Developer](https://developer.hashicorp.com/packer/guides/hcl/variables)

That doesn’t seem to be the problem anyway, because, even if I define `internal_01` in the same file, I still get the same error, so it literally cannot find the variable and I don’t understand why. Any ideas how I can solve this?

---

<div class="post-metadata">

**Author:** ![hashicorpbro](https://avatars.discourse-cdn.com/v4/letter/h/59ef9b/32.png) [@hashicorpbro](https://discuss.hashicorp.com/u/hashicorpbro)\
**Post date:** [January 25, 2024, 12:13pm UTC](https://discuss.hashicorp.com/t/reference-variable-value-with-a-local-variable-using-cidrhost/61935/2 "2024-01-25T12:13:20Z")

</div>

You are calling your file " **variables**.pkr.hcl"  
Yet calling -var-file=“_values_.pkrvars.hcl”. Could just be a copy paste error.

I would also try the following in the locals file. Might help. Might not. Who knows.

```auto
locals { internal_01_gw = cidrhost(${var.internal_01}, 1) }
# Or
locals { internal_01_gw = cidrhost("${var.internal_01}", 1) }

```
