Data Sources
Note: Data Sources is a feature included in Packer 1.7 and later.
Data sources allow data to be fetched or computed for use elsewhere in locals and sources configuration. Use of data sources allows a Builder to make use of information defined outside of Packer.
Using Data Sources
A data source is declared using a data block, and the configuration looks like the following:
A data block requests that Packer read from a given data source ("amazon-ami") and export the result under the given local name ("example"). The name is used to refer to this data source from elsewhere in the same Packer configuration.
The data block creates a data instance of the given type (first block label) and name (second block label). The combination of the type and name must be unique within a configuration.
Within the block (the { }
) is the configuration for the data instance. The configuration is dependent on the data source type,
and is documented for each data source. For example the configuration of the amazon-ami
data source can be found at plugins/datasources/amazon/ami.
A data source can output one or more attributes, which can be used by adding their key name to the data source unique
identifier, like data.<TYPE>.<NAME>.<ATTRIBUTE>
.
The output from the amazon-ami.example
above can be accessed as follows:
Output data:
Usage:
Known Limitations
At this present time the use of locals within data sources such as the example below is not supported.
Locals can reference data sources but data sources can not reference locals to avoid cyclic dependencies, where a local
may reference a data source that references the same local or some other locals variable. The preferred method, at this time,
for referencing user input data within a data source is to use the variable
block.
Related
- The list of available data sources can be found in the data sources section.
- Create your own custom data source !