---
description: >
  The `variable` and `input-variable` blocks define variables in your Packer configuration. Learn how to use these blocks to declare variables in your template.
page_title: variable block reference
---

# `variable` block

This topic provides reference information about the `variable` block.

## Description

The `variable` and `input-variable` blocks define variables
within your Packer configuration. You cannot use the `input-variable` block in another `input-variable` block. We recommend using the [`locals`](/packer/docs/templates/hcl_templates/blocks/locals) to nest variables instead.

`@include 'from-1.5/variables/foo-block.mdx'`

## Default value

If a default value is set, the variable is optional. Otherwise, the variable
**must** be set.

`@include 'from-1.5/variables/assignment.mdx'`

`@include 'from-1.5/variables/custom-validation.mdx'`

Example of a variable assignment from a file:

`@include 'from-1.5/variables/foo-pkrvar.mdx'`

`@include 'from-1.5/variables/must-be-set.mdx'`

`@include 'from-1.5/variables/sensitive.mdx'`

# More on variables

- Read the [full variables](/packer/docs/templates/hcl_templates/variables) description for a more
  thorough read.
- Read the [variables guide](/packer/guides/hcl/variables) for more examples.
