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

Terraform crash when applying vmware config #643

Closed
ghost opened this issue Oct 19, 2018 · 6 comments · Fixed by #666
Closed

Terraform crash when applying vmware config #643

ghost opened this issue Oct 19, 2018 · 6 comments · Fixed by #666
Labels
bug Type: Bug crash Impact: Crash

Comments

@ghost
Copy link

ghost commented Oct 19, 2018

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


Terraform Version

Terraform v0.11.9
+ provider.vsphere v1.8.1

Terraform Configuration Files

# vCenter connection

variable "vsphere_user" {
  description = "vSphere user name"
}

variable "vsphere_password" {
  description = "vSphere password"
}

variable "vsphere_vcenter" {
  description = "vCenter server FQDN or IP"
}

variable "vsphere_unverified_ssl" {
  description = "Is the vCenter using a self signed certificate (true/false)"
}

# VM specifications

variable "vsphere_datacenter" {
  description = "In which datacenter the VM will be deployed"
}

variable "vsphere_vm_name" {
  description = "What is the name of the VM"
}

variable "vsphere_vm_template" {
  description = "Where is the VM template located"
}

variable "vsphere_vm_folder" {
  description = "In which folder the VM will be store"
}

variable "vsphere_cluster" {
  description = "In which cluster the VM will be deployed"
}

variable "vsphere_vcpu_number" {
  description = "How many vCPU will be assigned to the VM (default: 1)"
  default     = "1"
}

variable "vsphere_memory_size" {
  description = "How much RAM will be assigned to the VM (default: 1024)"
  default     = "1024"
}

variable "vsphere_datastore" {
  description = "What is the name of the VM datastore"
}

/*
variable "vsphere_datastore_cluster" {
  description = "What is the name of the VM datastore cluster"
}
*/

variable "vsphere_port_group" {
  description = "In which port group the VM NIC will be configured (default: VM Network)"
  default     = "VM Network"
}

variable "vsphere_ipv4_address" {
  description = "What is the IPv4 address of the VM"
}

variable "vsphere_ipv4_netmask" {
  description = "What is the IPv4 netmask of the VM (default: 24)"
  default     = "24"
}

variable "vsphere_ipv4_gateway" {
  description = "What is the IPv4 gateway of the VM"
}

variable "vsphere_dns_servers" {
  description = "What are the DNS servers of the VM (default: 8.8.8.8,5.5.5.5)"
  default     = "8.8.8.8,5.5.5.5"
}

variable "vsphere_domain" {
  description = "What is the domain of the VM"
}

variable "vsphere_time_zone" {
  description = "What is the timezone of the VM (default: UTC)"
  default     = "UTC"
}

variable "windows_pass" {
  description = "What is the guest OS windows password"
  default     = "Password1"
}

#===============================================================================
# vSphere Provider
#===============================================================================
provider "vsphere" {
//  version        = "1.5.0"
  vsphere_server = "${var.vsphere_vcenter}"
  user           = "${var.vsphere_user}"
  password       = "${var.vsphere_password}"

  allow_unverified_ssl = "${var.vsphere_unverified_ssl}"
}

#===============================================================================
# vSphere Data
#===============================================================================

data "vsphere_datacenter" "dc" {
  name = "${var.vsphere_datacenter}"
}

data "vsphere_compute_cluster" "cluster" {
  name          = "${var.vsphere_cluster}"
  datacenter_id = "${data.vsphere_datacenter.dc.id}"
}


data "vsphere_datastore" "datastore" {
  name          = "${var.vsphere_datastore}"
  datacenter_id = "${data.vsphere_datacenter.dc.id}"
}


data "vsphere_network" "network" {
  name          = "${var.vsphere_port_group}"
  datacenter_id = "${data.vsphere_datacenter.dc.id}"
}

data "vsphere_virtual_machine" "template" {
  name          = "${var.vsphere_vm_template}"
  datacenter_id = "${data.vsphere_datacenter.dc.id}"
}

/*
data "vsphere_datastore_cluster" "datastore_cluster" {
  name          = "${var.vsphere_datastore_cluster}"
  datacenter_id = "${data.vsphere_datacenter.dc.id}"
}
*/

#===============================================================================
# vSphere Resources
#===============================================================================

# Create a vSphere VM folder #
resource "vsphere_folder" "terraform-winbase-01" {
  path          = "${var.vsphere_vm_folder}"
  type          = "vm"
  datacenter_id = "${data.vsphere_datacenter.dc.id}"
}

# Create a vSphere VM in the folder #
resource "vsphere_virtual_machine" "terraform-winbase" {
  # VM placement #
  name             = "${var.vsphere_vm_name}"
  resource_pool_id = "${data.vsphere_compute_cluster.cluster.resource_pool_id}"
  datastore_id     = "${data.vsphere_datastore.datastore.id}"
//  folder           = "${vsphere_folder.terraform-winbase-01.path}"

  # VM resources #
  num_cpus = "${var.vsphere_vcpu_number}"
  memory   = "${var.vsphere_memory_size}"

  # Guest OS #
  guest_id = "${data.vsphere_virtual_machine.template.guest_id}"

  # VM storage #
  disk {
    label            = "${var.vsphere_vm_name}.vmdk"
    size             = "${data.vsphere_virtual_machine.template.disks.0.size}"
    thin_provisioned = "${data.vsphere_virtual_machine.template.disks.0.thin_provisioned}"
    eagerly_scrub    = "${data.vsphere_virtual_machine.template.disks.0.eagerly_scrub}"
  }

  # VM networking #
  network_interface {
    network_id   = "${data.vsphere_network.network.id}"
    adapter_type = "${data.vsphere_virtual_machine.template.network_interface_types[0]}"
  }

  # Customization of the VM #
  clone {
    template_uuid = "${data.vsphere_virtual_machine.template.id}"

    customize {
//      linux_options {
//        host_name = "${var.vsphere_vm_name}"
//        domain    = "${var.vsphere_domain}"
//        time_zone = "${var.vsphere_time_zone}"
//      }

      windows_options {
        computer_name  = "${var.vsphere_vm_name}"
        workgroup      = "WORKGROUP"
        admin_password = "${var.windows_pass}"
      }

      network_interface {
        ipv4_address = "${var.vsphere_ipv4_address}"
        ipv4_netmask = "${var.vsphere_ipv4_netmask}"
      }

      ipv4_gateway    = "${var.vsphere_ipv4_gateway}"
      dns_server_list = ["${var.vsphere_dns_servers}"]
      dns_suffix_list = ["${var.vsphere_domain}"]
    }
  }
}

Debug Output

Crash Output

crash.log

Expected Behavior

Actual Behavior

terraform plan completed successfully but terraform apply -auto-approve did not

Steps to Reproduce

  1. terraform init
  2. terraform plan
  3. terraform apply -auto-approve

Additional Context

References

@bill-rich
Copy link
Contributor

Hi @rh917! It looks like var.vsphere_domain is not being set. This ends up with a list with an empty value in it, which causes a type error. This needs to be addressed in the provider so it results in a useful error message instead of a crash. In the meantime, if you ensure var.vsphere_domain is set, it should get you unblocked. Let me know if that doesn't work for you. I'll keep the issue open to track the problem until it is fixed.

@wmariuss
Copy link

Same issue with:

terraform version 

Terraform v0.11.10
+ provider.vsphere v1.5.0

crash.log

In my case vsphere_domain was set.

@wmariuss
Copy link

Same for:

Terraform v0.11.10
+ provider.vsphere v1.9.0

crash (1).log

@bill-rich
Copy link
Contributor

bill-rich commented Nov 15, 2018

@wmariuss Based on your crash.log, it looks like you're issue is probably similar, but as a result of dns_server_list, being an empty list. When the fix is in that covers dns_suffix_list is done, dns_server_list will also be fixed.

@wmariuss
Copy link

Hmm, you right. I setup dns server list with default one and works.

@wmariuss
Copy link

I think you can close this issue.

@ghost ghost locked and limited conversation to collaborators Apr 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Type: Bug crash Impact: Crash
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants