diff --git a/README.md b/README.md index ba51701..b28b760 100644 --- a/README.md +++ b/README.md @@ -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" diff --git a/esxi/guest-create.go b/esxi/guest-create.go index 86799cf..145c619 100644 --- a/esxi/guest-create.go +++ b/esxi/guest-create.go @@ -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) @@ -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 // @@ -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" diff --git a/esxi/guest_functions.go b/esxi/guest_functions.go index 1e9e9c1..e0ebc71 100644 --- a/esxi/guest_functions.go +++ b/esxi/guest_functions.go @@ -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 { diff --git a/esxi/resource_guest.go b/esxi/resource_guest.go index d36c67b..1879063 100644 --- a/esxi/resource_guest.go +++ b/esxi/resource_guest.go @@ -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, @@ -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)) @@ -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 { diff --git a/go.mod b/go.mod index bbc121b..c32a9e0 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/main.go b/main.go index f938762..3b529dc 100644 --- a/main.go +++ b/main.go @@ -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() {