2019-05-31 08:27:41 -04:00
|
|
|
//go:generate struct-markdown
|
|
|
|
|
2013-12-27 10:37:39 -05:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
2018-11-07 12:42:03 -05:00
|
|
|
"fmt"
|
2014-10-28 11:37:12 -04:00
|
|
|
"os"
|
2013-12-27 10:37:39 -05:00
|
|
|
|
2020-11-11 13:21:37 -05:00
|
|
|
"github.com/hashicorp/packer/packer-plugin-sdk/template/interpolate"
|
2013-12-27 10:37:39 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type DriverConfig struct {
|
2020-03-24 11:16:25 -04:00
|
|
|
// When set to true, Packer will cleanup the cache folder where the ISO file is stored during the build on the remote machine.
|
|
|
|
// By default, this is set to false.
|
|
|
|
CleanUpRemoteCache bool `mapstructure:"cleanup_remote_cache" required:"false"`
|
2019-05-28 11:50:58 -04:00
|
|
|
// Path to "VMware Fusion.app". By default this is
|
2019-06-06 10:29:25 -04:00
|
|
|
// /Applications/VMware Fusion.app but this setting allows you to
|
|
|
|
// customize this.
|
|
|
|
FusionAppPath string `mapstructure:"fusion_app_path" required:"false"`
|
2019-05-28 11:50:58 -04:00
|
|
|
// The type of remote machine that will be used to
|
2019-06-06 10:29:25 -04:00
|
|
|
// build this VM rather than a local desktop product. The only value accepted
|
|
|
|
// for this currently is esx5. If this is not set, a desktop product will
|
|
|
|
// be used. By default, this is not set.
|
|
|
|
RemoteType string `mapstructure:"remote_type" required:"false"`
|
2019-05-28 11:50:58 -04:00
|
|
|
// The path to the datastore where the VM will be stored
|
2019-06-06 10:29:25 -04:00
|
|
|
// on the ESXi machine.
|
|
|
|
RemoteDatastore string `mapstructure:"remote_datastore" required:"false"`
|
2019-05-28 11:50:58 -04:00
|
|
|
// The path to the datastore where supporting files
|
2019-06-06 10:29:25 -04:00
|
|
|
// will be stored during the build on the remote machine.
|
|
|
|
RemoteCacheDatastore string `mapstructure:"remote_cache_datastore" required:"false"`
|
2019-05-28 11:50:58 -04:00
|
|
|
// The path where the ISO and/or floppy files will
|
2019-06-06 10:29:25 -04:00
|
|
|
// be stored during the build on the remote machine. The path is relative to
|
|
|
|
// the remote_cache_datastore on the remote machine.
|
|
|
|
RemoteCacheDirectory string `mapstructure:"remote_cache_directory" required:"false"`
|
2019-05-28 11:50:58 -04:00
|
|
|
// The host of the remote machine used for access.
|
2019-06-06 10:29:25 -04:00
|
|
|
// This is only required if remote_type is enabled.
|
|
|
|
RemoteHost string `mapstructure:"remote_host" required:"false"`
|
2019-05-28 11:50:58 -04:00
|
|
|
// The SSH port of the remote machine
|
2019-06-06 10:29:25 -04:00
|
|
|
RemotePort int `mapstructure:"remote_port" required:"false"`
|
2019-05-28 11:50:58 -04:00
|
|
|
// The SSH username used to access the remote machine.
|
2019-06-06 10:29:25 -04:00
|
|
|
RemoteUser string `mapstructure:"remote_username" required:"false"`
|
2019-05-28 11:50:58 -04:00
|
|
|
// The SSH password for access to the remote machine.
|
2019-06-06 10:29:25 -04:00
|
|
|
RemotePassword string `mapstructure:"remote_password" required:"false"`
|
2019-05-28 11:50:58 -04:00
|
|
|
// The SSH key for access to the remote machine.
|
2019-06-06 10:29:25 -04:00
|
|
|
RemotePrivateKey string `mapstructure:"remote_private_key_file" required:"false"`
|
2019-05-28 11:50:58 -04:00
|
|
|
// When Packer is preparing to run a
|
2019-06-06 10:29:25 -04:00
|
|
|
// remote esxi build, and export is not disable, by default it runs a no-op
|
|
|
|
// ovftool command to make sure that the remote_username and remote_password
|
|
|
|
// given are valid. If you set this flag to true, Packer will skip this
|
|
|
|
// validation. Default: false.
|
|
|
|
SkipValidateCredentials bool `mapstructure:"skip_validate_credentials" required:"false"`
|
2013-12-27 10:37:39 -05:00
|
|
|
}
|
|
|
|
|
2015-05-27 17:16:28 -04:00
|
|
|
func (c *DriverConfig) Prepare(ctx *interpolate.Context) []error {
|
2020-09-11 10:46:33 -04:00
|
|
|
var errs []error
|
|
|
|
|
2014-10-28 11:21:39 -04:00
|
|
|
if c.FusionAppPath == "" {
|
|
|
|
c.FusionAppPath = os.Getenv("FUSION_APP_PATH")
|
|
|
|
}
|
2013-12-27 10:37:39 -05:00
|
|
|
if c.FusionAppPath == "" {
|
|
|
|
c.FusionAppPath = "/Applications/VMware Fusion.app"
|
|
|
|
}
|
2017-02-06 02:13:37 -05:00
|
|
|
if c.RemoteUser == "" {
|
|
|
|
c.RemoteUser = "root"
|
|
|
|
}
|
|
|
|
if c.RemoteDatastore == "" {
|
|
|
|
c.RemoteDatastore = "datastore1"
|
|
|
|
}
|
|
|
|
if c.RemoteCacheDatastore == "" {
|
|
|
|
c.RemoteCacheDatastore = c.RemoteDatastore
|
|
|
|
}
|
|
|
|
if c.RemoteCacheDirectory == "" {
|
|
|
|
c.RemoteCacheDirectory = "packer_cache"
|
|
|
|
}
|
|
|
|
if c.RemotePort == 0 {
|
|
|
|
c.RemotePort = 22
|
|
|
|
}
|
2013-12-27 10:37:39 -05:00
|
|
|
|
2020-09-11 10:46:33 -04:00
|
|
|
if c.RemoteType != "" {
|
|
|
|
if c.RemoteHost == "" {
|
|
|
|
errs = append(errs,
|
|
|
|
fmt.Errorf("remote_host must be specified"))
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.RemoteType != "esx5" {
|
|
|
|
errs = append(errs,
|
|
|
|
fmt.Errorf("Only 'esx5' value is accepted for remote_type"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return errs
|
2013-12-27 10:37:39 -05:00
|
|
|
}
|
2018-11-07 12:42:03 -05:00
|
|
|
|
|
|
|
func (c *DriverConfig) Validate(SkipExport bool) error {
|
2020-08-25 15:18:38 -04:00
|
|
|
if SkipExport {
|
2018-11-12 12:46:02 -05:00
|
|
|
return nil
|
|
|
|
}
|
2020-08-25 15:18:38 -04:00
|
|
|
|
|
|
|
if c.RemoteType != "" && c.RemotePassword == "" {
|
|
|
|
return fmt.Errorf("exporting the vm from esxi with ovftool requires " +
|
|
|
|
"that you set a value for remote_password")
|
|
|
|
}
|
|
|
|
|
2018-11-07 12:42:03 -05:00
|
|
|
return nil
|
|
|
|
}
|