vmware / govmomi

Go library for the VMware vSphere API
Apache License 2.0
2.32k stars 913 forks source link

vcsim Terraform support? #1779

Closed Satak closed 3 years ago

Satak commented 4 years ago

I want to use vcsim to test out our Terraform VM templates for VMware. Does vcsim support Terraform VM provisioning? If so is there any reference what kind of Terraform configuration should work against vcsim? In the Terraform template I want to clone an existing VM or Template and not just create the VM item. Is this possible with vcsim? I have tried to do this with Terraform against vcsim but Terraform plan just says: No changes. Infrastructure is up-to-date.

Any tested Terraform template that actually creates a VM to vcsim with clone functionality?

I found this gist: https://gist.github.com/zpratt/0ad7bcf382b321501bd92e958bf9f8a9 But it doesn't use clone and it actually time outs with error: vsphere_virtual_machine.test-node: timeout waiting for an available IP address

dougm commented 4 years ago

We have worked with the Ansible community quite a bit to enhance vcsim to meet their testing needs, but have only heard from Terraform folks once or twice. We don't have a reference or any tests that are Ansible/Terraform specific on the vcsim side (Ansible does on their side).

Happy to further enhance vcsim to meet Terraform's needs in general. In this case, vcsim VMs don't have an IP address by default. You can populate them however: https://github.com/vmware/govmomi/wiki/vcsim-features#injecting-virtual-machine-properties

Or even with a running container: https://github.com/vmware/govmomi/wiki/vcsim-features#containers-as-vms

We could add something else that populates the VM's IP, such as range of fake IPs or even just 127.0.0.1 for all. Open to suggestions.

Satak commented 4 years ago

It would be a good start to put IP 127.0.0.1 for all VMs by default. Not sure how this should be tested and make it happen with VMware and Hashicorp. Opened also an issue for Hashicorp VMware provider repo: https://github.com/terraform-providers/terraform-provider-vsphere/issues/940

Not even sure where to start debugging this No changes. Infrastructure is up-to-date. issue for cloning operations. Most Terraform use cases against vSphere is of course to clone a template or a VM.

dougm commented 4 years ago

vcsim has -trace and -trace-file options that capture all traffic to/from vcsim. I'm sure terraform has verbose logging on its side. If you can provide steps to reproduce, starting from zero (where/what terraform binaries to download, how to run, etc), I could take a look too.

Satak commented 4 years ago

I wrote a small gist how to start testing this: https://gist.github.com/Satak/ca370e3e40f7756e7e2064081f876b5f

First step would be to define a working configuration. Like what datacenter, datastore, resource pool, network, template to use for terraform. Basically what is a basic config to clone VM/template in vcsim? When we know what should work, add those variables to Terraform and then test it.

This current config (terraform plan command) now gives this error message:

