Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow guest Vm to run in ESXi nested host #210

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ Configuration reference
* key - Required - Key of the property
* value - Required - Value of the property
* ovf_properties_timer - Optional - Length of time to wait for ovf_properties to process. Default 90s.
* nested_esxi - Optional - Set to "y" indicates that the guest can run in a ESXi nested environment


* resource "esxi_vswitch"
Expand Down
18 changes: 14 additions & 4 deletions esxi/guest-create.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
func guestCREATE(c *Config, guest_name string, disk_store string,
src_path string, resource_pool_name string, strmemsize string, strnumvcpus string, strvirthwver string, guestos string,
boot_disk_type string, boot_disk_size string, virtual_networks [10][3]string, boot_firmware string,
virtual_disks [60][2]string, guest_shutdown_timeout int, ovf_properties_timer int, notes string,
virtual_disks [60][2]string, guest_shutdown_timeout int, ovf_properties_timer int, notes string, nested_esxi string,
guestinfo map[string]interface{}, ovf_properties map[string]string) (string, error) {

esxiConnInfo := getConnectionInfo(c)
Expand Down Expand Up @@ -164,6 +164,10 @@ func guestCREATE(c *Config, guest_name string, disk_store string,
fmt.Sprintf("ide1:0.deviceType = \\\"cdrom-raw\\\"\n")
}

if nested_esxi == "y" {
vmx_contents = vmx_contents +
fmt.Sprintf("monitor.allowLegacyCPU = \\\"TRUE\\\"\n")
}
//
// Write vmx file to esxi host
//
Expand Down Expand Up @@ -251,9 +255,15 @@ func guestCREATE(c *Config, guest_name string, disk_store string,
}
log.Println("[guestCREATE] ovf_properties extra_params: " + extra_params)
}

ovf_cmd := fmt.Sprintf("ovftool --acceptAllEulas --noSSLVerify --X:useMacNaming=false %s "+
"-dm=%s --name='%s' --overwrite -ds='%s' %s '%s' '%s'", extra_params, boot_disk_type, guest_name, disk_store, net_param, src_path, dst_path)
if ( (nested_esxi == "y") && (is_ovf_properties == false) ) {
extra_params = "--allowExtraConfig"
}
allow_nested_esxi := ""
if nested_esxi == "y" {
allow_nested_esxi = "--extraConfig:monitor.allowLegacyCPU=TRUE "
}
ovf_cmd := fmt.Sprintf("ovftool --acceptAllEulas --noSSLVerify --X:useMacNaming=false %s %s "+
"-dm=%s --name='%s' --overwrite -ds='%s' %s '%s' '%s'", extra_params, allow_nested_esxi,boot_disk_type, guest_name, disk_store, net_param, src_path, dst_path)

if runtime.GOOS == "windows" {
osShellCmd = "cmd.exe"
Expand Down
1 change: 1 addition & 0 deletions esxi/guest_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ func updateVmx_contents(c *Config, vmid string, iscreate bool, memsize int, numv
if strings.Contains(vmx_contents, "Unable to find a VM corresponding") {
return nil
}
log.Printf("[updateVmx_contents] Current contents: %s\n", vmx_contents)

// modify memsize
if memsize != 0 {
Expand Down
10 changes: 9 additions & 1 deletion esxi/resource_guest.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,13 @@ func resourceGUEST() *schema.Resource {
Computed: true,
Description: "Guest notes (annotation).",
},
"nested_esxi": &schema.Schema{
Type: schema.TypeString,
Optional: true,
ForceNew: false,
Computed: true,
Description: "Guest runs in nested ESXI",
},
"guestinfo": &schema.Schema{
Type: schema.TypeMap,
Optional: true,
Expand Down Expand Up @@ -258,6 +265,7 @@ func resourceGUESTCreate(d *schema.ResourceData, m interface{}) error {
boot_firmware := d.Get("boot_firmware").(string)
notes := d.Get("notes").(string)
power := d.Get("power").(string)
nested_esxi := d.Get("nested_esxi").(string)

if d.Get("guest_startup_timeout").(int) > 0 {
d.Set("guest_startup_timeout", d.Get("guest_startup_timeout").(int))
Expand Down Expand Up @@ -402,7 +410,7 @@ func resourceGUESTCreate(d *schema.ResourceData, m interface{}) error {

vmid, err := guestCREATE(c, guest_name, disk_store, src_path, resource_pool_name, memsize,
numvcpus, virthwver, guestos, boot_disk_type, boot_disk_size, virtual_networks, boot_firmware,
virtual_disks, guest_shutdown_timeout, ovf_properties_timer, notes, guestinfo, ovf_properties)
virtual_disks, guest_shutdown_timeout, ovf_properties_timer, notes, nested_esxi, guestinfo, ovf_properties)
if err != nil {
tmpint, _ = strconv.Atoi(vmid)
if tmpint > 0 {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/josenk/terraform-provider-esxi
module github.com/narenas/terraform-provider-esxi

require (
github.com/hashicorp/terraform v0.12.2
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"github.com/hashicorp/terraform/plugin"
"github.com/hashicorp/terraform/terraform"
"github.com/josenk/terraform-provider-esxi/esxi"
"github.com/narenas/terraform-provider-esxi/esxi"
)

func main() {
Expand Down