hashicorp / terraform-provider-vsphere

Terraform Provider for VMware vSphere
https://registry.terraform.io/providers/hashicorp/vsphere/
Mozilla Public License 2.0
615 stars 449 forks source link

Terraform plan crashes when a VCenter is unreachable #826

Closed ghost closed 4 years ago

ghost commented 5 years ago

This issue was originally opened by @awslovato as hashicorp/terraform#22471. It was migrated here as a result of the provider split. The original body of the issue is below.


Terraform Version

$ terraform version
Terraform v0.12.6
+ provider.vsphere v1.11.0
...

Terraform Configuration Files

...resource "vsphere_virtual_machine" "stage-tmpltest" {
    name             = "bldsttmpltest"
    num_cpus         = 2
    memory           = 4096
    guest_id         = "${data.vsphere_virtual_machine.stg_win2k16_template.guest_id}"
    resource_pool_id = "${data.vsphere_resource_pool.dcb_pool.id}"
    scsi_type        = "${data.vsphere_virtual_machine.stg_win2k16_template.scsi_type}"
    datastore_id     = "${data.vsphere_datastore.dcb_p2.id}"

    network_interface {
        network_id   = "${data.vsphere_network.vmnet_4.id}"
      }

    disk {
        label            = "disk0"
        size             = "100"
        thin_provisioned = true
        eagerly_scrub    = false
      }

    clone {
      template_uuid  = "${data.vsphere_virtual_machine.stg_win2k16_template.id}"

      customize {
        windows_options {
        computer_name    = "bldsttmpltest"
        admin_password = "${var.admin_password}"
      }
        network_interface {
          ipv4_address = "172.1.14.21"
          dns_domain   = "${var.vmdomain_qa}"
          ipv4_netmask = "24"
          dns_server_list = ["172.1.14.5", "172.1.14.6"]
        }
        ipv4_gateway = "${var.vlan_4_gateway}"
      }
    }
}

Debug Output

https://gist.github.com/awslovato/50318181e7f03ae422630eea3111e1b0

Crash Output

$ 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.

data.vsphere_datacenter.dcb: Refreshing state... data.vsphere_virtual_machine.stg_rabbit_template: Refreshing state... data.vsphere_resource_pool.dcb_pool: Refreshing state... data.vsphere_virtual_machine.stg_bists_template: Refreshing state... data.vsphere_network.vlan_710: Refreshing state... data.vsphere_network.vm_isci: Refreshing state... data.vsphere_network.vm_v3_is: Refreshing state... data.vsphere_datastore.dcb_p4: Refreshing state... data.vsphere_network.vlan_99: Refreshing state... data.vsphere_datastore.dcb_p1: Refreshing state... data.vsphere_datastore.dcb_p2: Refreshing state... data.vsphere_datastore.dcb_p3: Refreshing state... data.vsphere_virtual_machine.stg_win2k16_template: Refreshing state... data.vsphere_compute_cluster.boco: Refreshing state... data.vsphere_network.vmnet_4: Refreshing state... vsphere_virtual_machine.stage-tmpltest: Refreshing state... [id=42325983-2e9e-4c15-45a0-2625c6d3ed70]

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

