mirror of
https://github.com/hashicorp/packer.git
synced 2026-04-21 22:26:59 -04:00
* Updating the license from MPL to Business Source License Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at https://hashi.co/bsl-blog, FAQ at https://hashi.co/license-faq, and details of the license at www.hashicorp.com/bsl. * Update copyright file headers to BUSL-1.1 --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
98 lines
2.2 KiB
Go
98 lines
2.2 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package fix
|
|
|
|
import (
|
|
"github.com/mitchellh/mapstructure"
|
|
)
|
|
|
|
// FixerVMwareCompaction adds "skip_compaction = true" to "vmware-iso" builders with incompatible disk_type_id
|
|
type FixerVMwareCompaction struct{}
|
|
|
|
func (FixerVMwareCompaction) DeprecatedOptions() map[string][]string {
|
|
return map[string][]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 {
|
|
Builders []map[string]interface{}
|
|
}
|
|
|
|
// Decode the input into our structure, if we can
|
|
var tpl template
|
|
if err := mapstructure.Decode(input, &tpl); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
for _, builder := range tpl.Builders {
|
|
builderTypeRaw, ok := builder["type"]
|
|
if !ok {
|
|
continue
|
|
}
|
|
|
|
builderType, ok := builderTypeRaw.(string)
|
|
if !ok {
|
|
continue
|
|
}
|
|
|
|
if builderType != "vmware-iso" {
|
|
continue
|
|
}
|
|
|
|
builderRemoteTypeRaw, ok := builder["remote_type"]
|
|
if !ok {
|
|
continue
|
|
}
|
|
|
|
builderRemoteType, ok := builderRemoteTypeRaw.(string)
|
|
if !ok {
|
|
continue
|
|
}
|
|
|
|
if builderRemoteType != "esx5" {
|
|
continue
|
|
}
|
|
|
|
builderDiskTypeIdRaw, ok := builder["disk_type_id"]
|
|
// set to default when this fixer was added due to incompatibility of defaults
|
|
if !ok {
|
|
builderDiskTypeId := "zeroedthick"
|
|
builder["disk_type_id"] = builderDiskTypeId
|
|
}
|
|
|
|
if ok {
|
|
builderDiskTypeId, ok := builderDiskTypeIdRaw.(string)
|
|
if !ok {
|
|
continue
|
|
}
|
|
if builderDiskTypeId == "thin" {
|
|
continue
|
|
}
|
|
}
|
|
|
|
builderSkipCompactionRaw, ok := builder["skip_compaction"]
|
|
// already verified this is not creating a "thin" disk, will need to skip_compaction
|
|
if ok {
|
|
builderSkipCompaction, ok := builderSkipCompactionRaw.(bool)
|
|
if !ok {
|
|
continue
|
|
}
|
|
if !builderSkipCompaction {
|
|
builder["skip_compaction"] = !builderSkipCompaction
|
|
}
|
|
continue
|
|
}
|
|
|
|
builderSkipCompaction := true
|
|
builder["skip_compaction"] = builderSkipCompaction
|
|
}
|
|
|
|
input["builders"] = tpl.Builders
|
|
return input, nil
|
|
}
|
|
|
|
func (FixerVMwareCompaction) Synopsis() string {
|
|
return `Adds "skip_compaction = true" to "vmware-iso" builders with incompatible disk_type_id`
|
|
}
|