* Update validate command to use FixConfig for checking against known fixers * Update validation command flag docs * Add ConfigFixer method to PackerHandler Interface * Implement ConfigFixer interface in PackerConfig * Remove all stdout messaging (i.e calls to c.Ui.Say) in the validate command. The command will only display hcl.Diagnotic messaging when there is an error or warning. HCL2 Configs ``` ⇶ packer validate docker_centos_shell_provisioner.pkr.hcl ``` JSON Configs ``` ⇶ packer validate vmware-iso_ubuntu_minimal/vmware-iso_ubuntu_minimal.json Error: Failed to prepare build: "vmware-iso" 1 error occurred: * Deprecated configuration key: 'iso_checksum_type'. Please call `packer fix` against your template to update your template to be compatable with the current version of Packer. Visit https://www.packer.io/docs/commands/fix/ for more detail. Warning: Fixable configuration found. You may need to run `packer fix` to get your build to run correctly. See debug log for more information. map[string]interface{}{ "builders": []interface{}{ map[string]interface{}{ ... // 3 identical entries "guest_os_type": string("ubuntu-64"), "http_directory": string("http"), - "iso_checksum": string("946a6077af6f5f95a51f82fdc44051c7aa19f9cfc5f737954845a6050543d7c2"), + "iso_checksum": string("sha256:946a6077af6f5f95a51f82fdc44051c7aa19f9cfc5f737954845a6050543d7c2"), - "iso_checksum_type": string("sha256"), "iso_url": string("http://old-releases.ubuntu.com/releases/14.04.1/ubuntu-14.04.1-server-amd64.iso"), "shutdown_command": string("echo 'vagrant' | sudo -S shutdown -P now"), ... // 4 identical entries }, }, } ```
55 lines
1.4 KiB
Go
55 lines
1.4 KiB
Go
package packer
|
|
|
|
import "github.com/hashicorp/hcl/v2"
|
|
|
|
type GetBuildsOptions struct {
|
|
// Get builds except the ones that match with except and with only the ones
|
|
// that match with Only. When those are empty everything matches.
|
|
Except, Only []string
|
|
Debug, Force bool
|
|
OnError string
|
|
}
|
|
|
|
type BuildGetter interface {
|
|
// GetBuilds return all possible builds for a config. It also starts all
|
|
// builders.
|
|
// TODO(azr): rename to builder starter ?
|
|
GetBuilds(GetBuildsOptions) ([]Build, hcl.Diagnostics)
|
|
}
|
|
|
|
type Evaluator interface {
|
|
// EvaluateExpression is meant to be used in the `packer console` command.
|
|
// It parses the input string and returns what needs to be displayed. In
|
|
// case of an error the error should be displayed.
|
|
EvaluateExpression(expr string) (output string, exit bool, diags hcl.Diagnostics)
|
|
}
|
|
|
|
// The packer.Handler handles all Packer things.
|
|
type Handler interface {
|
|
Evaluator
|
|
BuildGetter
|
|
ConfigFixer
|
|
}
|
|
|
|
//go:generate enumer -type FixConfigMode
|
|
type FixConfigMode int
|
|
|
|
const (
|
|
// Stdout will make FixConfig simply print what the config should be; it
|
|
// will only work when a single file is passed.
|
|
Stdout FixConfigMode = iota
|
|
// Inplace fixes your files on the spot.
|
|
Inplace
|
|
// Diff shows a full diff.
|
|
Diff
|
|
)
|
|
|
|
type FixConfigOptions struct {
|
|
Mode FixConfigMode
|
|
}
|
|
|
|
type ConfigFixer interface {
|
|
// FixConfig will output the config in a fixed manner.
|
|
FixConfig(FixConfigOptions) hcl.Diagnostics
|
|
}
|