Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions command/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
20 changes: 20 additions & 0 deletions hcl2template/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package hcl2template

import (
"fmt"
"log"
"os"
"path/filepath"
"reflect"
Expand Down Expand Up @@ -568,6 +569,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 {
Expand Down
1 change: 1 addition & 0 deletions hcl2template/types.build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
5 changes: 5 additions & 0 deletions hcl2template/types.build.provisioners.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package hcl2template

import (
"fmt"
"log"
"strconv"
"time"

Expand All @@ -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 {
Expand Down Expand Up @@ -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
}

Expand Down
3 changes: 3 additions & 0 deletions packer/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions packer/run_interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type Handler interface {
ConfigFixer
ConfigInspector
PluginBinaryDetector
EnforceProvisioners()
}

//go:generate enumer -type FixConfigMode
Expand Down
Loading