Documentation ¶
Overview ¶
Package hcl2template defines code to parse hcl2 template files.
In order to configure a packer builder,provisioner, and post processor.
Checkout the files in testdata/complete/ to see what a packer config could look like.
Code generated by "mapstructure-to-hcl2 -type KeyValue,KeyValues,KeyValueFilter,NameValue,NameValues,NameValueFilter"; DO NOT EDIT.
Index ¶
- Constants
- func Functions(basedir string) map[string]function.Function
- func GetHCL2Files(filename, hclSuffix, jsonSuffix string) (hclFiles, jsonFiles []string, diags hcl.Diagnostics)
- type BuildBlock
- type Builds
- type Decodable
- type FlatKeyValue
- type FlatKeyValueFilter
- type FlatNameValue
- type FlatNameValueFilter
- type HCL2Ref
- type KeyValue
- type KeyValueFilter
- type KeyValues
- type Local
- type NameValue
- type NameValueFilter
- type NameValues
- type PackerConfig
- type Parser
- type PostProcessorBlock
- type ProvisionerBlock
- type SourceBlock
- type SourceRef
- type ValidationOptions
- type Variable
- type Variables
Constants ¶
const VarEnvPrefix = "PKR_VAR_"
Prefix your environment variables with VarEnvPrefix so that Packer can see them.
Variables ¶
This section is empty.
Functions ¶
func Functions ¶ added in v1.5.2
Functions returns the set of functions that should be used to when evaluating expressions in the receiving scope.
basedir is used with file functions and allows a user to reference a file using local path. Usually basedir is the directory in which the config file is located
func GetHCL2Files ¶ added in v1.5.2
func GetHCL2Files(filename, hclSuffix, jsonSuffix string) (hclFiles, jsonFiles []string, diags hcl.Diagnostics)
GetHCL2Files returns two slices of json formatted and hcl formatted files, hclSuffix and jsonSuffix tell which file is what. Filename can be a folder or a file.
When filename is a folder all files of folder matching the suffixes will be returned. Otherwise if filename references a file and filename matches one of the suffixes it is returned in the according slice.
Types ¶
type BuildBlock ¶ added in v1.5.0
type BuildBlock struct { // Sources is the list of sources that we want to start in this build block. Sources []SourceRef // ProvisionerBlocks references a list of HCL provisioner block that will // will be ran against the sources. ProvisionerBlocks []*ProvisionerBlock // ProvisionerBlocks references a list of HCL post-processors block that // will be ran against the artifacts from the provisioning steps. PostProcessors []*PostProcessorBlock HCL2Ref HCL2Ref }
BuildBlock references an HCL 'build' block and it content, for example :
build { sources = [ ... ] provisioner "" { ... } post-processor "" { ... } }
type Builds ¶
type Builds []*BuildBlock
type Decodable ¶
type Decodable interface {
ConfigSpec() hcldec.ObjectSpec
}
Decodable structs are structs that can tell their hcl2 ObjectSpec; this config spec will be passed to hcldec.Decode and the result will be a cty.Value. This Value can then be applied on the said struct.
type FlatKeyValue ¶ added in v1.5.6
FlatKeyValue is an auto-generated flat version of KeyValue. Where the contents of a field with a `mapstructure:,squash` tag are bubbled up.
type FlatKeyValueFilter ¶ added in v1.5.6
type FlatKeyValueFilter struct { Filters map[string]string `cty:"filters"` Filter []FlatKeyValue `cty:"filter"` }
FlatKeyValueFilter is an auto-generated flat version of KeyValueFilter. Where the contents of a field with a `mapstructure:,squash` tag are bubbled up.
func (*FlatKeyValueFilter) HCL2Spec ¶ added in v1.5.6
func (*FlatKeyValueFilter) HCL2Spec() map[string]hcldec.Spec
HCL2Spec returns the hcl spec of a KeyValueFilter. This spec is used by HCL to read the fields of KeyValueFilter. The decoded values from this spec will then be applied to a FlatKeyValueFilter.
type FlatNameValue ¶ added in v1.5.5
FlatNameValue is an auto-generated flat version of NameValue. Where the contents of a field with a `mapstructure:,squash` tag are bubbled up.
type FlatNameValueFilter ¶ added in v1.5.6
type FlatNameValueFilter struct { Filters map[string]string `cty:"filters"` Filter []FlatNameValue `cty:"filter"` }
FlatNameValueFilter is an auto-generated flat version of NameValueFilter. Where the contents of a field with a `mapstructure:,squash` tag are bubbled up.
func (*FlatNameValueFilter) HCL2Spec ¶ added in v1.5.6
func (*FlatNameValueFilter) HCL2Spec() map[string]hcldec.Spec
HCL2Spec returns the hcl spec of a NameValueFilter. This spec is used by HCL to read the fields of NameValueFilter. The decoded values from this spec will then be applied to a FlatNameValueFilter.
type HCL2Ref ¶
type HCL2Ref struct { // references DefRange hcl.Range TypeRange hcl.Range LabelsRanges []hcl.Range // remainder of unparsed body Rest hcl.Body }
HCL2Ref references to the source definition in configuration text file. It is used to tell were something was wrong, - like a warning or an error - long after it was parsed; allowing to give pointers as to where change/fix things in a file.
type KeyValue ¶ added in v1.5.6
func (*KeyValue) FlatMapstructure ¶ added in v1.5.6
FlatMapstructure returns a new FlatKeyValue. FlatKeyValue is an auto-generated flat version of KeyValue. Where the contents a fields with a `mapstructure:,squash` tag are bubbled up.
type KeyValueFilter ¶ added in v1.5.6
func (*KeyValueFilter) Empty ¶ added in v1.5.6
func (kvf *KeyValueFilter) Empty() bool
func (*KeyValueFilter) FlatMapstructure ¶ added in v1.5.6
func (*KeyValueFilter) FlatMapstructure() interface{ HCL2Spec() map[string]hcldec.Spec }
FlatMapstructure returns a new FlatKeyValueFilter. FlatKeyValueFilter is an auto-generated flat version of KeyValueFilter. Where the contents a fields with a `mapstructure:,squash` tag are bubbled up.
func (*KeyValueFilter) Prepare ¶ added in v1.5.6
func (kvf *KeyValueFilter) Prepare() []error
type Local ¶ added in v1.5.5
type Local struct { Name string Expr hcl.Expression }
Local represents a single entry from a "locals" block in a module or file. The "locals" block itself is not represented, because it serves only to provide context for us to interpret its contents.
type NameValue ¶ added in v1.5.5
func (*NameValue) FlatMapstructure ¶ added in v1.5.5
FlatMapstructure returns a new FlatNameValue. FlatNameValue is an auto-generated flat version of NameValue. Where the contents a fields with a `mapstructure:,squash` tag are bubbled up.
type NameValueFilter ¶ added in v1.5.6
type NameValueFilter struct { Filters map[string]string Filter NameValues }
func (*NameValueFilter) Empty ¶ added in v1.5.6
func (nvf *NameValueFilter) Empty() bool
func (*NameValueFilter) FlatMapstructure ¶ added in v1.5.6
func (*NameValueFilter) FlatMapstructure() interface{ HCL2Spec() map[string]hcldec.Spec }
FlatMapstructure returns a new FlatNameValueFilter. FlatNameValueFilter is an auto-generated flat version of NameValueFilter. Where the contents a fields with a `mapstructure:,squash` tag are bubbled up.
func (*NameValueFilter) Prepare ¶ added in v1.5.6
func (nvf *NameValueFilter) Prepare() []error
type NameValues ¶ added in v1.5.5
type NameValues []NameValue
type PackerConfig ¶
type PackerConfig struct { // Directory where the config files are defined Basedir string // Available Source blocks Sources map[SourceRef]*SourceBlock // InputVariables and LocalVariables are the list of defined input and // local variables. They are of the same type but are not used in the same // way. Local variables will not be decoded from any config file, env var, // or ect. Like the Input variables will. InputVariables Variables LocalVariables Variables ValidationOptions // Builds is the list of Build blocks defined in the config files. Builds Builds }
PackerConfig represents a loaded Packer HCL config. It will contain references to all possible blocks of the allowed configuration.
func (*PackerConfig) EvalContext ¶ added in v1.5.2
func (cfg *PackerConfig) EvalContext(variables map[string]cty.Value) *hcl.EvalContext
EvalContext returns the *hcl.EvalContext that will be passed to an hcl decoder in order to tell what is the actual value of a var or a local and the list of defined functions.
type Parser ¶
type Parser struct { *hclparse.Parser BuilderSchemas packer.BuilderStore ProvisionersSchemas packer.ProvisionerStore PostProcessorsSchemas packer.PostProcessorStore }
Parser helps you parse HCL folders. It will parse an hcl file or directory and start builders, provisioners and post-processors to configure them with the parsed HCL and then return a []packer.Build. Packer will use that list of Builds to run everything in order.
func (*Parser) Parse ¶
func (p *Parser) Parse(path string, varFiles []string, argVars map[string]string, onlyBuilds []string, exceptBuilds []string) ([]packer.Build, hcl.Diagnostics)
Parse will parse HCL file(s) in path. Path can be a folder or a file.
Parse will first parse variables and then the rest; so that interpolation can happen.
For each build block a packer.Build will be started, and for each builder, all provisioners and post-processors will be started.
Parse then return a slice of packer.Builds; which are what packer core uses to run builds.
type PostProcessorBlock ¶ added in v1.5.0
ProvisionerBlock references a detected but unparsed post processor
func (*PostProcessorBlock) String ¶ added in v1.5.2
func (p *PostProcessorBlock) String() string
type ProvisionerBlock ¶ added in v1.5.0
type ProvisionerBlock struct { PType string PName string PauseBefore time.Duration MaxRetries int Timeout time.Duration HCL2Ref }
ProvisionerBlock references a detected but unparsed provisioner
func (*ProvisionerBlock) String ¶ added in v1.5.2
func (p *ProvisionerBlock) String() string
type SourceBlock ¶ added in v1.5.2
type SourceBlock struct { // Type of source; ex: virtualbox-iso Type string // Given name; if any Name string // contains filtered or unexported fields }
SourceBlock references an HCL 'source' block.
func (*SourceBlock) Ref ¶ added in v1.5.2
func (source *SourceBlock) Ref() SourceRef
type SourceRef ¶
var NoSource SourceRef
NoSource is the zero value of sourceRef, representing the absense of an source.
type ValidationOptions ¶ added in v1.5.5
type ValidationOptions struct {
Strict bool
}
type Variable ¶ added in v1.5.2
type Variable struct { // CmdValue, VarfileValue, EnvValue, DefaultValue are possible values of // the variable; The first value set from these will be the one used. If // none is set; an error will be returned if a user tries to use the // Variable. CmdValue cty.Value VarfileValue cty.Value EnvValue cty.Value DefaultValue cty.Value // Cty Type of the variable. If the default value or a collected value is // not of this type nor can be converted to this type an error diagnostic // will show up. This allows us to assume that values are valid later in // code. // // When a default value - and no type - is passed in the variable // declaration, the type of the default variable will be used. This will // allow to ensure that users set this variable correctly. Type cty.Type // Common name of the variable Name string // Description of the variable Description string // When Sensitive is set to true Packer will try it best to hide/obfuscate // the variable from the output stream. By replacing the text. Sensitive bool Range hcl.Range }