Error: cannot find OS family for guest ID "otherGuest": ServerFaultCode: The object has already been deleted or has not been completely created

  on main.tf line 32, in resource "vsphere_virtual_machine" "vm":
  32: resource "vsphere_virtual_machine" "vm" {

Maybe the biggest problem is that the VMs don't have IPs, do they have disks? etc. So if we would create proper VMs and templates then it would be easier to use clone operation in Terraform.

dougm commented 4 years ago

Thanks @Satak , I'll try this out soon and see if I can help fill in some of the blanks on the vcsim side.

Satak commented 4 years ago

Any progress on this? I can do a clone operation with govc tool but not with Terraform because of this error mentioned earlier: Error: cannot find OS family for guest ID "otherGuest": ServerFaultCode: The object has already been deleted or has not been completely created

Folks at Terraform also thinks there might be some properties missing in vcsim that Terraform needs. This would be truly great to get it working. My guess is that I'm not the only one who would like to develop their VMware Terraform templates rapidly against vcsim.

Working Terraform config

I managed to create one working Terraform config and I made gist out of it:

Problem is this customize {} block in it. If you uncomment that out, it will give you the error: Error: cannot find OS family for guest ID "otherGuest": could not find guest ID "otherGuest"

How one can create a VM/template that has guest_id either otherLinux64Guest or windows9Server64Guest? There is something with that otherGuest guest_id that Terraform doesn't like.

update: Managed to create a VM with govc like this with otherLinux64Guest as guest_id: govc vm.create -on=false -host DC0_H0 -version 6.7 -g otherLinux64Guest -c 2 template-vm

But still the Terraform complains: cannot find OS family for guest ID "otherLinux64Guest": could not find guest ID "otherLinux64Guest"

Terraform log here: https://gist.github.com/Satak/1745368ebc694b4430c795293b27b472

Satak commented 4 years ago

Maybe this is the reason. All VMs by default doesn't have any GuestFamily or GuestFullName:

Get-VM -Name DC0_H0_VM0 |  select -ExpandProperty ExtensionData | select -ExpandProperty Guest

Output:

ToolsStatus                     : toolsNotInstalled
ToolsVersionStatus              :
ToolsVersionStatus2             :
ToolsRunningStatus              : guestToolsNotRunning
ToolsVersion                    : 0
ToolsInstallType                :
GuestId                         :
GuestFamily                     :
GuestFullName                   :
HostName                        :
IpAddress                       :
Net                             : {4000}
IpStack                         :
Disk                            :
Screen                          :
GuestState                      :
AppHeartbeatStatus              :
GuestKernelCrashed              :
AppState                        :
GuestOperationsReady            :
InteractiveGuestOperationsReady :
GuestStateChangeSupported       :
GenerationInfo                  :
dougm commented 4 years ago

Started to look. One issue is related to the EnvironmentBrowser, where vcsim currently returns an empty list for GuestOSDescriptor here: https://github.com/terraform-providers/terraform-provider-vsphere/blob/master/vsphere/internal/helper/envbrowse/environment_browser_helper.go#L83

It is something we can implement, will look at it more this week.

Satak commented 4 years ago

Any news on this?

If you have this under your VM resource:

  clone {
    template_uuid = data.vsphere_virtual_machine.template.id
  }

It will crash the whole terraform:

❯ terraform plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.

module.vmware.data.vsphere_datacenter.dc: Refreshing state...
module.vmware.data.vsphere_resource_pool.pool: Refreshing state...
module.vmware.data.vsphere_virtual_machine.template: Refreshing state...
module.vmware.data.vsphere_network.network[0]: Refreshing state...
module.vmware.data.vsphere_datastore.datastore[0]: Refreshing state...

------------------------------------------------------------------------

Error: rpc error: code = Unavailable desc = transport is closing

panic: runtime error: invalid memory address or nil pointer dereference
2020-03-24T10:34:19.611+0200 [DEBUG] plugin.terraform-provider-vsphere_v1.17.0_x4.exe: [signal 0xc0000005 code=0x0 addr=0x0 pc=0x11ac5a1]
2020-03-24T10:34:19.611+0200 [DEBUG] plugin.terraform-provider-vsphere_v1.17.0_x4.exe:
2020-03-24T10:34:19.611+0200 [DEBUG] plugin.terraform-provider-vsphere_v1.17.0_x4.exe: goroutine 14 [running]:
2020-03-24T10:34:19.611+0200 [DEBUG] plugin.terraform-provider-vsphere_v1.17.0_x4.exe: github.com/vmware/govmomi/vapi/rest.(*Client).Resource(...)
2020-03-24T10:34:19.611+0200 [DEBUG] plugin.terraform-provider-vsphere_v1.17.0_x4.exe:  /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-vsphere/vendor/github.com/vmware/govmomi/vapi/rest/client.go:67
2020-03-24T10:34:19.611+0200 [DEBUG] plugin.terraform-provider-vsphere_v1.17.0_x4.exe: github.com/vmware/govmomi/vapi/library.(*Manager).GetLibraryItem(0xc00041f230, 0x1bfd0e0, 0xc0000300a8, 0xc00011e060, 0x24, 0x100, 0x89, 0x14)
2020-03-24T10:34:19.611+0200 [DEBUG] plugin.terraform-provider-vsphere_v1.17.0_x4.exe:  /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-vsphere/vendor/github.com/vmware/govmomi/vapi/library/library_item.go:115 +0x31
2020-03-24T10:34:19.611+0200 [DEBUG] plugin.terraform-provider-vsphere_v1.17.0_x4.exe: github.com/terraform-providers/terraform-provider-vsphere/vsphere/internal/helper/contentlibrary.ItemFromID(0x0, 0xc00011e060, 0x24, 0x1, 0x1, 0x0)
2020-03-24T10:34:19.611+0200 [DEBUG] plugin.terraform-provider-vsphere_v1.17.0_x4.exe:  /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-vsphere/vsphere/internal/helper/contentlibrary/content_library_helper.go:116 +0x102
2020-03-24T10:34:19.611+0200 [DEBUG] plugin.terraform-provider-vsphere_v1.17.0_x4.exe: github.com/terraform-providers/terraform-provider-vsphere/vsphere/internal/helper/contentlibrary.IsContentLibraryItem(0x0, 0xc00011e060, 0x24, 0x14aae40)
2020-03-24T10:34:19.611+0200 [DEBUG] plugin.terraform-provider-vsphere_v1.17.0_x4.exe:  /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-vsphere/vsphere/internal/helper/contentlibrary/content_library_helper.go:127 +0xb5
2020-03-24T10:34:19.611+0200 [DEBUG] plugin.terraform-provider-vsphere_v1.17.0_x4.exe: github.com/terraform-providers/terraform-provider-vsphere/vsphere.resourceVSphereVirtualMachineCustomizeDiff(0xc00024a140, 0x1519180, 0xc000005400, 0xc000487d40, 0xc00024a140)
2020-03-24T10:34:19.611+0200 [DEBUG] plugin.terraform-provider-vsphere_v1.17.0_x4.exe:  /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-vsphere/vsphere/resource_vsphere_virtual_machine.go:865 +0x7d2
2020-03-24T10:34:19.611+0200 [DEBUG] plugin.terraform-provider-vsphere_v1.17.0_x4.exe: github.com/hashicorp/terraform-plugin-sdk/helper/schema.schemaMap.Diff(0xc000109860, 0xc0000aa960, 0xc0001a9590, 0x18a6bd0, 0x1519180, 0xc000005400, 0x1810f00, 0x1bfdd20, 0xffffffffffffffff, 0x0)
2020-03-24T10:34:19.611+0200 [DEBUG] plugin.terraform-provider-vsphere_v1.17.0_x4.exe:  /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-vsphere/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/schema/schema.go:518 +0xaca
2020-03-24T10:34:19.611+0200 [DEBUG] plugin.terraform-provider-vsphere_v1.17.0_x4.exe: github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Resource).simpleDiff(0xc00013b880, 0xc0000aa960, 0xc0001a9590, 0x1519180, 0xc000005400, 0x1, 0xc00002f420, 0xc0001a9590)
2020-03-24T10:34:19.611+0200 [DEBUG] plugin.terraform-provider-vsphere_v1.17.0_x4.exe:  /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-vsphere/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/schema/resource.go:351 +0x8c
2020-03-24T10:34:19.611+0200 [DEBUG] plugin.terraform-provider-vsphere_v1.17.0_x4.exe: github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Provider).SimpleDiff(0xc0002d0780, 0xc00059fac8, 0xc0000aa960, 0xc0001a9590, 0xc00015a540, 0xc0001a9590, 0x0)
2020-03-24T10:34:19.611+0200 [DEBUG] plugin.terraform-provider-vsphere_v1.17.0_x4.exe:  /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-vsphere/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/schema/provider.go:321 +0x196
2020-03-24T10:34:19.611+0200 [DEBUG] plugin.terraform-provider-vsphere_v1.17.0_x4.exe: github.com/hashicorp/terraform-plugin-sdk/internal/helper/plugin.(*GRPCProviderServer).PlanResourceChange(0xc000006608, 0x1bfd160, 0xc00008c1b0, 0xc00011a420, 0xc000006608, 0xc00008c1b0, 0xc0003f7bd0)
2020-03-24T10:34:19.611+0200 [DEBUG] plugin.terraform-provider-vsphere_v1.17.0_x4.exe:  /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-vsphere/vendor/github.com/hashicorp/terraform-plugin-sdk/internal/helper/plugin/grpc_provider.go:633 +0x79b
2020-03-24T10:34:19.611+0200 [DEBUG] plugin.terraform-provider-vsphere_v1.17.0_x4.exe: github.com/hashicorp/terraform-plugin-sdk/internal/tfplugin5._Provider_PlanResourceChange_Handler(0x17ca0a0, 0xc000006608, 0x1bfd160, 0xc00008c1b0, 0xc00011a3c0, 0x0, 0x1bfd160, 0xc00008c1b0, 0xc000596000, 0xf82)
2020-03-24T10:34:19.611+0200 [DEBUG] plugin.terraform-provider-vsphere_v1.17.0_x4.exe:  /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-vsphere/vendor/github.com/hashicorp/terraform-plugin-sdk/internal/tfplugin5/tfplugin5.pb.go:3171 +0x245
2020-03-24T10:34:19.612+0200 [DEBUG] plugin.terraform-provider-vsphere_v1.17.0_x4.exe: google.golang.org/grpc.(*Server).processUnaryRPC(0xc0000bc160, 0x1c0c5e0, 0xc0004be480, 0xc000098000, 0xc0001091a0, 0x2a99fc8, 0x0, 0x0, 0x0)
2020-03-24T10:34:19.612+0200 [DEBUG] plugin.terraform-provider-vsphere_v1.17.0_x4.exe:  /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-vsphere/vendor/google.golang.org/grpc/server.go:995 +0x46d
2020-03-24T10:34:19.612+0200 [DEBUG] plugin.terraform-provider-vsphere_v1.17.0_x4.exe: google.golang.org/grpc.(*Server).handleStream(0xc0000bc160, 0x1c0c5e0, 0xc0004be480, 0xc000098000, 0x0)
2020-03-24T10:34:19.612+0200 [DEBUG] plugin.terraform-provider-vsphere_v1.17.0_x4.exe:  /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-vsphere/vendor/google.golang.org/grpc/server.go:1275 +0xdad
2020-03-24T10:34:19.612+0200 [DEBUG] plugin.terraform-provider-vsphere_v1.17.0_x4.exe: google.golang.org/grpc.(*Server).serveStreams.func1.1(0xc00012a180, 0xc0000bc160, 0x1c0c5e0, 0xc0004be480, 0xc000098000)
2020-03-24T10:34:19.612+0200 [DEBUG] plugin.terraform-provider-vsphere_v1.17.0_x4.exe:  /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-vsphere/vendor/google.golang.org/grpc/server.go:710 +0xa6
2020-03-24T10:34:19.612+0200 [DEBUG] plugin.terraform-provider-vsphere_v1.17.0_x4.exe: created by google.golang.org/grpc.(*Server).serveStreams.func1
2020-03-24T10:34:19.612+0200 [DEBUG] plugin.terraform-provider-vsphere_v1.17.0_x4.exe:  /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-vsphere/vendor/google.golang.org/grpc/server.go:708 +0xa8
2020/03/24 10:34:19 [ERROR] module.vmware: eval: *terraform.EvalDiff, err: rpc error: code = Unavailable desc = transport is closing
2020/03/24 10:34:19 [ERROR] module.vmware: eval: *terraform.EvalSequence, err: rpc error: code = Unavailable desc = transport is closing
2020/03/24 10:34:19 [TRACE] [walkPlan] Exiting eval tree: module.vmware.vsphere_virtual_machine.Windows[0]
2020/03/24 10:34:19 [TRACE] vertex "module.vmware.vsphere_virtual_machine.Windows[0]": visit complete
2020/03/24 10:34:19 [TRACE] vertex "module.vmware.vsphere_virtual_machine.Windows": dynamic subgraph encountered errors
2020/03/24 10:34:19 [TRACE] vertex "module.vmware.vsphere_virtual_machine.Windows": visit complete
2020/03/24 10:34:19 [TRACE] dag/walk: upstream of "module.vmware.output.Windows-VM" errored, so skipping
2020/03/24 10:34:19 [TRACE] dag/walk: upstream of "module.vmware.provider.vsphere (close)" errored, so skipping
2020/03/24 10:34:19 [TRACE] dag/walk: upstream of "module.vmware.output.Windows-uuid" errored, so skipping
2020/03/24 10:34:19 [TRACE] dag/walk: upstream of "module.vmware.output.Windows-ip" errored, so skipping
2020/03/24 10:34:19 [TRACE] dag/walk: upstream of "module.vmware.output.Windows-guest-ip" errored, so skipping
2020/03/24 10:34:19 [TRACE] dag/walk: upstream of "meta.count-boundary (EachMode fixup)" errored, so skipping
2020/03/24 10:34:19 [TRACE] dag/walk: upstream of "root" errored, so skipping
2020/03/24 10:34:19 [INFO] backend/local: plan operation completed
2020/03/24 10:34:19 [TRACE] statemgr.Filesystem: removing lock metadata file .terraform.tfstate.lock.info
2020/03/24 10:34:19 [TRACE] statemgr.Filesystem: unlocked by closing terraform.tfstate
2020-03-24T10:34:19.624+0200 [DEBUG] plugin: plugin process exited: path=C:\Dev\terraform-mcss-vmware\test\.terraform\plugins\windows_amd64\terraform-provider-vsphere_v1.17.0_x4.exe pid=11164 error="exit status 2"
2020-03-24T10:34:19.624+0200 [DEBUG] plugin: plugin exited

