36 lines
1.1 KiB
Plaintext
36 lines
1.1 KiB
Plaintext
## 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 won’t be set.
|