The initialization of packer core in JSON also validates that `null` variables were set, except in the case of `packer validate --syntax-only` , but after the refactor to allow to have all commands work with HCL2 and JSON this subtlety was lost. This refactors the initialisation of the core in order to allow to have `packer validate --syntax-only` not error in case a variable is not set. Since these calls are refactored this works for HCL2 too. fix #9478
26 lines
465 B
Go
26 lines
465 B
Go
package command
|
|
|
|
import (
|
|
"github.com/hashicorp/hcl/v2"
|
|
"github.com/hashicorp/packer/packer"
|
|
)
|
|
|
|
// CoreWrapper wraps a packer.Core in order to have it's Initialize func return
|
|
// a diagnostic.
|
|
type CoreWrapper struct {
|
|
*packer.Core
|
|
}
|
|
|
|
func (c *CoreWrapper) Initialize() hcl.Diagnostics {
|
|
err := c.Core.Initialize()
|
|
if err != nil {
|
|
return hcl.Diagnostics{
|
|
&hcl.Diagnostic{
|
|
Detail: err.Error(),
|
|
Severity: hcl.DiagError,
|
|
},
|
|
}
|
|
}
|
|
return nil
|
|
}
|