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
- Variables
- func Functions(basedir string) map[string]function.Function
- func GetHCL2Files(filename, hclSuffix, jsonSuffix string) (hclFiles, jsonFiles []string, diags hcl.Diagnostics)
- func PrintableCtyValue(v cty.Value) string
- type BuildBlock
- type Builds
- type Decodable
- type FlatKeyValue
- type FlatKeyValueFilter
- type FlatNameValue
- type FlatNameValueFilter
- type HCL2PostProcessor
- func (p *HCL2PostProcessor) ConfigSpec() hcldec.ObjectSpec
- func (p *HCL2PostProcessor) Configure(args ...interface{}) error
- func (p *HCL2PostProcessor) HCL2Prepare(buildVars map[string]interface{}) error
- func (p *HCL2PostProcessor) PostProcess(ctx context.Context, ui packer.Ui, artifact packer.Artifact) (packer.Artifact, bool, bool, error)
- type HCL2Provisioner
- func (p *HCL2Provisioner) ConfigSpec() hcldec.ObjectSpec
- func (p *HCL2Provisioner) HCL2Prepare(buildVars map[string]interface{}) error
- func (p *HCL2Provisioner) Prepare(args ...interface{}) error
- func (p *HCL2Provisioner) Provision(ctx context.Context, ui packer.Ui, c packer.Communicator, ...) error
- type HCL2Ref
- type KeyValue
- type KeyValueFilter
- type KeyValues
- type LocalBlock
- type NameValue
- type NameValueFilter
- type NameValues
- type OnlyExcept
- type PackerConfig
- func (cfg *PackerConfig) EvalContext(variables map[string]cty.Value) *hcl.EvalContext
- func (p *PackerConfig) EvaluateExpression(line string) (out string, exit bool, diags hcl.Diagnostics)
- func (p *PackerConfig) FixConfig(_ packer.FixConfigOptions) (diags hcl.Diagnostics)
- func (cfg *PackerConfig) GetBuilds(opts packer.GetBuildsOptions) ([]packer.Build, hcl.Diagnostics)
- func (cfg *PackerConfig) Initialize() hcl.Diagnostics
- func (p *PackerConfig) InspectConfig(opts packer.InspectConfigOptions) int
- 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 ¶
var PackerConsoleHelp = strings.TrimSpace(`
Packer console HCL2 Mode.
The Packer console allows you to experiment with Packer interpolations.
You may access variables and functions in the Packer config you called the
console with.
Type in the interpolation to test and hit <enter> to see the result.
"upper(var.foo.id)" would evaluate to the ID of "foo" and uppercase is, if it
exists in your config file.
"variables" will dump all available variables and their values.
To exit the console, type "exit" and hit <enter>, or use Control-C.
/!\ It is not possible to use go templating interpolation like "{{timestamp}}"
with in HCL2 mode.
`)
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.
func PrintableCtyValue ¶ added in v1.6.0
Types ¶
type BuildBlock ¶ added in v1.5.0
type BuildBlock struct { // Name is a string representing the named build to show in the logs Name string // A description of what this build does, it could be used in a inspect // call for example. Description string // 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 // PostProcessorLists references the lists of lists of HCL post-processors // block that will be run against the artifacts from the provisioning // steps. PostProcessorsLists [][]*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
type FlatKeyValue struct { Key *string `cty:"key" hcl:"key"` Value *string `cty:"value" hcl:"value"` }
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" hcl:"filters"` Filter []FlatKeyValue `cty:"filter" hcl:"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
type FlatNameValue struct { Name *string `cty:"name" hcl:"name"` Value *string `cty:"value" hcl:"value"` }
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" hcl:"filters"` Filter []FlatNameValue `cty:"filter" hcl:"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 HCL2PostProcessor ¶ added in v1.6.1
type HCL2PostProcessor struct { PostProcessor packer.PostProcessor // contains filtered or unexported fields }
HCL2PostProcessor has a reference to the part of the HCL2 body where it is defined, allowing to completely reconfigure the PostProcessor right before calling PostProcess: with contextual variables. This permits using "${build.ID}" values for example.
func (*HCL2PostProcessor) ConfigSpec ¶ added in v1.6.1
func (p *HCL2PostProcessor) ConfigSpec() hcldec.ObjectSpec
func (*HCL2PostProcessor) Configure ¶ added in v1.6.1
func (p *HCL2PostProcessor) Configure(args ...interface{}) error
func (*HCL2PostProcessor) HCL2Prepare ¶ added in v1.6.1
func (p *HCL2PostProcessor) HCL2Prepare(buildVars map[string]interface{}) error
type HCL2Provisioner ¶ added in v1.6.1
type HCL2Provisioner struct { Provisioner packer.Provisioner // contains filtered or unexported fields }
HCL2Provisioner has a reference to the part of the HCL2 body where it is defined, allowing to completely reconfigure the Provisioner right before calling Provision: with contextual variables. This permits using "${build.ID}" values for example.
func (*HCL2Provisioner) ConfigSpec ¶ added in v1.6.1
func (p *HCL2Provisioner) ConfigSpec() hcldec.ObjectSpec
func (*HCL2Provisioner) HCL2Prepare ¶ added in v1.6.1
func (p *HCL2Provisioner) HCL2Prepare(buildVars map[string]interface{}) error
func (*HCL2Provisioner) Prepare ¶ added in v1.6.1
func (p *HCL2Provisioner) Prepare(args ...interface{}) error
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 LocalBlock ¶ added in v1.6.1
type LocalBlock 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 OnlyExcept ¶ added in v1.6.0
type OnlyExcept struct { Only []string `json:"only,omitempty"` Except []string `json:"except,omitempty"` }
OnlyExcept is a struct that is meant to be embedded that contains the logic required for "only" and "except" meta-parameters.
func (*OnlyExcept) Skip ¶ added in v1.6.0
func (o *OnlyExcept) Skip(n string) bool
Skip says whether or not to skip the build with the given name.
func (*OnlyExcept) Validate ¶ added in v1.6.0
func (o *OnlyExcept) Validate() hcl.Diagnostics
Validate validates that the OnlyExcept settings are correct for a thing.
type PackerConfig ¶
type PackerConfig struct { // Directory where the config files are defined Basedir string // directory Packer was called from Cwd 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 LocalBlocks []*LocalBlock ValidationOptions // Builds is the list of Build blocks defined in the config files. Builds Builds // contains filtered or unexported fields }
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.
func (*PackerConfig) EvaluateExpression ¶ added in v1.6.0
func (p *PackerConfig) EvaluateExpression(line string) (out string, exit bool, diags hcl.Diagnostics)
func (*PackerConfig) FixConfig ¶ added in v1.6.0
func (p *PackerConfig) FixConfig(_ packer.FixConfigOptions) (diags hcl.Diagnostics)
func (*PackerConfig) GetBuilds ¶ added in v1.6.0
func (cfg *PackerConfig) GetBuilds(opts packer.GetBuildsOptions) ([]packer.Build, hcl.Diagnostics)
GetBuilds returns a list of packer Build based on the HCL2 parsed build blocks. All Builders, Provisioners and Post Processors will be started and configured.
func (*PackerConfig) Initialize ¶ added in v1.6.1
func (cfg *PackerConfig) Initialize() hcl.Diagnostics
func (*PackerConfig) InspectConfig ¶ added in v1.6.1
func (p *PackerConfig) InspectConfig(opts packer.InspectConfigOptions) int
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(filename string, varFiles []string, argVars map[string]string) (*PackerConfig, hcl.Diagnostics)
Parse will Parse all HCL files in filename. Path can be a folder or a file.
Parse will first Parse variables and then the rest; so that interpolation can happen.
Parse returns a PackerConfig that contains configuration layout of a packer build; sources(builders)/provisioners/posts-processors will not be started and their contents wont be verified; Most syntax errors will cause an error.
type PostProcessorBlock ¶ added in v1.5.0
type PostProcessorBlock struct { PType string PName string OnlyExcept OnlyExcept KeepInputArtifact *bool HCL2Ref }
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 Override map[string]interface{} OnlyExcept OnlyExcept 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 // LocalName can be set in a singular source block from a build block, it // allows to give a special name to a build in the logs. LocalName 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
func (*SourceBlock) String ¶ added in v1.6.1
func (b *SourceBlock) String() string
type SourceRef ¶
type SourceRef struct { Type string Name string // LocalName can be set in a singular source block from a build block, it // allows to give a special name to a build in the logs. LocalName string // contains filtered or unexported fields }
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 }
Source Files ¶
- decode.go
- docs.go
- functions.go
- parser.go
- types.build.from.go
- types.build.go
- types.build.post-processor.go
- types.build.provisioners.go
- types.hcl_post-processor.go
- types.hcl_provisioner.go
- types.hcl_ref.go
- types.kv.go
- types.kv.hcl2spec.go
- types.packer_config.go
- types.source.go
- types.variables.go
- utils.go
Directories ¶
Path | Synopsis |
---|---|
Code generated by "mapstructure-to-hcl2 -type MockConfig,NestedMockConfig,MockTag"; DO NOT EDIT.
|
Code generated by "mapstructure-to-hcl2 -type MockConfig,NestedMockConfig,MockTag"; DO NOT EDIT. |
Package repl provides the structs and functions necessary to run REPL for HCL2.
|
Package repl provides the structs and functions necessary to run REPL for HCL2. |