ESXi builds require we store the value of displayName in the statebag

The value of displayName is needed by later steps:
* When determining the IP address of the build VM
* When exporting the VM using ovftool

By default Packer will configure the VMX so `displayName` is equal to
the value defined for `vm_name` in the build template. However, it is
possible (and sometimes desirable) to set a custom value for
`displayName`.
Users can set a custom `displayName` through use of the `vmx_data`
option in their template.
This commit is contained in:
DanHam 2018-07-02 12:33:55 +01:00
parent 4b1f96b527
commit 3eab3cc99b
No known key found for this signature in database
GPG Key ID: 58E79AEDD6AA987E
1 changed files with 16 additions and 0 deletions

View File

@ -16,6 +16,9 @@ import (
//
// Uses:
// vmx_path string
//
// Produces:
// display_name string - Value of the displayName key set in the VMX file
type StepConfigureVMX struct {
CustomData map[string]string
SkipFloppy bool
@ -73,6 +76,19 @@ func (s *StepConfigureVMX) Run(_ context.Context, state multistep.StateBag) mult
return multistep.ActionHalt
}
// If the build is taking place on a remote ESX server, the displayName
// will be needed for discovery of the VM's IP address and for export
// of the VM. The displayName key should always be set in the VMX file,
// so error if we don't find it
if displayName, ok := vmxData["displayname"]; !ok { // Packer converts key names to lowercase!
err := fmt.Errorf("Error: Could not get value of displayName from VMX data")
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
} else {
state.Put("display_name", displayName)
}
return multistep.ActionContinue
}