Files
Packer-Cn/website/content/docs/commands/validate.mdx
T
50da6c8dc8 docs: Migrate link formats (#12192)
* Adding check-legacy-links-format workflow

* Adding test-link-rewrites workflow

* Migrating links to new format

* Updating docs-content-check-legacy-links-format hash

* chore: update source

* Update generated partials from Packer plugin SDK

* Bump packer-plugin-sdk to get latest packer-sdc

* Update website/content/docs/templates/hcl_templates/blocks/build/provisioner.mdx

* Update Plugin SDK to fix shell-local regression

---------

Co-authored-by: Kendall Strautman <[email protected]>
Co-authored-by: Wilken Rivera <[email protected]>
Co-authored-by: Kendall Strautman <[email protected]>
2023-01-27 09:47:08 -08:00

74 lines
3.2 KiB
Plaintext

---
description: |
The `packer validate` Packer command is used to validate the syntax and
configuration of a template. The command will return a zero exit status on
success, and a non-zero exit status on failure. Additionally, if a template
doesn't validate, any error messages will be outputted.
page_title: packer validate - Commands
---
# `validate` Command
The `packer validate` Packer command is used to validate the syntax and
configuration of a [template](/packer/docs/templates). The command will
return a zero exit status on success, and a non-zero exit status on failure.
Additionally, if a template doesn't validate, any error messages will be
outputted.
Example usage:
```shell-session
$ packer validate my-template.pkr.hcl
Template validation failed. Errors are shown below.
Errors validating build 'vmware'. 1 error(s) occurred:
* Either a path or inline script must be specified.
```
## Options
- `-syntax-only` - Only the syntax of the template is checked. The
configuration is not validated.
- `-evaluate-datasources` - Evaluate all data sources when validating a template.
This is only valid on HCL2 templates, since JSON templates do not feature
datasources, this option will be ignored.
~> **Warning:** Data sources may rely on external services for fetching data,
which can incur some costs at validation if the services being contacted are
billing per operation.
- `-except=foo,bar,baz` - Validates all the builds except those with the
comma-separated names. In legacy JSON templates, build names default to the
types of their builders (e.g. `docker` or
`amazon-ebs` or `virtualbox-iso`), unless a specific `name` attribute is
specified within the configuration. In HCL2 templates, the "name" is the
source block's "name" label, unless an in-build source definition adds the
"name" configuration option.
- `-no-warn-on-undeclared-var` - Silence warnings when the a variable definition
file contains variable assignments for undeclared variables. This can occur
when using a var-file that contains a large amount of unused variables for a
given HCL2 template. For HCL2 template defining a value for a variable in a
var-file is not enough on its own for Packer to function, as there also needs
to be a variable block definition in the template files `pkr.hcl` for the
variable. By default `packer validate` will warn when a var-file contains one
or more undeclared variables.
- `-only=foo,bar,baz` - Only validate the builds with the given comma-separated
names. In legacy JSON templates, build names default to the
types of their builders (e.g. `docker` or
`amazon-ebs` or `virtualbox-iso`), unless a specific `name` attribute is
specified within the configuration. In HCL2 templates, the "name" is the
source block's "name" label, unless an in-build source definition adds the
"name" configuration option.
- `-machine-readable` Sets all output to become machine-readable on stdout.
Logging, if enabled, continues to appear on stderr.
- `-var` - Set a variable in your Packer template. This option can be used
multiple times. This is useful for setting version numbers for your build.
- `-var-file` - Set template variables from a file.