!!!!!!!!!!!!!!!!!!!!!!!!!!! TERRAFORM CRASH !!!!!!!!!!!!!!!!!!!!!!!!!!!!

Terraform crashed! This is always indicative of a bug within Terraform.
A crash log has been placed at "crash.log" relative to your current
working directory. It would be immensely helpful if you could please
report the crash with Terraform[1] so that we can fix this.

When reporting bugs, please include your terraform version. That
information is available on the first line of crash.log. You can also
get it by running 'terraform --version' on the command line.

SECURITY WARNING: the "crash.log" file that was created may contain
sensitive information that must be redacted before it is safe to share
on the issue tracker.

[1]: https://github.com/hashicorp/terraform/issues

!!!!!!!!!!!!!!!!!!!!!!!!!!! TERRAFORM CRASH !!!!!!!!!!!!!!!!!!!!!!!!!!!!
dougm commented 4 years ago

When I first looked into this, https://github.com/terraform-providers/terraform-provider-vsphere/pull/959 was the first step. And just opened #1907 to make use of that. But tf still crashes using your gist, though in a different place. Looks different from your output above though. Can you try using #1907 ?

Satak commented 4 years ago

Terraform still crashes if you put clone block.

Without clone block and with this resource you will get an error.

resource "vsphere_virtual_machine" "vm" {
  name             = var.vm_name
  resource_pool_id = data.vsphere_resource_pool.pool.id
  datastore_id     = data.vsphere_datastore.datastore.id
  guest_id         = data.vsphere_virtual_machine.template.guest_id
  scsi_type        = data.vsphere_virtual_machine.template.scsi_type

  num_cpus = 2
  memory   = 1024

  disk {
    label = "disk0"
    size  = 20
  }

  network_interface {
    network_id   = data.vsphere_network.network.id
    adapter_type = data.vsphere_virtual_machine.template.network_interface_types[0]
  }

  wait_for_guest_net_routable = false
  wait_for_guest_ip_timeout   = 0
  wait_for_guest_net_timeout  = -1
}

