Added windows clone options in vsphere and documented them
This commit is contained in:
parent
5f4a3ec09a
commit
7dfc0a6d1e
|
@ -44,6 +44,15 @@ type hardDisk struct {
|
||||||
initType string
|
initType string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Additional options Vsphere can use clones of windows machines
|
||||||
|
type windowsOptConfig struct {
|
||||||
|
productKey string
|
||||||
|
adminPassword string
|
||||||
|
domainUser string
|
||||||
|
domain string
|
||||||
|
domainUserPassword string
|
||||||
|
}
|
||||||
|
|
||||||
type virtualMachine struct {
|
type virtualMachine struct {
|
||||||
name string
|
name string
|
||||||
folder string
|
folder string
|
||||||
|
@ -62,6 +71,7 @@ type virtualMachine struct {
|
||||||
timeZone string
|
timeZone string
|
||||||
dnsSuffixes []string
|
dnsSuffixes []string
|
||||||
dnsServers []string
|
dnsServers []string
|
||||||
|
windowsOptionalConfig windowsOptConfig
|
||||||
customConfigurations map[string](types.AnyType)
|
customConfigurations map[string](types.AnyType)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,6 +181,44 @@ func resourceVSphereVirtualMachine() *schema.Resource {
|
||||||
Optional: true,
|
Optional: true,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
|
"windows_opt_config": &schema.Schema{
|
||||||
|
Type: schema.TypeList,
|
||||||
|
Optional: true,
|
||||||
|
ForceNew: true,
|
||||||
|
Elem: &schema.Resource{
|
||||||
|
Schema: map[string]*schema.Schema{
|
||||||
|
"product_key": &schema.Schema{
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Required: true,
|
||||||
|
ForceNew: true,
|
||||||
|
},
|
||||||
|
|
||||||
|
"admin_password": &schema.Schema{
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Optional: true,
|
||||||
|
ForceNew: true,
|
||||||
|
},
|
||||||
|
|
||||||
|
"domain_user": &schema.Schema{
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Optional: true,
|
||||||
|
ForceNew: true,
|
||||||
|
},
|
||||||
|
|
||||||
|
"domain": &schema.Schema{
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Optional: true,
|
||||||
|
ForceNew: true,
|
||||||
|
},
|
||||||
|
|
||||||
|
"domain_user_password": &schema.Schema{
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Optional: true,
|
||||||
|
ForceNew: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
"network_interface": &schema.Schema{
|
"network_interface": &schema.Schema{
|
||||||
Type: schema.TypeList,
|
Type: schema.TypeList,
|
||||||
|
@ -386,6 +434,28 @@ func resourceVSphereVirtualMachineCreate(d *schema.ResourceData, meta interface{
|
||||||
log.Printf("[DEBUG] network_interface init: %v", networks)
|
log.Printf("[DEBUG] network_interface init: %v", networks)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if vL, ok := d.GetOk("windows_opt_config"); ok {
|
||||||
|
var winOpt windowsOptConfig
|
||||||
|
custom_configs := (vL.([]interface{}))[0].(map[string]interface{})
|
||||||
|
if v, ok := custom_configs["admin_password"].(string); ok && v != "" {
|
||||||
|
winOpt.adminPassword = v
|
||||||
|
}
|
||||||
|
if v, ok := custom_configs["domain"].(string); ok && v != "" {
|
||||||
|
winOpt.domain = v
|
||||||
|
}
|
||||||
|
if v, ok := custom_configs["domain_user"].(string); ok && v != "" {
|
||||||
|
winOpt.domainUser = v
|
||||||
|
}
|
||||||
|
if v, ok := custom_configs["product_key"].(string); ok && v != "" {
|
||||||
|
winOpt.productKey = v
|
||||||
|
}
|
||||||
|
if v, ok := custom_configs["domain_user_password"].(string); ok && v != "" {
|
||||||
|
winOpt.domainUserPassword = v
|
||||||
|
}
|
||||||
|
vm.windowsOptionalConfig = winOpt
|
||||||
|
log.Printf("[DEBUG] windows config init: %v", winOpt)
|
||||||
|
}
|
||||||
|
|
||||||
if vL, ok := d.GetOk("disk"); ok {
|
if vL, ok := d.GetOk("disk"); ok {
|
||||||
disks := make([]hardDisk, len(vL.([]interface{})))
|
disks := make([]hardDisk, len(vL.([]interface{})))
|
||||||
for i, v := range vL.([]interface{}) {
|
for i, v := range vL.([]interface{}) {
|
||||||
|
@ -1207,27 +1277,46 @@ func (vm *virtualMachine) deployVirtualMachine(c *govmomi.Client) error {
|
||||||
var timeZone int
|
var timeZone int
|
||||||
timeZone, err := strconv.Atoi(vm.timeZone)
|
timeZone, err := strconv.Atoi(vm.timeZone)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error reading base VM properties: %s", err)
|
return fmt.Errorf("Error converting TimeZone: %s", err)
|
||||||
}
|
}
|
||||||
identity_options = &types.CustomizationSysprep{
|
|
||||||
GuiUnattended: types.CustomizationGuiUnattended{
|
guiUnattended := types.CustomizationGuiUnattended{
|
||||||
AutoLogon: false,
|
AutoLogon: false,
|
||||||
AutoLogonCount: 1,
|
AutoLogonCount: 1,
|
||||||
Password: &types.CustomizationPassword{
|
|
||||||
PlainText: true,
|
|
||||||
Value: "NULL",
|
|
||||||
},
|
|
||||||
TimeZone: timeZone,
|
TimeZone: timeZone,
|
||||||
},
|
}
|
||||||
Identification: types.CustomizationIdentification{},
|
|
||||||
UserData: types.CustomizationUserData{
|
customIdentification := types.CustomizationIdentification{}
|
||||||
|
|
||||||
|
userData := types.CustomizationUserData{
|
||||||
ComputerName: &types.CustomizationFixedName{
|
ComputerName: &types.CustomizationFixedName{
|
||||||
Name: strings.Split(vm.name, ".")[0],
|
Name: strings.Split(vm.name, ".")[0],
|
||||||
},
|
},
|
||||||
FullName: "LSTTE",
|
ProductId: vm.windowsOptionalConfig.productKey,
|
||||||
OrgName: "LSTTE",
|
FullName: "terraform",
|
||||||
ProductId: "ruh roh",
|
OrgName: "terraform",
|
||||||
},
|
}
|
||||||
|
|
||||||
|
if vm.windowsOptionalConfig.domainUserPassword != "" && vm.windowsOptionalConfig.domainUser != "" && vm.windowsOptionalConfig.domain != "" {
|
||||||
|
customIdentification.DomainAdminPassword = &types.CustomizationPassword{
|
||||||
|
PlainText: true,
|
||||||
|
Value: vm.windowsOptionalConfig.domainUserPassword,
|
||||||
|
}
|
||||||
|
customIdentification.DomainAdmin = vm.windowsOptionalConfig.domainUser
|
||||||
|
customIdentification.JoinDomain = vm.windowsOptionalConfig.domain
|
||||||
|
}
|
||||||
|
|
||||||
|
if vm.windowsOptionalConfig.adminPassword != "" {
|
||||||
|
guiUnattended.Password = &types.CustomizationPassword{
|
||||||
|
PlainText: true,
|
||||||
|
Value: vm.windowsOptionalConfig.adminPassword,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
identity_options = &types.CustomizationSysprep{
|
||||||
|
GuiUnattended: guiUnattended,
|
||||||
|
Identification: customIdentification,
|
||||||
|
UserData: userData,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
identity_options = &types.CustomizationLinuxPrep{
|
identity_options = &types.CustomizationLinuxPrep{
|
||||||
|
|
|
@ -41,12 +41,14 @@ The following arguments are supported:
|
||||||
* `resource_pool` (Optional) The name of a Resource Pool in which to launch the virtual machine
|
* `resource_pool` (Optional) The name of a Resource Pool in which to launch the virtual machine
|
||||||
* `gateway` - (Optional) Gateway IP address to use for all network interfaces
|
* `gateway` - (Optional) Gateway IP address to use for all network interfaces
|
||||||
* `domain` - (Optional) A FQDN for the virtual machine; defaults to "vsphere.local"
|
* `domain` - (Optional) A FQDN for the virtual machine; defaults to "vsphere.local"
|
||||||
* `time_zone` - (Optional) The [time zone](https://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/timezone.html) to set on the virtual machine. Defaults to "Etc/UTC"
|
* `time_zone` - (Optional) The [Linux](https://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/timezone.html) or [Windows](https://msdn.microsoft.com/en-us/library/ms912391.aspx) time zone to set on the virtual machine. Defaults to "Etc/UTC"
|
||||||
* `dns_suffixes` - (Optional) List of name resolution suffixes for the virtual network adapter
|
* `dns_suffixes` - (Optional) List of name resolution suffixes for the virtual network adapter
|
||||||
* `dns_servers` - (Optional) List of DNS servers for the virtual network adapter; defaults to 8.8.8.8, 8.8.4.4
|
* `dns_servers` - (Optional) List of DNS servers for the virtual network adapter; defaults to 8.8.8.8, 8.8.4.4
|
||||||
* `network_interface` - (Required) Configures virtual network interfaces; see [Network Interfaces](#network-interfaces) below for details.
|
* `network_interface` - (Required) Configures virtual network interfaces; see [Network Interfaces](#network-interfaces) below for details.
|
||||||
* `disk` - (Required) Configures virtual disks; see [Disks](#disks) below for details
|
* `disk` - (Required) Configures virtual disks; see [Disks](#disks) below for details
|
||||||
* `boot_delay` - (Optional) Time in seconds to wait for machine network to be ready.
|
* `boot_delay` - (Optional) Time in seconds to wait for machine network to be ready.
|
||||||
|
* `windows_opt_config` - (Optional) Extra options for clones of Windows machines.
|
||||||
|
* `linkedClone` - (Optional) Specifies if the new machine is a [linked clone](https://www.vmware.com/support/ws5/doc/ws_clone_overview.html#wp1036396) of another machine or not.
|
||||||
* `custom_configuration_parameters` - (Optional) Map of values that is set as virtual machine custom configurations.
|
* `custom_configuration_parameters` - (Optional) Map of values that is set as virtual machine custom configurations.
|
||||||
|
|
||||||
The `network_interface` block supports:
|
The `network_interface` block supports:
|
||||||
|
@ -61,6 +63,13 @@ removed in a future version:
|
||||||
* `ip_address` - __Deprecated, please use `ipv4_address` instead_.
|
* `ip_address` - __Deprecated, please use `ipv4_address` instead_.
|
||||||
* `subnet_mask` - __Deprecated, please use `ipv4_prefix_length` instead_.
|
* `subnet_mask` - __Deprecated, please use `ipv4_prefix_length` instead_.
|
||||||
|
|
||||||
|
The `windows_opt_config` block supports:
|
||||||
|
|
||||||
|
* `product_key` - (Optional) Serial number for new installation of Windows. This serial number is ignored if the original guest operating system was installed using a volume-licensed CD.
|
||||||
|
* `admin_password` - (Optional) The password for the new `administrator` account. Omit for passwordless admin (using `""` does not work).
|
||||||
|
* `domain` - (Optional) Domain that the new machine will be placed into. If `domain`, `domain_user`, and `domain_user_password` are not all set, all three will be ignored.
|
||||||
|
* `domain_user` - (Optional) User that is a member of the specified domain.
|
||||||
|
* `domain_user_password` - (Optional) Password for domain user, in plain text.
|
||||||
|
|
||||||
The `disk` block supports:
|
The `disk` block supports:
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue