github.com/hashicorp/packer@v1.14.3/fix/fixer_parallels_headless.go (about)

     1  // Copyright (c) HashiCorp, Inc.
     2  // SPDX-License-Identifier: BUSL-1.1
     3  
     4  package fix
     5  
     6  import (
     7  	"github.com/mitchellh/mapstructure"
     8  )
     9  
    10  // FixerParallelsHeadless removes "headless" from a template in a Parallels builder
    11  type FixerParallelsHeadless struct{}
    12  
    13  func (FixerParallelsHeadless) DeprecatedOptions() map[string][]string {
    14  	return map[string][]string{
    15  		"packer.parallels": []string{"headless"},
    16  	}
    17  }
    18  
    19  func (FixerParallelsHeadless) Fix(input map[string]interface{}) (map[string]interface{}, error) {
    20  	// The type we'll decode into; we only care about builders
    21  	type template struct {
    22  		Builders []map[string]interface{}
    23  	}
    24  
    25  	// Decode the input into our structure, if we can
    26  	var tpl template
    27  	if err := mapstructure.Decode(input, &tpl); err != nil {
    28  		return nil, err
    29  	}
    30  
    31  	for _, builder := range tpl.Builders {
    32  		builderTypeRaw, ok := builder["type"]
    33  		if !ok {
    34  			continue
    35  		}
    36  
    37  		builderType, ok := builderTypeRaw.(string)
    38  		if !ok {
    39  			continue
    40  		}
    41  
    42  		if builderType != "parallels-iso" && builderType != "parallels-pvm" {
    43  			continue
    44  		}
    45  
    46  		_, ok = builder["headless"]
    47  		if !ok {
    48  			continue
    49  		}
    50  
    51  		delete(builder, "headless")
    52  	}
    53  
    54  	input["builders"] = tpl.Builders
    55  	return input, nil
    56  }
    57  
    58  func (FixerParallelsHeadless) Synopsis() string {
    59  	return `Removes unused "headless" from Parallels builders`
    60  }