You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
packer/website/content/partials/from-1.5/variables/must-be-set.mdx

36 lines
1.1 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

## A variable value must be known:
Take the following variable for example:
```hcl
variable "foo" {
type = string
}
```
Here `foo` must have a known value but you can default it to `null` to make
this behavior optional :
| | no default | `default = null` | `default = "xy"` |
| :---------------------------: | :--------------------------: | :--------------: | :--------------: |
| foo unused | error, "foo needs to be set" | - | - |
| var.foo | error, "foo needs to be set" | null¹ | xy |
| `PKR_VAR_foo=yz`<br />var.foo | yz | yz | yz |
| `-var foo=yz`<br />var.foo | yz | yz | yz |
1: Null is a valid value. Packer will only error when the receiving field needs
a value, example:
```hcl
variable "example" {
type = string
default = null
}
source "example" "foo" {
arg = var.example
}
```
In the above case, as long as "arg" is optional for an "example" source, there is no error and arg wont be set.