2020-07-24 04:58:03 -04:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/hashicorp/hcl/v2"
|
|
|
|
"github.com/hashicorp/packer/packer"
|
2021-02-02 12:05:04 -05:00
|
|
|
plugingetter "github.com/hashicorp/packer/packer/plugin-getter"
|
2020-07-24 04:58:03 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// CoreWrapper wraps a packer.Core in order to have it's Initialize func return
|
|
|
|
// a diagnostic.
|
|
|
|
type CoreWrapper struct {
|
|
|
|
*packer.Core
|
|
|
|
}
|
|
|
|
|
2021-01-20 04:37:16 -05:00
|
|
|
func (c *CoreWrapper) Initialize(_ packer.InitializeOptions) hcl.Diagnostics {
|
2020-07-24 04:58:03 -04:00
|
|
|
err := c.Core.Initialize()
|
|
|
|
if err != nil {
|
|
|
|
return hcl.Diagnostics{
|
|
|
|
&hcl.Diagnostic{
|
|
|
|
Detail: err.Error(),
|
|
|
|
Severity: hcl.DiagError,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2021-02-02 12:05:04 -05:00
|
|
|
|
|
|
|
func (c *CoreWrapper) PluginRequirements() (plugingetter.Requirements, hcl.Diagnostics) {
|
|
|
|
return nil, hcl.Diagnostics{
|
|
|
|
&hcl.Diagnostic{
|
|
|
|
Summary: "Packer init is supported for HCL2 configuration templates only",
|
|
|
|
Detail: "Please manually install plugins or use a HCL2 configuration that will do that for you.",
|
|
|
|
Severity: hcl.DiagError,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|