update fixer interface to return a list of deprecated options, if any

This commit is contained in:
Megan Marsh 2020-05-28 14:37:29 -07:00
parent b28059c0a5
commit 21e9bef202
33 changed files with 135 additions and 2 deletions

View File

@ -2,6 +2,12 @@ package fix
// A Fixer is something that can perform a fix operation on a template.
type Fixer interface {
// DeprecatedOptions returns the name(s) of the option(s) being replaced in
// this fixer. It is used to generate a list of deprecated options that the
// template parser checks against to warn users that they need to call
// `packer fix` against their templates after upgrading.
DeprecatedOptions() []string
// Fix takes a raw map structure input, potentially transforms it
// in some way, and returns the new, transformed structure. The
// Fix method is allowed to mutate the input.

View File

@ -10,6 +10,10 @@ import (
// with the clearer "ena_support". This disambiguates ena_support from sriov_support.
type FixerAmazonEnhancedNetworking struct{}
func (FixerAmazonEnhancedNetworking) DeprecatedOptions() []string {
return []string{"enhanced_networking"}
}
func (FixerAmazonEnhancedNetworking) Fix(input map[string]interface{}) (map[string]interface{}, error) {
// Our template type we'll use for this fixer only
type template struct {

View File

@ -12,6 +12,10 @@ import (
// true` with `"ssh_interface": "private_ip"`
type FixerAmazonPrivateIP struct{}
func (FixerAmazonPrivateIP) DeprecatedOptions() []string {
return []string{"ssh_private_ip"}
}
func (FixerAmazonPrivateIP) Fix(input map[string]interface{}) (map[string]interface{}, error) {
type template struct {
Builders []map[string]interface{}

View File

@ -10,6 +10,10 @@ import (
// template in a Amazon builder
type FixerAmazonShutdownBehavior struct{}
func (FixerAmazonShutdownBehavior) DeprecatedOptions() []string {
return []string{"shutdown_behaviour"}
}
func (FixerAmazonShutdownBehavior) Fix(input map[string]interface{}) (map[string]interface{}, error) {
// The type we'll decode into; we only care about builders
type template struct {

View File

@ -4,10 +4,14 @@ import (
"github.com/mitchellh/mapstructure"
)
// FixerAmazonSpotPriceProductDeprecation removes the deprecated "vhd_temp_path" setting
// FixerAmazonSpotPriceProductDeprecation removes the deprecated "spot_price_auto_product" setting
// from Amazon builder templates
type FixerAmazonSpotPriceProductDeprecation struct{}
func (FixerAmazonSpotPriceProductDeprecation) DeprecatedOptions() []string {
return []string{"spot_price_auto_product"}
}
func (FixerAmazonSpotPriceProductDeprecation) Fix(input map[string]interface{}) (map[string]interface{}, error) {
// The type we'll decode into; we only care about builders
type template struct {

View File

@ -8,6 +8,10 @@ import (
type FixerAmazonTemporarySecurityCIDRs struct{}
func (FixerAmazonTemporarySecurityCIDRs) DeprecatedOptions() []string {
return []string{}
}
func (FixerAmazonTemporarySecurityCIDRs) Fix(input map[string]interface{}) (map[string]interface{}, error) {
// Our template type we'll use for this fixer only
type template struct {

View File

@ -11,6 +11,10 @@ import (
// calls with "clean_resource_name"
type FixerCleanImageName struct{}
func (FixerCleanImageName) DeprecatedOptions() []string {
return []string{"clean_image_name", "clean_ami_name"}
}
func (FixerCleanImageName) Fix(input map[string]interface{}) (map[string]interface{}, error) {
// Our template type we'll use for this fixer only
type template struct {

View File

@ -10,6 +10,11 @@ import (
// for variables host_port_min, host_port_max, skip_nat_mapping
type FixerCommConfig struct{}
func (FixerCommConfig) DeprecatedOptions() []string {
return []string{"ssh_host_port_min", "ssh_host_port_max",
"ssh_skip_nat_mapping"}
}
func (FixerCommConfig) Fix(input map[string]interface{}) (map[string]interface{}, error) {
type template struct {
Builders []interface{}

View File

@ -10,6 +10,10 @@ import (
// calls with "{{timestamp}"
type FixerCreateTime struct{}
func (FixerCreateTime) DeprecatedOptions() []string {
return []string{}
}
func (FixerCreateTime) Fix(input map[string]interface{}) (map[string]interface{}, error) {
// Our template type we'll use for this fixer only
type template struct {

View File

@ -4,6 +4,10 @@ import "github.com/mitchellh/mapstructure"
type FixerDockerEmail struct{}
func (FixerDockerEmail) DeprecatedOptions() []string {
return []string{"login_email"}
}
func (FixerDockerEmail) Fix(input map[string]interface{}) (map[string]interface{}, error) {
if input["post-processors"] == nil {
return input, nil

View File

@ -8,6 +8,10 @@ import (
// environment variables and replace galaxycommand with galaxy_command
type FixerGalaxyCommand struct{}
func (FixerGalaxyCommand) DeprecatedOptions() []string {
return []string{"galaxycommand"}
}
func (FixerGalaxyCommand) Fix(input map[string]interface{}) (map[string]interface{}, error) {
type template struct {
Provisioners []interface{}

View File

@ -8,6 +8,10 @@ import (
// it with "clone_from_vmcx_path" in Hyper-V VMCX builder templates
type FizerHypervCPUandRAM struct{}
func (FizerHypervCPUandRAM) DeprecatedOptions() []string {
return []string{"cpu", "ram_size"}
}
func (FizerHypervCPUandRAM) Fix(input map[string]interface{}) (map[string]interface{}, error) {
// The type we'll decode into; we only care about builders
type template struct {

View File

@ -8,6 +8,10 @@ import (
// from Hyper-V ISO builder templates
type FixerHypervDeprecations struct{}
func (FixerHypervDeprecations) DeprecatedOptions() []string {
return []string{"vhd_temp_path"}
}
func (FixerHypervDeprecations) Fix(input map[string]interface{}) (map[string]interface{}, error) {
// The type we'll decode into; we only care about builders
type template struct {

View File

@ -8,6 +8,10 @@ import (
// it with "clone_from_vmcx_path" in Hyper-V VMCX builder templates
type FixerHypervVmxcTypo struct{}
func (FixerHypervVmxcTypo) DeprecatedOptions() []string {
return []string{"clone_from_vmxc_path"}
}
func (FixerHypervVmxcTypo) Fix(input map[string]interface{}) (map[string]interface{}, error) {
// The type we'll decode into; we only care about builders
type template struct {

View File

@ -8,6 +8,10 @@ import (
// "iso_checksum_type" to put everything in the checksum field.
type FixerISOChecksumTypeAndURL struct{}
func (FixerISOChecksumTypeAndURL) DeprecatedOptions() []string {
return []string{"iso_checksum_url", "iso_checksum_type"}
}
func (FixerISOChecksumTypeAndURL) Fix(input map[string]interface{}) (map[string]interface{}, error) {
// Our template type we'll use for this fixer only
type template struct {

View File

@ -8,6 +8,10 @@ import (
// with the newer "iso_checksum" and "iso_checksum_type" within builders.
type FixerISOMD5 struct{}
func (FixerISOMD5) DeprecatedOptions() []string {
return []string{"iso_md5"}
}
func (FixerISOMD5) Fix(input map[string]interface{}) (map[string]interface{}, error) {
// Our template type we'll use for this fixer only
type template struct {

View File

@ -9,6 +9,10 @@ import (
// "guest_os_type", possibly overwriting any existing "guest_os_type"
type FixerParallelsDeprecations struct{}
func (FixerParallelsDeprecations) DeprecatedOptions() []string {
return []string{"parallels_tools_host_path", "guest_os_distribution"}
}
func (FixerParallelsDeprecations) Fix(input map[string]interface{}) (map[string]interface{}, error) {
// The type we'll decode into; we only care about builders
type template struct {

View File

@ -7,6 +7,10 @@ import (
// FixerParallelsHeadless removes "headless" from a template in a Parallels builder
type FixerParallelsHeadless struct{}
func (FixerParallelsHeadless) DeprecatedOptions() []string {
return []string{"headless"}
}
func (FixerParallelsHeadless) Fix(input map[string]interface{}) (map[string]interface{}, error) {
// The type we'll decode into; we only care about builders
type template struct {

View File

@ -10,6 +10,10 @@ import (
// environment variables and elevated username and password strings
type FixerPowerShellEscapes struct{}
func (FixerPowerShellEscapes) DeprecatedOptions() []string {
return []string{}
}
func (FixerPowerShellEscapes) Fix(input map[string]interface{}) (map[string]interface{}, error) {
type template struct {
Provisioners []interface{}

View File

@ -9,6 +9,10 @@ import (
// FixerDockerTagtoTags renames tag to tags
type FixerDockerTagtoTags struct{}
func (FixerDockerTagtoTags) DeprecatedOptions() []string {
return []string{"tag"}
}
func (FixerDockerTagtoTags) Fix(input map[string]interface{}) (map[string]interface{}, error) {
if input["post-processors"] == nil {
return input, nil

View File

@ -7,6 +7,10 @@ import (
// FixerManifestFilename renames any Filename to Output
type FixerManifestFilename struct{}
func (FixerManifestFilename) DeprecatedOptions() []string {
return []string{"filename"}
}
func (FixerManifestFilename) Fix(input map[string]interface{}) (map[string]interface{}, error) {
if input["post-processors"] == nil {
return input, nil

View File

@ -7,6 +7,10 @@ import "github.com/mitchellh/mapstructure"
// as part of Packer 0.5.0.
type FixerVagrantPPOverride struct{}
func (FixerVagrantPPOverride) DeprecatedOptions() []string {
return []string{}
}
func (FixerVagrantPPOverride) Fix(input map[string]interface{}) (map[string]interface{}, error) {
if input["post-processors"] == nil {
return input, nil

View File

@ -9,6 +9,10 @@ import (
// FixerQEMUDiskSize updates disk_size from a string to int for QEMU builders
type FixerQEMUDiskSize struct{}
func (FixerQEMUDiskSize) DeprecatedOptions() []string {
return []string{}
}
func (FixerQEMUDiskSize) Fix(input map[string]interface{}) (map[string]interface{}, error) {
type template struct {
Builders []map[string]interface{}

View File

@ -8,6 +8,10 @@ import (
// to "organization_id".
type FixerScalewayAccessKey struct{}
func (FixerScalewayAccessKey) DeprecatedOptions() []string {
return []string{"access_key"}
}
func (FixerScalewayAccessKey) Fix(input map[string]interface{}) (map[string]interface{}, error) {
// The type we'll decode into; we only care about builders
type template struct {

View File

@ -7,6 +7,10 @@ import (
// FixerSSHTimout replaces ssh_wait_timeout with ssh_timeout
type FixerSSHTimout struct{}
func (FixerSSHTimout) DeprecatedOptions() []string {
return []string{"ssh_wait_timeout"}
}
func (FixerSSHTimout) Fix(input map[string]interface{}) (map[string]interface{}, error) {
type template struct {
Builders []interface{}

View File

@ -8,6 +8,10 @@ import (
// to "ssh_disable_agent_forwarding".
type FixerSSHDisableAgent struct{}
func (FixerSSHDisableAgent) DeprecatedOptions() []string {
return []string{"ssh_disable_agent"}
}
func (FixerSSHDisableAgent) Fix(input map[string]interface{}) (map[string]interface{}, error) {
// The type we'll decode into; we only care about builders
type template struct {

View File

@ -8,6 +8,10 @@ import (
// to "ssh_private_key_file".
type FixerSSHKeyPath struct{}
func (FixerSSHKeyPath) DeprecatedOptions() []string {
return []string{"ssh_key_path"}
}
func (FixerSSHKeyPath) Fix(input map[string]interface{}) (map[string]interface{}, error) {
// The type we'll decode into; we only care about builders
type template struct {

View File

@ -8,6 +8,10 @@ import (
// to "guest_additions_mode".
type FixerVirtualBoxGAAttach struct{}
func (FixerVirtualBoxGAAttach) DeprecatedOptions() []string {
return []string{"guest_additions_attach"}
}
func (FixerVirtualBoxGAAttach) Fix(input map[string]interface{}) (map[string]interface{}, error) {
// The type we'll decode into; we only care about builders
type template struct {

View File

@ -7,6 +7,10 @@ import (
// FixerVirtualBoxRename changes "virtualbox" builders to "virtualbox-iso"
type FixerVirtualBoxRename struct{}
func (FixerVirtualBoxRename) DeprecatedOptions() []string {
return []string{}
}
func (FixerVirtualBoxRename) Fix(input map[string]interface{}) (map[string]interface{}, error) {
type template struct {
Builders []map[string]interface{}

View File

@ -7,6 +7,10 @@ import (
// FixerVMwareCompaction adds "skip_compaction = true" to "vmware-iso" builders with incompatible disk_type_id
type FixerVMwareCompaction struct{}
func (FixerVMwareCompaction) DeprecatedOptions() []string {
return []string{}
}
func (FixerVMwareCompaction) Fix(input map[string]interface{}) (map[string]interface{}, error) {
// The type we'll decode into; we only care about builders
type template struct {

View File

@ -4,9 +4,13 @@ import (
"github.com/mitchellh/mapstructure"
)
// FixerVMwareRename changes "virtualbox" builders to "virtualbox-iso"
// FixerVMwareRename changes "vmware" builders to "vmware-iso"
type FixerVMwareRename struct{}
func (FixerVMwareRename) DeprecatedOptions() []string {
return []string{}
}
func (FixerVMwareRename) Fix(input map[string]interface{}) (map[string]interface{}, error) {
// The type we'll decode into; we only care about builders
type template struct {

View File

@ -8,6 +8,10 @@ import (
// changes the disk_size, disk_thin_provisioned, and disk_eagerly_scrub into a storage adapter
type FixerVSphereNetworkDisk struct{}
func (FixerVSphereNetworkDisk) DeprecatedOptions() []string {
return []string{"network_card", "network", "networkCard"}
}
func (FixerVSphereNetworkDisk) Fix(input map[string]interface{}) (map[string]interface{}, error) {
// The type we'll decode into; we only care about builders
type template struct {

View File

@ -377,6 +377,8 @@ func Parse(r io.Reader) (*Template, error) {
rawTpl.Comments = append(rawTpl.Comments, comment)
continue
}
// Check for whether any of these keys are handled in a packer fix
// call.
err = multierror.Append(err, fmt.Errorf(
"Unknown root level key in template: '%s'", unused))