panic: runtime error: invalid memory address or nil pointer dereference 2019-08-14T11:57:39.629-0600 [DEBUG] plugin.terraform-provider-vsphere_v1.11.0_x4.exe: [signal 0xc0000005 code=0x0 addr=0x18 pc=0x121278f] 2019-08-14T11:57:39.629-0600 [DEBUG] plugin.terraform-provider-vsphere_v1.11.0_x4.exe: 2019-08-14T11:57:39.629-0600 [DEBUG] plugin.terraform-provider-vsphere_v1.11.0_x4.exe: goroutine 375 [running]: 2019-08-14T11:57:39.629-0600 [DEBUG] plugin.terraform-provider-vsphere_v1.11.0_x4.exe: github.com/terraform-providers/terraform-provider-vsphere/vsphere.resourceVSphereVirtualMachineRead(0xc0003a4770, 0x143bca0, 0xc000424f90, 0xc0003a4770, 0x0) 2019-08-14T11:57:39.629-0600 [DEBUG] plugin.terraform-provider-vsphere_v1.11.0_x4.exe: /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-vsphere/vsphere/resource_vsphere_virtual_machine.go:371 +0x69f 2019-08-14T11:57:39.629-0600 [DEBUG] plugin.terraform-provider-vsphere_v1.11.0_x4.exe: github.com/terraform-providers/terraform-provider-vsphere/vendor/github.com/hashicorp/terraform/helper/schema.(Resource).RefreshWithoutUpgrade(0xc00017f680, 0xc0005e0280, 0x143bca0, 0xc000424f90, 0xc0006ac9c0, 0xc0005e0280, 0x0) 2019-08-14T11:57:39.629-0600 [DEBUG] plugin.terraform-provider-vsphere_v1.11.0_x4.exe: /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-vsphere/vendor/github.com/hashicorp/terraform/helper/schema/resource.go:447 +0x123 2019-08-14T11:57:39.629-0600 [DEBUG] plugin.terraform-provider-vsphere_v1.11.0_x4.exe: github.com/terraform-providers/terraform-provider-vsphere/vendor/github.com/hashicorp/terraform/helper/plugin.(GRPCProviderServer).ReadResource(0xc0001564f0, 0x198aae0, 0xc0005d61e0, 0xc0006180c0, 0xc0001564f0, 0xc0005d6150, 0x1457200) 2019-08-14T11:57:39.629-0600 [DEBUG] plugin.terraform-provider-vsphere_v1.11.0_x4.exe: /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-vsphere/vendor/github.com/hashicorp/terraform/helper/plugin/grpc_provider.go:464 +0x354 2019-08-14T11:57:39.629-0600 [DEBUG] plugin.terraform-provider-vsphere_v1.11.0_x4.exe: github.com/terraform-providers/terraform-provider-vsphere/vendor/github.com/hashicorp/terraform/internal/tfplugin5._Provider_ReadResource_Handler(0x16c69e0, 0xc0001564f0, 0x198aae0, 0xc0005d61e0, 0xc0005e0140, 0x0, 0x0, 0x0, 0xc00085ec00, 0xb3c) 2019-08-14T11:57:39.629-0600 [DEBUG] plugin.terraform-provider-vsphere_v1.11.0_x4.exe: /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-vsphere/vendor/github.com/hashicorp/terraform/internal/tfplugin5/tfplugin5.pb.go:2983 +0x245 2019-08-14T11:57:39.629-0600 [DEBUG] plugin.terraform-provider-vsphere_v1.11.0_x4.exe: github.com/terraform-providers/terraform-provider-vsphere/vendor/google.golang.org/grpc.(Server).processUnaryRPC(0xc000076a80, 0x1990f60, 0xc000077680, 0xc0004b8000, 0xc0002c9f20, 0x295ea90, 0x0, 0x0, 0x0) 2019-08-14T11:57:39.629-0600 [DEBUG] plugin.terraform-provider-vsphere_v1.11.0_x4.exe: /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-vsphere/vendor/google.golang.org/grpc/server.go:972 +0x4a9 2019-08-14T11:57:39.629-0600 [DEBUG] plugin.terraform-provider-vsphere_v1.11.0_x4.exe: github.com/terraform-providers/terraform-provider-vsphere/vendor/google.golang.org/grpc.(Server).handleStream(0xc000076a80, 0x1990f60, 0xc000077680, 0xc0004b8000, 0x0) 2019-08-14T11:57:39.629-0600 [DEBUG] plugin.terraform-provider-vsphere_v1.11.0_x4.exe: /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-vsphere/vendor/google.golang.org/grpc/server.go:1252 +0xe09 2019-08-14T11:57:39.629-0600 [DEBUG] plugin.terraform-provider-vsphere_v1.11.0_x4.exe: github.com/terraform-providers/terraform-provider-vsphere/vendor/google.golang.org/grpc.(Server).serveStreams.func1.1(0xc000444580, 0xc000076a80, 0x1990f60, 0xc000077680, 0xc0004b8000) 2019-08-14T11:57:39.629-0600 [DEBUG] plugin.terraform-provider-vsphere_v1.11.0_x4.exe: /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-vsphere/vendor/google.golang.org/grpc/server.go:691 +0xa6 2019-08-14T11:57:39.629-0600 [DEBUG] plugin.terraform-provider-vsphere_v1.11.0_x4.exe: created by github.com/terraform-providers/terraform-provider-vsphere/vendor/google.golang.org/grpc.(Server).serveStreams.func1 2019-08-14T11:57:39.629-0600 [DEBUG] plugin.terraform-provider-vsphere_v1.11.0_x4.exe: /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-vsphere/vendor/google.golang.org/grpc/server.go:689 +0xa8 2019/08/14 11:57:39 [ERROR] : eval: terraform.EvalRefresh, err: rpc error: code = Unavailable desc = transport is closing 2019/08/14 11:57:39 [ERROR] : eval: terraform.EvalSequence, err: rpc error: code = Unavailable desc = transport is closing 2019/08/14 11:57:39 [TRACE] [walkRefresh] Exiting eval tree: vsphere_virtual_machine.stage-tmpltest 2019/08/14 11:57:39 [TRACE] vertex "vsphere_virtual_machine.stage-tmpltest": visit complete 2019/08/14 11:57:39 [TRACE] vertex "vsphere_virtual_machine.stage-tmpltest": dynamic subgraph encountered errors 2019/08/14 11:57:39 [TRACE] vertex "vsphere_virtual_machine.stage-tmpltest": visit complete 2019/08/14 11:57:39 [TRACE] dag/walk: upstream of "provider.vsphere (close)" errored, so skipping 2019/08/14 11:57:39 [TRACE] dag/walk: upstream of "root" errored, so skipping 2019/08/14 11:57:39 [TRACE] statemgr.Filesystem: removing lock metadata file .terraform.tfstate.lock.info 2019/08/14 11:57:39 [TRACE] statemgr.Filesystem: unlocked by closing terraform.tfstate 2019-08-14T11:57:39.641-0600 [DEBUG] plugin: plugin process exited: path=C:\Users\jlovato\src\devops\terraform\tf-boulder\environments\staging.terraform\plugins\windows_amd64\terraform-provider-vsphere_v1.11.0_x4.exe pid=20772 error="exit status 2" 2019-08-14T11:57:39.641-0600 [DEBUG] plugin: plugin exited

Expected Behavior

Normal state attained and ready for apply

Actual Behavior

crash

Steps to Reproduce

  1. terraform plan

    Additional Context

    On second run it appears the issue may be because the VCenter was unreachable. A graceful exit should have happened rather than a crash.

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.

Error: error setting up new vSphere SOAP client: Post https://vcenter.$DOMAIN/sdk: dial tcp 172.21.3.61:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

on provider.tf line 1, in provider "vsphere": 1: provider "vsphere" {

References

koikonom commented 4 years ago

Hi @awslovato, thanks for reporting this issue!

Can you please try upgrading to the latest provider version and try to reproduce this issue? We have made some changes in the code around the behavior of the code that's currently crashing and I would like to see if that fixes the issue.

ghost commented 4 years ago

This behaviour has not happened since upgrading to 1.13.0, although I say that without making the VCenter unavailable. :) I get SOAP errors if I fiddle with the credentials, so on my end, things are ok. Thanks for looking.

aareet commented 4 years ago

Thanks for your response and help @awslovato. In that case, I will close this issue until it's reproduced by someone.