2020-05-26 09:29:47 -04:00
|
|
|
|
## A variable value must be known:
|
|
|
|
|
|
|
|
|
|
Take the following variable for example:
|
|
|
|
|
|
|
|
|
|
```hcl
|
|
|
|
|
variable "foo" {
|
|
|
|
|
type = string
|
2020-10-14 16:35:21 -04:00
|
|
|
|
}
|
2020-05-26 09:29:47 -04:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2020-07-13 06:33:16 -04:00
|
|
|
|
In the above case, as long as "arg" is optional for an "example" source, there is no error and arg won’t be set.
|