Error:

Error: ServerFaultCode: PbmProfileProfileManager:ProfileManager does not implement: PbmQueryAssociatedProfile: RESOURCE (vm-69), ACTION (queryAssociatedProfile): RESOURCE (vm-69), ACTION (PolicyIDByVirtualMachine)

Satak commented 4 years ago

Still same problem when trying to use simple terraform template without clone with latest terrafrom and vcsim:

data.vsphere_datacenter.dc: Refreshing state...
data.vsphere_datastore.datastore: Refreshing state...
data.vsphere_network.network: Refreshing state...
data.vsphere_resource_pool.pool: Refreshing state...
data.vsphere_virtual_machine.template: Refreshing state...
vsphere_virtual_machine.vm: Refreshing state... [id=b4bf078a-f7e0-53bb-a378-8a1d31d70343]

Error: ServerFaultCode: PbmProfileProfileManager:ProfileManager does not implement: PbmQueryAssociatedProfile: RESOURCE (vm-69), ACTION (queryAssociatedProfile): RESOURCE (vm-69), ACTION (PolicyIDByVirtualMachine)
dougm commented 4 years ago

I haven't tested against TF, but it looks like #2015 would be enough to get past this part.

I know you've provide gists and snippets such as the above, would it be possible to provide an updated version? Such as a repo containing the scripts, etc., and a single command I could run to easily reproduce?

