github.com/hashicorp/packer@v1.14.3/website/content/partials/from-1.5/variables/must-be-set.mdx (about)

     1  ## A variable value must be known:
     2  
     3  Take the following variable for example:
     4  
     5  ```hcl
     6  variable "foo" {
     7    type = string
     8  }
     9  ```
    10  
    11  Here `foo` must have a known value but you can default it to `null` to make
    12  this behavior optional :
    13  
    14  |                               |          no default          | `default = null` | `default = "xy"` |
    15  | :---------------------------: | :--------------------------: | :--------------: | :--------------: |
    16  |          foo unused           | error, "foo needs to be set" |        -         |        -         |
    17  |            var.foo            | error, "foo needs to be set" |      null¹       |        xy        |
    18  | `PKR_VAR_foo=yz`<br />var.foo |              yz              |        yz        |        yz        |
    19  |  `-var foo=yz`<br />var.foo   |              yz              |        yz        |        yz        |
    20  
    21  1: Null is a valid value. Packer will only error when the receiving field needs
    22  a value, example:
    23  
    24  ```hcl
    25  variable "example" {
    26    type = string
    27    default = null
    28  }
    29  
    30  source "example" "foo" {
    31    arg = var.example
    32  }
    33  ```
    34  
    35  In the above case, as long as "arg" is optional for an "example" source, there is no error and arg won’t be set.