2020-01-07 19:59:31 -05:00
|
|
|
//go:generate struct-markdown
|
|
|
|
//go:generate mapstructure-to-hcl2 -type LocationConfig
|
|
|
|
|
2018-05-06 17:26:04 -04:00
|
|
|
package common
|
|
|
|
|
2020-07-07 12:25:14 -04:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"path"
|
|
|
|
"strings"
|
|
|
|
)
|
2018-05-06 17:26:04 -04:00
|
|
|
|
|
|
|
type LocationConfig struct {
|
2020-01-07 19:59:31 -05:00
|
|
|
// Name of the new VM to create.
|
|
|
|
VMName string `mapstructure:"vm_name"`
|
|
|
|
// VM folder to create the VM in.
|
|
|
|
Folder string `mapstructure:"folder"`
|
2020-10-09 16:09:06 -04:00
|
|
|
// ESXi cluster where target VM is created. See the
|
|
|
|
// [Working With Clusters And Hosts](#working-with-clusters-and-hosts)
|
|
|
|
// section above for more details.
|
2020-01-07 19:59:31 -05:00
|
|
|
Cluster string `mapstructure:"cluster"`
|
|
|
|
// ESXi host where target VM is created. A full path must be specified if
|
|
|
|
// the host is in a folder. For example `folder/host`. See the
|
2020-10-09 16:09:06 -04:00
|
|
|
// [Working With Clusters And Hosts](#working-with-clusters-and-hosts)
|
|
|
|
// section above for more details.
|
2020-01-07 19:59:31 -05:00
|
|
|
Host string `mapstructure:"host"`
|
2020-10-09 16:09:06 -04:00
|
|
|
// VMWare resource pool. If not set, it will look for the root resource
|
|
|
|
// pool of the `host` or `cluster`. If a root resource is not found, it
|
|
|
|
// will then look for a default resource pool.
|
2018-05-06 17:26:04 -04:00
|
|
|
ResourcePool string `mapstructure:"resource_pool"`
|
2020-01-07 19:59:31 -05:00
|
|
|
// VMWare datastore. Required if `host` is a cluster, or if `host` has
|
|
|
|
// multiple datastores.
|
|
|
|
Datastore string `mapstructure:"datastore"`
|
2020-05-05 14:34:15 -04:00
|
|
|
// Set this to true if packer should the host for uploading files
|
|
|
|
// to the datastore. Defaults to false.
|
|
|
|
SetHostForDatastoreUploads bool `mapstructure:"set_host_for_datastore_uploads"`
|
2018-05-06 17:26:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *LocationConfig) Prepare() []error {
|
|
|
|
var errs []error
|
|
|
|
|
|
|
|
if c.VMName == "" {
|
|
|
|
errs = append(errs, fmt.Errorf("'vm_name' is required"))
|
|
|
|
}
|
|
|
|
if c.Cluster == "" && c.Host == "" {
|
|
|
|
errs = append(errs, fmt.Errorf("'host' or 'cluster' is required"))
|
|
|
|
}
|
|
|
|
|
2020-07-07 12:25:14 -04:00
|
|
|
// clean Folder path and remove leading slash as folders are relative within vsphere
|
|
|
|
c.Folder = path.Clean(c.Folder)
|
|
|
|
c.Folder = strings.TrimLeft(c.Folder, "/")
|
|
|
|
|
2018-05-06 17:26:04 -04:00
|
|
|
return errs
|
|
|
|
}
|