This commit is contained in:
Karthik P 2026-03-26 12:32:44 +00:00 committed by GitHub
commit a5f60e8fc0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 33 additions and 0 deletions

View file

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

View file

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

View file

@ -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() {

View file

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

View file

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

View file

@ -68,6 +68,7 @@ type Handler interface {
ConfigFixer
ConfigInspector
PluginBinaryDetector
EnforceProvisioners()
}
//go:generate enumer -type FixConfigMode