Support named builds in HCL2 templates.

pull/9245/head
Adrienne Cohea 6 years ago
parent 170520dcca
commit 6aea8ead6a
No known key found for this signature in database
GPG Key ID: F83E59DFC2463856

@ -34,6 +34,9 @@ var buildSchema = &hcl.BodySchema{
// post-processor "" { ... }
// }
type BuildBlock struct {
// Name is a string representing the named build to show in the logs
Name string
// Sources is the list of sources that we want to start in this build block.
Sources []SourceRef
@ -56,6 +59,7 @@ func (p *Parser) decodeBuildConfig(block *hcl.Block) (*BuildBlock, hcl.Diagnosti
build := &BuildBlock{}
var b struct {
Name string `hcl:"name,optional"`
FromSources []string `hcl:"sources"`
Config hcl.Body `hcl:",remain"`
}
@ -64,6 +68,8 @@ func (p *Parser) decodeBuildConfig(block *hcl.Block) (*BuildBlock, hcl.Diagnosti
return nil, diags
}
build.Name = b.Name
for _, buildFrom := range b.FromSources {
ref := sourceRefFromString(buildFrom)

@ -353,6 +353,7 @@ func (cfg *PackerConfig) GetBuilds(opts packer.GetBuildsOptions) ([]packer.Build
}
pcb := &packer.CoreBuild{
BuildName: build.Name,
Type: src.Type,
Builder: builder,
Provisioners: provisioners,

@ -86,6 +86,7 @@ type Build interface {
// multiple files, of course, but it should be for only a single provider (such
// as VirtualBox, EC2, etc.).
type CoreBuild struct {
BuildName string
Type string
Builder Builder
BuilderConfig interface{}
@ -128,6 +129,9 @@ type CoreBuildProvisioner struct {
// Returns the name of the build.
func (b *CoreBuild) Name() string {
if b.BuildName != "" {
return b.BuildName
}
return b.Type
}

Loading…
Cancel
Save