Satak commented 4 years ago

I haven't tested against TF, but it looks like #2015 would be enough to get past this part.

I know you've provide gists and snippets such as the above, would it be possible to provide an updated version? Such as a repo containing the scripts, etc., and a single command I could run to easily reproduce?

Thanks for your reply. In this folder is everything that you need to run and test, it even have run_terraform.ps1 Powershell script to run basically terraform apply for you :-) https://github.com/Satak/vcsim-docker/tree/master/terraform

dougm commented 4 years ago

Thanks @Satak . Seems to work with #2015

% terraform apply -auto-approve
data.vsphere_datacenter.dc: Refreshing state...
data.vsphere_datastore.datastore: Refreshing state...
data.vsphere_network.network: Refreshing state...
data.vsphere_virtual_machine.template: Refreshing state...
data.vsphere_resource_pool.pool: Refreshing state...
vsphere_virtual_machine.vm: Refreshing state... [id=b4bf078a-f7e0-53bb-a378-8a1d31d70343]
vsphere_virtual_machine.vm: Creating...
vsphere_virtual_machine.vm: Creation complete after 1s [id=b4bf078a-f7e0-53bb-a378-8a1d31d70343]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
Satak commented 4 years ago

Thanks @Satak . Seems to work with #2015

Yes you are correct, now it works with Terraform but only without a clone block. If you add this block to the main.tf Terraform will crash:

  clone {
    template_uuid = data.vsphere_virtual_machine.template.id
  }

