mirror of
https://github.com/hashicorp/packer.git
synced 2026-06-08 16:22:15 -04:00
Merge 62b30f577d into 33740b7c61
This commit is contained in:
commit
a5f60e8fc0
6 changed files with 33 additions and 0 deletions
|
|
@ -125,6 +125,9 @@ func (c *BuildCommand) RunContext(buildCtx context.Context, cla *BuildArgs) int
|
|||
defer hcpRegistry.VersionStatusSummary()
|
||||
|
||||
err := hcpRegistry.PopulateVersion(buildCtx)
|
||||
|
||||
packerStarter.EnforceProvisioners()
|
||||
|
||||
if err != nil {
|
||||
return writeDiags(c.Ui, nil, hcl.Diagnostics{
|
||||
&hcl.Diagnostic{
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ package hcl2template
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
|
|
@ -567,6 +568,25 @@ func (cfg *PackerConfig) Initialize(opts packer.InitializeOptions) hcl.Diagnosti
|
|||
return diags
|
||||
}
|
||||
|
||||
func (cfg *PackerConfig) EnforceProvisioners() {
|
||||
// Fetch enforced provisioners from the HCP Packer registry.
|
||||
// Parse the raw HCL configuration into ProvisionerBlock objects.
|
||||
// Append the enforced provisioners to the build's execution plan.
|
||||
|
||||
// for point of POC, i just created a Global variable for a provisioner block thats mentioned in the template
|
||||
// we reattach the provisioner block to each build block. And as you can see,
|
||||
//we are able to run "an enforced provisioner"
|
||||
|
||||
if GlobalProvisioner != nil {
|
||||
log.Printf("SETTING THE GLOBAL PROVISIONER\n")
|
||||
for _, build := range cfg.Builds {
|
||||
build.ProvisionerBlocks = append(build.ProvisionerBlocks, GlobalProvisioner)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// parseConfig looks in the found blocks for everything that is not a variable
|
||||
// block.
|
||||
func (p *Parser) parseConfig(f *hcl.File, cfg *PackerConfig) hcl.Diagnostics {
|
||||
|
|
|
|||
|
|
@ -180,6 +180,7 @@ func (p *Parser) decodeBuildConfig(block *hcl.Block, cfg *PackerConfig) (*BuildB
|
|||
}
|
||||
build.Sources = append(build.Sources, ref)
|
||||
case buildProvisionerLabel:
|
||||
|
||||
p, moreDiags := p.decodeProvisioner(block, ectx)
|
||||
diags = append(diags, moreDiags...)
|
||||
if moreDiags.HasErrors() {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ package hcl2template
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
|
|
@ -15,6 +16,8 @@ import (
|
|||
"github.com/zclconf/go-cty/cty"
|
||||
)
|
||||
|
||||
var GlobalProvisioner *ProvisionerBlock
|
||||
|
||||
// OnlyExcept is a struct that is meant to be embedded that contains the
|
||||
// logic required for "only" and "except" meta-parameters.
|
||||
type OnlyExcept struct {
|
||||
|
|
@ -163,6 +166,8 @@ func (p *Parser) decodeProvisioner(block *hcl.Block, ectx *hcl.EvalContext) (*Pr
|
|||
provisioner.Timeout = timeout
|
||||
}
|
||||
|
||||
log.Printf("STORING PROVISIONER IN GLOBAL VARIABE")
|
||||
GlobalProvisioner = provisioner
|
||||
return provisioner, diags
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -162,6 +162,9 @@ func (c *Core) Initialize(_ InitializeOptions) hcl.Diagnostics {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
func (c *Core) EnforceProvisioners() {
|
||||
log.Printf("******* INSIDE ENFORCE PROVISIONERS FROM CORE.. ********\n")
|
||||
}
|
||||
|
||||
func (core *Core) initialize() error {
|
||||
if err := core.validate(); err != nil {
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@ type Handler interface {
|
|||
ConfigFixer
|
||||
ConfigInspector
|
||||
PluginBinaryDetector
|
||||
EnforceProvisioners()
|
||||
}
|
||||
|
||||
//go:generate enumer -type FixConfigMode
|
||||
|
|
|
|||
Loading…
Reference in a new issue