hcl2template

package
v1.4.5 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2019 License: MPL-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package hcl2template defines code to parse hcl2 template files correctly.

In order to configure a packer builder,provisioner,communicator and post processor.

Checkout the files in testdata/complete/ to see what a packer config could look like.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Artifact

type Artifact struct {
	Type string
	Name string

	DeclRange hcl.Range

	Config hcl.Body
}

func (*Artifact) Ref

func (a *Artifact) Ref() ArtifactRef

type ArtifactRef

type ArtifactRef struct {
	Type string
	Name string
}
var NoArtifact ArtifactRef

NoArtifact is the zero value of ArtifactRef, representing the absense of an artifact.

func (ArtifactRef) String

func (r ArtifactRef) String() string

type Artifacts

type Artifacts map[ArtifactRef]*Artifact

type Build

type Build struct {
	// Ordered list of provisioner groups
	ProvisionerGroups ProvisionerGroups

	// Ordered list of post-provisioner groups
	PostProvisionerGroups ProvisionerGroups

	// Ordered list of output stanzas
	Froms BuildFromList

	HCL2Ref HCL2Ref
}

type BuildFrom

type BuildFrom struct {
	// source to take config from
	Src SourceRef `hcl:"-"`

	HCL2Ref HCL2Ref
}

type BuildFromList

type BuildFromList []BuildFrom

type Builds

type Builds []*Build

type Communicator

type Communicator struct {
	// Type of communicator; ex: ssh
	Type string
	// Given name
	Name string

	Cfg interface{}

	HCL2Ref HCL2Ref
}

func (*Communicator) Ref

func (communicator *Communicator) Ref() CommunicatorRef

type CommunicatorRef

type CommunicatorRef struct {
	Type string
	Name string
}
var NoCommunicator CommunicatorRef

NoCommunicator is the zero value of CommunicatorRef, representing the absense of Communicator.

type Decodable

type Decodable interface {
	FlatMapstructure() interface{}
}

type HCL2Ref

type HCL2Ref struct {
	// reference to the source definition in configuration text file
	DeclRange hcl.Range

	// remainder of unparsed body
	Remain hcl.Body
}

reference to the source definition in configuration text file

type PackerConfig

type PackerConfig struct {
	Sources map[SourceRef]*Source

	Variables PackerV1Variables

	Builds Builds

	Communicators map[CommunicatorRef]*Communicator
}

PackerConfig represents a loaded packer config

func (*PackerConfig) ToTemplate

func (pkrCfg *PackerConfig) ToTemplate() (*template.Template, error)

func (*PackerConfig) ToV1Build

func (pkrCfg *PackerConfig) ToV1Build() PackerV1Build

type PackerV1Build

type PackerV1Build struct {
	Builders       []*template.Builder
	Provisioners   []*template.Provisioner
	PostProcessors []*template.PostProcessor
}

type PackerV1Variables

type PackerV1Variables map[string]string

func (PackerV1Variables) Variables

func (variables PackerV1Variables) Variables() map[string]*template.Variable

type Parser

type Parser struct {
	*hclparse.Parser

	ProvisionersSchemas map[string]Decodable

	PostProvisionersSchemas map[string]Decodable

	CommunicatorSchemas map[string]Decodable

	SourceSchemas map[string]Decodable
}

func (*Parser) Parse

func (p *Parser) Parse(filename string) (*PackerConfig, hcl.Diagnostics)

func (*Parser) ParseFile

func (p *Parser) ParseFile(f *hcl.File, cfg *PackerConfig) hcl.Diagnostics

ParseFile filename content into cfg.

ParseFile may be called multiple times with the same cfg on a different file.

ParseFile returns as complete a config as we can manage, even if there are errors, since a partial result can be useful for careful analysis by development tools such as text editor extensions.

type Provisioner

type Provisioner struct {
	// Cfg is a parsed config
	Cfg interface{}
}

Provisioner represents a parsed provisioner

type ProvisionerGroup

type ProvisionerGroup struct {
	CommunicatorRef CommunicatorRef

	Provisioners []Provisioner
	HCL2Ref      HCL2Ref
}

type ProvisionerGroups

type ProvisionerGroups []*ProvisionerGroup

ProvisionerGroups is a slice of provision blocks; which contains provisioners

func (ProvisionerGroups) FirstCommunicatorRef

func (pgs ProvisionerGroups) FirstCommunicatorRef() CommunicatorRef

type SelfSpecified

type SelfSpecified interface {
	HCL2Spec() map[string]hcldec.Spec
}

type Source

type Source struct {
	// Type of source; ex: virtualbox-iso
	Type string
	// Given name; if any
	Name string

	Cfg interface{}

	HCL2Ref HCL2Ref
}

A source field in an HCL file will load into the Source type.

func (*Source) Ref

func (source *Source) 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

Jump to

Keyboard shortcuts

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