github.com/hashicorp/packer@v1.14.3/website/content/docs/commands/validate.mdx (about)

     1  ---
     2  description: |
     3    The `packer validate` command validates the syntax and
     4    configuration in a Packer template, helping you prevent errors.
     5  page_title: packer validate command reference
     6  ---
     7  
     8  # `packer validate` command reference
     9  
    10  The `packer validate` Packer command is used to validate the syntax and
    11  configuration of a [template](/packer/docs/templates). The command will
    12  return a zero exit status on success, and a non-zero exit status on failure.
    13  Additionally, if a template doesn't validate, any error messages will be
    14  outputted.
    15  
    16  Example usage:
    17  
    18  ```shell-session
    19  $ packer validate my-template.pkr.hcl
    20  Template validation failed. Errors are shown below.
    21  
    22  Errors validating build 'vmware'. 1 error(s) occurred:
    23  
    24  * Either a path or inline script must be specified.
    25  ```
    26  
    27  ## Options
    28  
    29  - `-syntax-only` - Only the syntax of the template is checked. The
    30    configuration is not validated.
    31  
    32  - `-evaluate-datasources` - Evaluate all data sources when validating a template.
    33    This is only valid on HCL2 templates, since JSON templates do not feature
    34    datasources, this option will be ignored.
    35  
    36    ~> **Warning:** Data sources may rely on external services for fetching data,
    37    which can incur some costs at validation if the services being contacted are
    38    billing per operation.
    39  
    40  - `-except=foo,bar,baz` - Validates all the builds except those with the
    41    comma-separated names. In legacy JSON templates, build names default to the
    42    types of their builders (e.g. `docker` or
    43    `amazon-ebs` or `virtualbox-iso`), unless a specific `name` attribute is
    44    specified within the configuration. In HCL2 templates, the "name" is the
    45    source block's "name" label, unless an in-build source definition adds the
    46    "name" configuration option.
    47  
    48  - `-no-warn-undeclared-var` - Silence warnings when the variable definition
    49    file contains variable assignments for undeclared variables. This can occur
    50    when using a var-file that contains a large amount of unused variables for a
    51    given HCL2 template. For HCL2 template defining a value for a variable in a
    52    var-file is not enough on its own for Packer to function, as there also needs
    53    to be a variable block definition in the template files `pkr.hcl` for the
    54    variable. By default `packer validate` will warn when a var-file contains one
    55    or more undeclared variables.
    56  
    57  - `-only=foo,bar,baz` - Only validate the builds with the given comma-separated
    58    names. In legacy JSON templates, build names default to the
    59    types of their builders (e.g. `docker` or
    60    `amazon-ebs` or `virtualbox-iso`), unless a specific `name` attribute is
    61    specified within the configuration. In HCL2 templates, the "name" is the
    62    source block's "name" label, unless an in-build source definition adds the
    63    "name" configuration option.
    64  
    65  - `-machine-readable` Sets all output to become machine-readable on stdout.
    66    Logging, if enabled, continues to appear on stderr.
    67  
    68  - `-var` - Set a variable in your Packer template. This option can be used
    69    multiple times. This is useful for setting version numbers for your build.
    70  
    71  - `-var-file` - Set template variables from a file.