hcl2template

package
v1.5.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 14, 2020 License: MPL-2.0 Imports: 27 Imported by: 0

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.

Index

Constants

View Source
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

func Functions(basedir string) map[string]function.Function

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 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 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

	// 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() *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, vars map[string]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

type PostProcessorBlock struct {
	PType string
	PName string

	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
	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

type SourceRef struct {
	Type string
	Name string
}
var NoSource SourceRef

NoSource is the zero value of sourceRef, representing the absense of an source.

func (SourceRef) String

func (r SourceRef) String() string

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
	// 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
	// contains filtered or unexported fields
}

func (*Variable) GoString added in v1.5.2

func (v *Variable) GoString() string

func (*Variable) Value added in v1.5.2

func (v *Variable) Value() (cty.Value, *hcl.Diagnostic)

type Variables added in v1.5.2

type Variables map[string]*Variable

func (Variables) Values added in v1.5.2

func (variables Variables) Values() map[string]cty.Value

Directories

Path Synopsis
Code generated by "mapstructure-to-hcl2 -type MockConfig,NestedMockConfig"; DO NOT EDIT.
Code generated by "mapstructure-to-hcl2 -type MockConfig,NestedMockConfig"; DO NOT EDIT.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL