elsudano / terraform-provider-vmworkstation

VmWare Workstation Pro provider for Terraform
MIT License
52 stars 18 forks source link

Error on Windows 10: panic: runtime error: invalid memory address or nil pointer dereference #7

Open graememeyer opened 3 years ago

graememeyer commented 3 years ago

I'm trying out the vmware workstation provider and unfortunately get an error. I'm new to Terraform, so I may have something very basic wrong with my configuration/code.

I'm using:

Edition Windows 10 Pro
Version 21H1
OS build    19043.1110

VMware Workstation Pro

Build 15.5.7 build-17171714

Terraform

PS C:\Users\graem\terraform\learn-terraform-aws-instance> terraform --version
Terraform v1.0.3
on windows_amd64
+ provider registry.terraform.io/elsudano/vmworkstation v0.2.3

My main.tf:

terraform {
  required_providers {
    vmworkstation = {
      source  = "elsudano/vmworkstation"
      version = "0.2.3"
    }
  }
  required_version = ">= 0.14.5"
}

provider "vmworkstation" {
  user = "vmware"
  password = "mypassword"
  url = "http://localhost:8697/api"
  https = false
  debug = true
}

resource "vmworkstation_vm" "test_machine" {
  sourceid     = "QTR6F6BLLM7EVP62S4GIMKL4CJ5RJE84"
  denomination = "NewInstance"
  description  = "TestBox"
  path         = "C:\\Users\\graem\\Documents\\Virtual Machines\\Test"
  processors   = "2"
  memory       = "1024"
}

And here's the error + stack trace I get:

vmworkstation_vm.test_machine: Creating...
╷
│ Error: Plugin did not respond
│ 
│   with vmworkstation_vm.test_machine,
│   on main.tf line 20, in resource "vmworkstation_vm" "test_machine":
│   20: resource "vmworkstation_vm" "test_machine" {
│ 
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ApplyResourceChange call. The plugin logs may contain more details.
╵

Stack trace from the terraform-provider-vmworkstation_v0.2.3.exe plugin:

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x0 pc=0x14029b3]

goroutine 55 [running]:
github.com/elsudano/terraform-provider-vmworkstation/vmworkstation.resourceVMWSVmCreate(0xc000330510, 0x16d10e0, 0xc0001ead80, 0x2, 0x1c9ae60)
        /home/usuario/go/src/github.com/elsudano/terraform-provider-vmworkstation/vmworkstation/resource_vmworkstation_vm.go:82 +0x5d3
github.com/hashicorp/terraform/helper/schema.(*Resource).Apply(0xc000304080, 0xc0001657a0, 0xc00030e400, 0x16d10e0, 0xc0001ead80, 0x1, 0x0, 0x0)
        /home/usuario/go/pkg/mod/github.com/hashicorp/terraform@v0.13.3/helper/schema/resource.go:308 +0x3d8
github.com/hashicorp/terraform/helper/schema.(*Provider).Apply(0xc000304200, 0xc0004ada08, 0xc0001657a0, 0xc00030e400, 0xc000006550, 0x1826478, 0xc000006550)
        /home/usuario/go/pkg/mod/github.com/hashicorp/terraform@v0.13.3/helper/schema/provider.go:297 +0xa5
github.com/hashicorp/terraform/helper/plugin.(*GRPCProviderServer).ApplyResourceChange(0xc000312018, 0x1825aa0, 0xc000089800, 0xc0001655e0, 0xc000312018, 0xc000089800, 0xc00058bb80)        
        /home/usuario/go/pkg/mod/github.com/hashicorp/terraform@v0.13.3/helper/plugin/grpc_provider.go:923 +0x905
github.com/hashicorp/terraform/internal/tfplugin5._Provider_ApplyResourceChange_Handler(0x16f55c0, 0xc000312018, 0x1825aa0, 0xc000089800, 0xc000338a80, 0x0, 0x1825aa0, 0xc000089800, 0xc0004ae000, 0x192)
        /home/usuario/go/pkg/mod/github.com/hashicorp/terraform@v0.13.3/internal/tfplugin5/tfplugin5.pb.go:3303 +0x222
google.golang.org/grpc.(*Server).processUnaryRPC(0xc000584780, 0x182ce38, 0xc000585500, 0xc0002ec000, 0xc000088d20, 0x1c481c0, 0x0, 0x0, 0x0)
        /home/usuario/go/pkg/mod/google.golang.org/grpc@v1.27.1/server.go:1024 +0x522
google.golang.org/grpc.(*Server).handleStream(0xc000584780, 0x182ce38, 0xc000585500, 0xc0002ec000, 0x0)
        /home/usuario/go/pkg/mod/google.golang.org/grpc@v1.27.1/server.go:1313 +0xd4c
google.golang.org/grpc.(*Server).serveStreams.func1.1(0xc00008a190, 0xc000584780, 0x182ce38, 0xc000585500, 0xc0002ec000)
        /home/usuario/go/pkg/mod/google.golang.org/grpc@v1.27.1/server.go:722 +0xb2
created by google.golang.org/grpc.(*Server).serveStreams.func1
        /home/usuario/go/pkg/mod/google.golang.org/grpc@v1.27.1/server.go:720 +0xa8

Error: The terraform-provider-vmworkstation_v0.2.3.exe plugin crashed!

This is always indicative of a bug within the plugin. It would be immensely
helpful if you could report the crash with the plugin's maintainers so that it
can be fixed. The output above should help diagnose the issue.

I would really love this to work on Windows, and I see that that is a relatively new feature, so I'm happy to help out with any debugging and testing!

elsudano commented 3 years ago

Hi graememeyer,

First, sorry for the delay, right now I'm very busy but I will try take a look later.

Thanks for your interest in my provider, I will try to create a lab to understand which is your error, maybe I will have to request you some logs file

Kind regards

nagaprashanth0006 commented 3 years ago

Even I've got this exact error when tried to create VMs from my windows 10 machine.

ARGO1960 commented 3 years ago

Well I have the same result... WIN10 21H1 Workstation 15

austinnichols101 commented 3 years ago

Similar/same issue running terraform on:

Terraform v1.0.9
on linux_amd64
+ provider registry.terraform.io/elsudano/vmworkstation v0.2.1
/usr/bin/terraform apply

Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # vmworkstation_vm.test_machine will be created
  + resource "vmworkstation_vm" "test_machine" {
      + denomination = "NewInstance"
      + description  = "<frontend_description>"
      + id           = (known after apply)
      + memory       = 512
      + processors   = 1
      + sourceid     = "QTR6F6BLLM7EVP62S4GIMKL4CJ5RJE84"
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Changes to Outputs:
  + vmws_frontend_id = (known after apply)

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

vmworkstation_vm.test_machine: Creating...

Stack trace from the terraform-provider-vmworkstation_v0.2.3 plugin:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x99da13]

goroutine 29 [running]:
github.com/elsudano/terraform-provider-vmworkstation/vmworkstation.resourceVMWSVmCreate(0xc000510480, 0xc6a260, 0xc000217000, 0x2, 0x121dfc0)
    /home/usuario/go/src/github.com/elsudano/terraform-provider-vmworkstation/vmworkstation/resource_vmworkstation_vm.go:82 +0x5b3
github.com/hashicorp/terraform/helper/schema.(*Resource).Apply(0xc000294080, 0xc0001c9110, 0xc000288680, 0xc6a260, 0xc000217000, 0x1, 0x0, 0x0)
    /home/usuario/go/pkg/mod/github.com/hashicorp/terraform@v0.13.3/helper/schema/resource.go:308 +0x3b8
github.com/hashicorp/terraform/helper/schema.(*Provider).Apply(0xc000294200, 0xc00048ba08, 0xc0001c9110, 0xc000288680, 0xc00013e540, 0xdbd550, 0xc00013e540)
    /home/usuario/go/pkg/mod/github.com/hashicorp/terraform@v0.13.3/helper/schema/provider.go:297 +0x99
github.com/hashicorp/terraform/helper/plugin.(*GRPCProviderServer).ApplyResourceChange(0xc000286038, 0xdbcb40, 0xc000514f60, 0xc0001c8fc0, 0xc000286038, 0xc000514f60, 0xc00059ab80)
    /home/usuario/go/pkg/mod/github.com/hashicorp/terraform@v0.13.3/helper/plugin/grpc_provider.go:923 +0x8e5
github.com/hashicorp/terraform/internal/tfplugin5._Provider_ApplyResourceChange_Handler(0xc8e100, 0xc000286038, 0xdbcb40, 0xc000514f60, 0xc000300ba0, 0x0, 0xdbcb40, 0xc000514f60, 0xc000150840, 0x152)
    /home/usuario/go/pkg/mod/github.com/hashicorp/terraform@v0.13.3/internal/tfplugin5/tfplugin5.pb.go:3303 +0x214
google.golang.org/grpc.(*Server).processUnaryRPC(0xc000103980, 0xdc3838, 0xc000582a80, 0xc000501a00, 0xc000241020, 0x11e0680, 0x0, 0x0, 0x0)
    /home/usuario/go/pkg/mod/google.golang.org/grpc@v1.27.1/server.go:1024 +0x522
google.golang.org/grpc.(*Server).handleStream(0xc000103980, 0xdc3838, 0xc000582a80, 0xc000501a00, 0x0)
    /home/usuario/go/pkg/mod/google.golang.org/grpc@v1.27.1/server.go:1313 +0xd2c
google.golang.org/grpc.(*Server).serveStreams.func1.1(0xc00028a1f0, 0xc000103980, 0xdc3838, 0xc000582a80, 0xc000501a00)
    /home/usuario/go/pkg/mod/google.golang.org/grpc@v1.27.1/server.go:722 +0xab
created by google.golang.org/grpc.(*Server).serveStreams.func1
    /home/usuario/go/pkg/mod/google.golang.org/grpc@v1.27.1/server.go:720 +0xa5

Error: The terraform-provider-vmworkstation_v0.2.3 plugin crashed!

This is always indicative of a bug within the plugin. It would be immensely
helpful if you could report the crash with the plugin's maintainers so that it
can be fixed. The output above should help diagnose the issue.

╷
│ Error: Plugin did not respond
│ 
│   with vmworkstation_vm.test_machine,
│   on main.tf line 19, in resource "vmworkstation_vm" "test_machine":
│   19: resource "vmworkstation_vm" "test_machine" {
│ 
│ The plugin encountered an error, and failed to respond to the
│ plugin.(*GRPCProvider).ApplyResourceChange call. The plugin logs may
│ contain more details.
╵

Process finished with exit code 1
elsudano commented 3 years ago

Hi team,

First of all, sorry for the inconvenience.

In second place, thanks for your feedback, with that feedback I hope found the issue

Please still tuned for more information

Regards

yahmadpen commented 2 years ago

any update on this ?

elsudano commented 2 years ago

Hi guys,

Yep, I have an update about that, I think that the root cause is when the API try to save at the same time some resources in windows, I mean, the API try to save some files at the same time and for that crashed.

I will try to reproduce the error also in my Windows, I hope can inform you soon

Regards

Piranha900 commented 2 years ago

Hello!

Same here with :

Here the stacktrace:

var.vmws_reource_frontend_description                                                                                                                                                                                                         
  (Required) The Description at later maybe to explain the instance                                                                                                                                                                           

  Enter a value: /home/piranha900/Development/terraform/test                                                                                                                                                                                  

var.vmws_reource_frontend_path                                                                                                                                                                                                                
  (Required) The Path where will be our instance in VmWare                                                                                                                                                                                    

  Enter a value: /home/piranha900/Development/terraform/test                                                                                                                                                                                  

var.vmws_reource_frontend_sourceid                                                                                                                                                                                                            
  (Required) The ID of the VM that to use for clone at the new                                                                                                                                                                                

  Enter a value: 12345                                                                                                                                                                                                                        

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:                                                                                                    
  + create                                                                                                                                                                                                                                    

Terraform will perform the following actions:                                                                                                                                                                                                 

  # vmworkstation_vm.test_machine will be created 
  + resource "vmworkstation_vm" "test_machine" {                                                                                                                                                                                       [10/34]
      + denomination = "NewInstance"                                                                                                                                                                                                          
      + description  = "/home/piranha900/Development/terraform/test"                                                                                                                                                                          
      + id           = (known after apply)                                                                                                                                                                                                    
      + memory       = 512                                                                                                                                                                                                                    
      + path         = "/home/piranha900/Development/terraform/test"                                                                                                                                                                          
      + processors   = 1                                                                                                                                                                                                                      
      + sourceid     = "12345"                                                                                                                                                                                                                
    }                                                                                                                                                                                                                                         

Plan: 1 to add, 0 to change, 0 to destroy.                                                                                                                                                                                                    

Changes to Outputs:                                                                                                    
  + vmws_frontend_id = (known after apply)                 

Do you want to perform these actions?                     
  Terraform will perform the actions described above.      
  Only 'yes' will be accepted to approve.                                                                              

  Enter a value: yes              

vmworkstation_vm.test_machine: Creating...                 
╷                     
│ Error: Request cancelled                                 
│                                                          
│   with vmworkstation_vm.test_machine,                                                                                                                                                                                                       
│   on main.tf line 17, in resource "vmworkstation_vm" "test_machine":                                                 
│   17: resource "vmworkstation_vm" "test_machine" {       
│                                            
│ The plugin.(*GRPCProvider).ApplyResourceChange request was cancelled.                                                
╵                                                

Stack trace from the terraform-provider-vmworkstation_v1.0.3 plugin:                                                   

panic: runtime error: invalid memory address or nil pointer dereference                                                
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xc07494]                                                 

goroutine 83 [running]: 
github.com/elsudano/terraform-provider-vmworkstation/vmworkstation.resourceVMWSVmCreate(0xd177e0, {0xdc9280, 0xc0007cd000})                                                                                                                   
        /home/usuario/go/src/github.com/elsudano/terraform-provider-vmworkstation/vmworkstation/resource_vmworkstation_vm.go:82 +0x414                                                                                                        
github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Resource).Apply(0xc0004200a0, 0xc0000dd810, 0xc0008969a0, {0xdc9280, 0xc0007cd000})                                                                                                 
        /home/usuario/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk@v1.17.2/helper/schema/resource.go:320 +0x438                                                                                                                       
github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Provider).Apply(0xc000688280, 0xc0000fba68, 0xe1d3f7, 0xf)   
        /home/usuario/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk@v1.17.2/helper/schema/provider.go:294 +0x70 
github.com/hashicorp/terraform-plugin-sdk/internal/helper/plugin.(*GRPCProviderServer).ApplyResourceChange(0xc0006705a0, {0xc000183960, 0x588226}, 0xc000183960)                                                                              
        /home/usuario/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk@v1.17.2/internal/helper/plugin/grpc_provider.go:895 +0x7c5                                                                                                         
github.com/hashicorp/terraform-plugin-sdk/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0xde7800, 0xc0006705a0}, {0xfe99f0, 0xc0001aee40}, 0xc000814a80, 0x0)                                                                     
        /home/usuario/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk@v1.17.2/internal/tfplugin5/tfplugin5.pb.go:3305 +0x170                                                                                                             
google.golang.org/grpc.(*Server).processUnaryRPC(0xc0005e2700, {0xff8d78, 0xc0001a6a80}, 0xc00068c300, 0xc0006665a0, 0x15de9a0, 0x0)                                                                                                          
        /home/usuario/go/pkg/mod/google.golang.org/grpc@v1.32.0/server.go:1194 +0xc8f                                  
google.golang.org/grpc.(*Server).handleStream(0xc0005e2700, {0xff8d78, 0xc0001a6a80}, 0xc00068c300, 0x0)               
        /home/usuario/go/pkg/mod/google.golang.org/grpc@v1.32.0/server.go:1517 +0xa2a                                  
google.golang.org/grpc.(*Server).serveStreams.func1.2()
        /home/usuario/go/pkg/mod/google.golang.org/grpc@v1.32.0/server.go:859 +0x98                                    
created by google.golang.org/grpc.(*Server).serveStreams.func1                                                         
        /home/usuario/go/pkg/mod/google.golang.org/grpc@v1.32.0/server.go:857 +0x294                                   

Error: The terraform-provider-vmworkstation_v1.0.3 plugin crashed!    

This is always indicative of a bug within the plugin. It would be immensely                                            
helpful if you could report the crash with the plugin's maintainers so that it
can be fixed. The output above should help diagnose the issue.  
elsudano commented 2 years ago

Hi Piranha900,

After review your reply, I have to say that I think that your problem is different, I mean, If you review the documentation https://registry.terraform.io/providers/elsudano/vmworkstation/latest/docs, you can see that the sourceID can't have this value.

Maybe you make sure that the sourceID that the virtual machine test had this sourceID, you can check this in the path https://localhost:8697/api of your laptop when you enable the API of the Workstation.

Regards

justinpmcgraw commented 2 years ago

Any update on this? For me the plugin starts to work, you see the new VM folder get created and then clone the machine, but then the plugin crashes on what I assume to be the customize resources phase.

I really want this to work as I prefer vmware workstation to virtual box.

moozer commented 2 years ago

I am seeing the same issue on debian/bookworm and terraform 1.1.6

I used wireshark and saw the following:

POST /api/vms HTTP/1.1
Host: localhost:8697
User-Agent: Go-http-client/1.1
Content-Length: 65
Authorization: Basic YWRtaW46eWZpc0t0OFlKIQ==
Content-Type: application/vnd.vmware.vmw.rest-v1+json
Accept-Encoding: gzip

{"name":"newname","parentId":"BE7ROCQQMPL9M84NKC319V44UGQPL5US"}
HTTP/1.1 409 Conflict
Cache-Control: no-cache
Content-Length: 68
Content-Type: application/vnd.vmware.vmw.rest-v1+json
Date: Mon, 21 Feb 2022 21:40:40 GMT

{
  "Code": 108,
  "Message": "The virtual machine already exists"
}

It does exist, and vmware gui just does not show it. I deleted it.

Rerunning terraform gave me the exact same error (verified by wirehark) on the first run.

Checking the folder, it is on disk, but the only file is "newname.nvram"

moozer commented 2 years ago

Some more debugging

$ TF_LOG=debug terraform apply
...
2022-02-22T23:24:33.659+0100 [DEBUG] provider.terraform-provider-vmworkstation_v1.0.3: 2022/02/22 23:24:33 [WSAPICLI] Fi: wsapiclient.go Fu: NewClient Obj:Input values "https://localhost:8697/api", "admin", "Adm1n#00", true, false
...

I read it as having the wrong credentials. These are not the url, nor password from my main.tf.

It looks like the credentials from https://github.com/elsudano/terraform-provider-vmworkstation/blob/40dec72dd9d49802d34832323e59d3ac503d6707/main.go#L21-L23

moozer commented 2 years ago

I did some more digging

The fail is at this line

https://github.com/elsudano/terraform-provider-vmworkstation/blob/40dec72dd9d49802d34832323e59d3ac503d6707/vmworkstation/resource_vmworkstation_vm.go#L82

It break when the resource id is unknown - like when creating new instances. Commenting this line, makes the provider not crash.

I'm getting a new error:

╷ │ Error: Provider produced inconsistent result after apply │ │ When applying changes to vmworkstation_vm.test_machine, provider "provider[\"localhost/moozer/vmworkstation\"]" produced an unexpected new │ value: Root resource was present, but now absent. │ │ This is a bug in the provider, which should be reported in the provider's own issue tracker. ╵

I don't know what this means. I'll dig some more at a later time.

moozer commented 2 years ago

My impression is that there is an error in how the url+user+ass is used.

I get this in the logs 2022-02-23T23:19:36.350+0100 [DEBUG] provider.terraform-provider-vmworkstation_v1.0.4: 2022/02/23 23:19:36 [WSAPICLI] Fi: wsapiclient.go Fu: NewClient Obj:Input values "https://localhost:8697/api", "admin", "Adm1n#00", true, false

This is the default values from a separate library which included wsapiclient.go. That's next on my to-check lst.

graememeyer commented 2 years ago

@moozer have you any idea how to build/debug a Terraform provider? I have no experience with Go, but I'm tempted to give it a shot later this week if the setup hurdle isn't too high.

Edit: Though I'm on VMware 16 now so will need to see if this is still a problem

elsudano commented 2 years ago

First of all sorry for the delay, and thank for the troubleshooting

Said that, @moozer your first issue is because you try to redeploy a instance without delete the folder and then the provider fails because the folder exist

About of the second issues is because the API of WS in the 16th version, change the behavior about of create a instance

Moreover, I have searching another issues about of why the API don't accept change parameters regarding of one instance created and fails when I tried that.

Believe guys I trying to solve this but is a problem when VmWare don't respond my questions ;-)

moozer commented 2 years ago

@moozer have you any idea how to build/debug a Terraform provider? I have no experience with Go, but I'm tempted to give it a shot later this week if the setup hurdle isn't too high.

Edit: Though I'm on VMware 16 now so will need to see if this is still a problem

I'm on 16, and it is craching.

I am not strong with go, but felt like trying it. I find it difficult to get a good workflow for debugging this kind of problem. Installing go and using goreleaser works nicely. There is a Makefile, so it's trivial to build.

moozer commented 2 years ago

@elsudano We are just happy that you have made the provider, and we want to use it.

At first glance it seemed like a trivial issue, where it crashes due to an unitialized variable, but removing that, just show the issue with somthing that breaks in the wsapi module.

It seems to be this one that is automatically imported into the go program: https://github.com/elsudano/vmware-workstation-api-client

elsudano commented 2 years ago

@moozer have you any idea how to build/debug a Terraform provider? I have no experience with Go, but I'm tempted to give it a shot later this week if the setup hurdle isn't too high.

Edit: Though I'm on VMware 16 now so will need to see if this is still a problem

As @moozer said, just follow the makefile

elsudano commented 2 years ago

@elsudano We are just happy that you have made the provider, and we want to use it.

At first glance it seemed like a trivial issue, where it crashes due to an unitialized variable, but removing that, just show the issue with somthing that breaks in the wsapi module.

It seems to be this one that is automatically imported into the go program: https://github.com/elsudano/vmware-workstation-api-client

Thanks for your time make the troubleshooting, the problem here is that this module is necessary for call at API of VMware and sometimes is a little bit weird the kind of calls that I have to do for take the data and for that seems that this module fails, but if you try the VMware API manually fails as well this is the root cause.

Again I will trying to solve a soon as possible, in fact I'm proud that my module will be used by more people, for that I want to resolve these issues

elsudano commented 2 years ago

Hi everyone

Maybe I found the error for that issue, when I'm searching in my code about why we can't connect correctly at the API Rest, and reading the documentation of VmWare Workstation PRO 16 I can see the following lines:

https://docs.vmware.com/en/VMware-Workstation-Pro/16.0/com.vmware.ws.using.doc/GUID-C3361DF5-A4C1-432E-850C-8F60D83E5E2B.html

VmWare Workstation 15 PRO imagen

VmWare Workstation 16 PRO imagen

As you can see, the difference between 15 and 16 is that the version 16 not is possible access remotely at the API REST, JUST we can reach API Rest by localhost

Could you confirm me that all of you try access locally at the API Rest?

I looking forward for your comments

Regards

graememeyer commented 2 years ago

I confirm I was only trying local access over localhost and thus this should not have been an issue.

moozer commented 2 years ago

I am working on tracing the issue in my end. The API is exposed using HTTP (not HTTPS) , since I am working with wireshark to understand the issue.

As I see it, I have two issues.

  1. The provider plugin craches when the terraform parameter are wrong. There are some error handling that could be improved so the user knows about configuration issues.
  2. The "register vm" step fails.

Looking into the http stream, the failing part is

<snip>... other HTTP  requests ... </snip>
POST /api/vms/registration HTTP/1.1
Host: localhost:8697
User-Agent: Go-http-client/1.1
Content-Length: 62
Authorization: Basic YWRtaW46eWZpc0t0OFlKIQ==
Content-Type: application/vnd.vmware.vmw.rest-v1+json
Accept-Encoding: gzip

{"name":"newname","path":"/mnt/storage-general/moz/vmware-vm"}HTTP/1.1 400 Bad Request
Cache-Control: no-cache
Content-Length: 73
Content-Type: application/vnd.vmware.vmw.rest-v1+json
Date: Mon, 28 Feb 2022 23:16:46 GMT

{
  "Code": 100,
  "Message": "One of the parameters was invalid: path"
}

The correct path should, in this case, be "/home/moz/storage/vmware-vm/newname/newname.vmx", ie. the path of the new .vmx file.

Updating main.tf to

resource "vmworkstation_vm" "test_machine" {
  sourceid     = "CVEI3JF7IQAR17HTQA5NNN947UEFNIAT"
  denomination = "newname"
  description  = "some description"
  path         = "/mnt/storage-general/moz/vmware-vm/newname/newname.vmx"
  processors   = 2
  memory       = 1024
}

yields

...

POST /api/vms/registration HTTP/1.1
Host: localhost:8697
User-Agent: Go-http-client/1.1
Content-Length: 82
Authorization: Basic YWRtaW46eWZpc0t0OFlKIQ==
Content-Type: application/vnd.vmware.vmw.rest-v1+json
Accept-Encoding: gzip

{"name":"newname","path":"/mnt/storage-general/moz/vmware-vm/newname/newname.vmx"}HTTP/1.1 500 Internal Server Error
Cache-Control: no-cache
Content-Length: 156
Content-Type: application/vnd.vmware.vmw.rest-v1+json
Date: Mon, 28 Feb 2022 23:34:44 GMT

{
  "Code": 147,
  "Message": "Failed to add VM to the VM inventory file because VM already added: /mnt/storage-general/moz/vmware-vm/newname/newname.vmx"
}

and the vm appears in the GUI. Maybe the register step is not needed?

Note. I know that this is not aligned with some of my previous findings. My understanding of the program and the issue has improved :smiley:

elsudano commented 2 years ago

I am working on tracing the issue in my end. The API is exposed using HTTP (not HTTPS) , since I am working with wireshark to understand the issue.

As I see it, I have two issues.

1. The provider plugin craches when the terraform parameter are wrong. There are some error handling that could be improved so the user knows about configuration issues.

2. The "register vm" step fails.

Looking into the http stream, the failing part is

<snip>... other HTTP  requests ... </snip>
POST /api/vms/registration HTTP/1.1
Host: localhost:8697
User-Agent: Go-http-client/1.1
Content-Length: 62
Authorization: Basic YWRtaW46eWZpc0t0OFlKIQ==
Content-Type: application/vnd.vmware.vmw.rest-v1+json
Accept-Encoding: gzip

{"name":"newname","path":"/mnt/storage-general/moz/vmware-vm"}HTTP/1.1 400 Bad Request
Cache-Control: no-cache
Content-Length: 73
Content-Type: application/vnd.vmware.vmw.rest-v1+json
Date: Mon, 28 Feb 2022 23:16:46 GMT

{
  "Code": 100,
  "Message": "One of the parameters was invalid: path"
}

The correct path should, in this case, be "/home/moz/storage/vmware-vm/newname/newname.vmx", ie. the path of the new .vmx file.

Updating main.tf to

resource "vmworkstation_vm" "test_machine" {
  sourceid     = "CVEI3JF7IQAR17HTQA5NNN947UEFNIAT"
  denomination = "newname"
  description  = "some description"
  path         = "/mnt/storage-general/moz/vmware-vm/newname/newname.vmx"
  processors   = 2
  memory       = 1024
}

yields

...

POST /api/vms/registration HTTP/1.1
Host: localhost:8697
User-Agent: Go-http-client/1.1
Content-Length: 82
Authorization: Basic YWRtaW46eWZpc0t0OFlKIQ==
Content-Type: application/vnd.vmware.vmw.rest-v1+json
Accept-Encoding: gzip

{"name":"newname","path":"/mnt/storage-general/moz/vmware-vm/newname/newname.vmx"}HTTP/1.1 500 Internal Server Error
Cache-Control: no-cache
Content-Length: 156
Content-Type: application/vnd.vmware.vmw.rest-v1+json
Date: Mon, 28 Feb 2022 23:34:44 GMT

{
  "Code": 147,
  "Message": "Failed to add VM to the VM inventory file because VM already added: /mnt/storage-general/moz/vmware-vm/newname/newname.vmx"
}

and the vm appears in the GUI. Maybe the register step is not needed?

Note. I know that this is not aligned with some of my previous findings. My understanding of the program and the issue has improved 😃

Juummm first of all, thanks a lot for the troubleshooting, I tested before with Wireshark but my results was different.

I mean, my previous results of the troubleshooting was an errors in the API, I mean, that the result of API was a unknown error, and close it the communication between API and the provider, maybe that, change in the last version of the API.

The next weekend I will try to review if the register function isn't necessary in the new version

Please stay tuned for the news.

arturzarczynski commented 2 years ago

Almost everything works for me now. The only thing is it completly ignores what I put in 'path' variable and always creates new VM here: /home/art/vmware/NewInstance and dont add it to Workstation console.

Terraform throws this error: vmworkstation_vm.new_machine: Creating... ╷ │ Error: Request cancelled │ │ with vmworkstation_vm.new_machine, │ on resource.tf line 1, in resource "vmworkstation_vm" "new_machine": │ 1: resource "vmworkstation_vm" "new_machine" { │ │ The plugin.(*GRPCProvider).ApplyResourceChange request was cancelled. ╵

Stack trace from the terraform-provider-vmworkstation_v1.0.3 plugin:

panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xc07529]

elsudano commented 2 years ago

Hi Art, thanks for use the provider.

And yes, you are right, this is the problem that we have in this issue, the root cause is because the API of Workstation fails when I try it to change the configuration on the instance.

if you want to investigate in deeply, you can try to read this link https://vdc-download.vmware.com/vmwb-repository/dcr-public/be7ca070-81c1-422c-955a-ab665a48b988/30817295-87d6-4a40-8056-896cde7164d9/swagger.json

You can see here that you can less path that you can see in your API of WorkStation when you run https://localhost:8697

I will continue try to solve this error but is a few complicate because the API REST fails.

Regards

gitperede commented 2 years ago

Any news guys? Just had the same issue :,(

elsudano commented 9 months ago

Hi guys, after review the API of the VmWare Workstation, they had solved some issues that they had in the API calls, so this weekend I published another version 1.0.4

https://registry.terraform.io/providers/elsudano/vmworkstation/latest

If you want to take a look in order to see if I had be able to solve the issue, up to you.

All the feedback will be welcome

graememeyer commented 9 months ago

Thanks @elsudano.

Do you know which version of the API or VMware Workstation Pro have the new fix? I only have access to version 15 or 16 of workstation pro, so it might be that I won't have access to the fix since the latest version is 17.

elsudano commented 9 months ago

I test it with VMware Workstation 17 and the API version 1.3.1