Crash log here: https://gist.github.com/Satak/ec149546617397bc41f70291d64fe030

Maybe something to do with this: 2020-06-16T10:19:01.177+0300 [DEBUG] plugin.terraform-provider-vsphere_v1.18.3_x4.exe: panic: runtime error: invalid memory address or nil pointer dereference

dougm commented 4 years ago

I see this too. Based on crash.log it looks like restClient is nil here: https://github.com/hashicorp/terraform-provider-vsphere/blob/5f3413433cad6dcbb59a567295881574e7e406cf/vsphere/resource_vsphere_virtual_machine.go#L997

But I don't know why.

mrlesmithjr commented 4 years ago

Just chiming in here as well. I am also all of a sudden seeing this same thing with 0.12.28. I too have the clone block defined. However, I am only seeing this on Linux and not macOS. I know, it makes no sense at all. But.... Still troubleshooting.

Trace Log

dougm commented 3 years ago

The problem is that isEligibleRestEndpoint returns false here: https://github.com/hashicorp/terraform-provider-vsphere/blob/62eec9aa9d013d741ef747108f069330c3118a48/vsphere/config.go#L169-L182

Because it expects Product == VMware vCenter Server, but it vcsim Product is VMware vCenter Server (govmomi simulator)

That leaves meta.(*VSphereClient).restClient == nil, causing the panic later when the client is used here: https://github.com/hashicorp/terraform-provider-vsphere/blob/62eec9aa9d013d741ef747108f069330c3118a48/vsphere/resource_vsphere_virtual_machine.go#L968

You can workaround with this change:

modified   vcsim/main.go
@@ -155,7 +155,6 @@ func main() {
    }

    tag := " (govmomi simulator)"
-   model.ServiceContent.About.Name += tag
    model.ServiceContent.About.OsType = runtime.GOOS + "-" + runtime.GOARCH

    esx.HostSystem.Summary.Hardware.Vendor += tag

We can add a way to disable that in vcsim. Terraform could also use a fix to avoid that crash and a change tolerate the product name suffix.

Satak commented 3 years ago

Nice find. Finally we might have proper TF support :-)

dougm commented 3 years ago

Also needed to add a few pieces of functionality to vcsim. It's working with your config now, with customize uncommented too. There's likely more vcsim additions needed for other terraform features, please open new issues if you run into them!