Packer Settings
Note: This page is about HCL2 Packer templates. HCL2 templates were first introduced as a beta feature into Packer version 1.5. As of v1.7, HCL2 support is no longer in beta, and is the preferred way to write Packer configuration. For the old-style stable configuration language see template docs. As of v1.6.2, you can convert your legacy JSON template into an HCL2 config file using the hcl2_upgrade command.
Note: The packer
block is only available in Packer v1.6.5 and later.
The packer
configuration block type is used to configure some
behaviors of Packer itself, such as the minimum required Packer version needed to
apply your configuration.
Packer Block Syntax
Packer settings are gathered together into packer
blocks:
packer {
# ...
}
Each packer
block can contain a number of settings related to Packer's
behavior. Within a packer
block, only constant values can be used;
arguments may not refer to named objects such as resources, input variables,
etc, and may not use any of the Packer language built-in functions.
The various options supported within a packer
block are described in the
following sections.
Specifying a Required Packer Version
The required_version
setting accepts a version constraint
string, which specifies which versions of Packer
can be used with your configuration.
If the running version of Packer doesn't match the constraints specified, Packer will produce an error and exit without taking any further actions.
Use Packer version constraints in a collaborative environment to ensure that everyone is using a specific Packer version, or using at least a minimum Packer version that has behavior expected by the configuration.
Specifying Plugin Requirements
Note: The required_plugins
block is only available in Packer v1.7.0 and
later.
The required_plugins
block specifies all of the plugins required by the
current config, mapping each local plugin name to a source address and a
version constraint.
packer {
required_plugins {
happycloud = {
version = ">= 2.7.0"
source = "github.com/hashicorp/happycloud"
}
}
}
For more information, see Plugins.
Version Constraints
Anywhere that Packer lets you specify a range of acceptable versions for something, it expects a specially formatted string known as a version constraint.
Version Constraint Syntax
Packer's syntax for version constraints is very similar to the syntax used by other dependency management systems like Bundler and NPM.
required_version = ">= 1.2.0, < 2.0.0"
A version constraint is a string literal containing one or more conditions, which are separated by commas.
Each condition consists of an operator and a version number.
Version numbers should be a series of numbers separated by periods (like
1.2.0
), optionally with a suffix to indicate a beta release.
The following operators are valid:
=
(or no operator): Allows only one exact version number. Cannot be combined with other conditions.!=
: Excludes an exact version number.>
,>=
,<
,<=
: Comparisons against a specified version, allowing versions for which the comparison is true. "Greater-than" requests newer versions, and "less-than" requests older versions.~>
: Allows the specified version, plus newer versions that only increase the most specific segment of the specified version number. For example,~> 0.9
is equivalent to>= 0.9, < 1.0
, and~> 0.8.4
, is equivalent to>= 0.8.4, < 0.9
. This is usually called the pessimistic constraint operator.
Version Constraint Behavior
A version number that meets every applicable constraint is considered acceptable.
Packer consults version constraints to determine whether it has acceptable versions of itself.
A prerelease version is a version number that contains a suffix introduced by
a dash, like 1.2.0-beta
. A prerelease version can be selected only by an
exact version constraint (the =
operator or no operator). Prerelease
versions do not match inexact operators such as >=
, ~>
, etc.