hashicorp / terraform-provider-vsphere

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

Terraform crash after two failed attempts to connect to vSphere vCenter, correcting the access credentials and making third attempt #221

Closed hashibot closed 6 years ago

hashibot commented 6 years ago

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


Terraform Version

0.10.7

Terraform Configuration Files

variables.tf

variable "vsphere_vcenter" {} variable "vsphere_user" {} variable "vsphere_password" {} variable "ssh_root_password" {}

variable "vsphere_datacenter" {}

variable "datastore" { description = "datastore is really a property of resource pool so this is a map" type = "map" }

variable "vm_per_server" {} variable "template" {}

terraform.tfvars

access critera for VMWare vCenter

vsphere_vcenter = "" vsphere_user = "" vsphere_password = "" ssh_root_password = ""

Data center and resource pool pair used to find resource on which to create VM

vsphere_datacenter = "

resource pool determines required datastore

datastore={ "All of dot1" = "Node1_HDD1" "All of dot2" = "Node2_HDD1" "All of dot3" = "Node3_HDD1" "All of dot4" = "Node4_HDD1" "All of dot5" = "Node5_HDD1" }

number of VMs per server

vm_per_server = "4"

which template to use including path

template = ""

build.tf

Configure the VMware vSphere Provider

provider "vsphere" { vsphere_server = "${var.vsphere_vcenter}" user = "${var.vsphere_user}" password = "${var.vsphere_password}" allow_unverified_ssl = true }

First server nodes

resource "vsphere_virtual_machine" "Nodes" { count = 17 datacenter = "${var.vsphere_datacenter}" resource_pool = "All of dot${floor(count.index / var.vm_per_server) +1}" #will put the first n VMs on 1st server, next n on second server, etc. name = "Amazeballs_CentOS_7_3_192_16833${count.index + 7}" hostname = "vm${count.index + 1}" vcpu = "24" memory = 12288 domain = ""

# Define the Disks and resources. The first disk should include the template.
disk {
    template = "${var.template}"
    datastore = "${lookup(var.datastore,"All of dot${floor(count.index / var.vm_per_server) +1}")}"
    type ="thin"
}
 # Define the Networking settings for the VM
network_interface {
    label = "VM Network"
    ipv4_gateway = "192.168.35.254"
    ipv4_address = "${cidrhost("192.168.33.0/27", count.index + 7)}"
    ipv4_prefix_length = "22"
}
network_interface {
    label = "Data"
    # Gateway added by the remote exec provisioner as CentOS will pick 'wrong' NIC as default and network connectivity will cease.
    #       ipv4_gateway = "192.168.63.254"
    ipv4_address = "${cidrhost("192.168.63.0/24", count.index + 1)}"
    ipv4_prefix_length = "20"
}
dns_servers = ["137.58.71.251", "137.58.65.3"]

# Provisioner
# find and remove old files in /network-scripts/ containing the IP address, if there are any
# ifconfig link down
# sbin rename link
# mv /network-scripts/oldname to desired name
# set NAME, DEVICE, DEFROUTE and delete the line DOMAIN from /network-scripts/desiredname 
#
# Repeat for 2nd interface but also add gateway
#
#
provisioner "remote-exec" {
    inline = [
      "grep -r ${cidrhost("192.168.33.0/27", count.index + 7)} /etc/sysconfig/network-scripts/ | cut -d: -f1| xargs ls -t | tail -n +2 | xargs rm",
      "ifconfig `grep -r ${cidrhost("192.168.33.0/27", count.index + 7)} /etc/sysconfig/network-scripts/ | cut -d: -f1 | cut -d- -f3` down",
      "/sbin/ip link set `grep -r ${cidrhost("192.168.33.0/27", count.index + 7)} /etc/sysconfig/network-scripts/ | cut -d: -f1 | cut -d- -f3`  name eth0",
      "mv `grep -r ${cidrhost("192.168.33.0/27", count.index + 7)} /etc/sysconfig/network-scripts/ | cut -d: -f1` /etc/sysconfig/network-scripts/ifcfg-eth0",
      "sed -i 's/.*NAME=.*$/NAME=eth0/g' /etc/sysconfig/network-scripts/ifcfg-eth0",
      "sed -i 's/.*DEVICE=.*$/DEVICE=eth0/g' /etc/sysconfig/network-scripts/ifcfg-eth0",
      "sed -i '/DOMAIN/d' /etc/sysconfig/network-scripts/ifcfg-eth0",
      "sed -i '3 a DEFROUTE=yes' /etc/sysconfig/network-scripts/ifcfg-eth0",

      "grep -r ${cidrhost("192.168.63.0/24", count.index + 1)} /etc/sysconfig/network-scripts/ | cut -d: -f1| xargs ls -t | tail -n +2 | xargs rm",
      "ifconfig `grep -r ${cidrhost("192.168.63.0/24", count.index + 1)} /etc/sysconfig/network-scripts/ | cut -d: -f1 | cut -d- -f3` down",
      "/sbin/ip link set `grep -r ${cidrhost("192.168.63.0/24", count.index + 1)} /etc/sysconfig/network-scripts/ | cut -d: -f1 | cut -d- -f3`  name eth1",
      "mv `grep -r ${cidrhost("192.168.63.0/24", count.index + 1)} /etc/sysconfig/network-scripts/ | cut -d: -f1` /etc/sysconfig/network-scripts/ifcfg-eth1",
      "sed -i 's/.*NAME=.*$/NAME=eth1/g' /etc/sysconfig/network-scripts/ifcfg-eth1",
      "sed -i 's/.*DEVICE=.*$/DEVICE=eth1/g' /etc/sysconfig/network-scripts/ifcfg-eth1",
      "sed -i 's/.*DEVICE=.*$/DEVICE=eth1/g' /etc/sysconfig/network-scripts/ifcfg-eth1",
      "sed -i '/DOMAIN/d' /etc/sysconfig/network-scripts/ifcfg-eth1",
      "sed -i '3 a DEFROUTE=no' /etc/sysconfig/network-scripts/ifcfg-eth1",
      "sed -i '5 a GATEWAY=192.168.63.254' /etc/sysconfig/network-scripts/ifcfg-eth1",

      "udevadm trigger",
      "ifconfig eth0 up",
      "ifconfig eth1 up",
      "systemctl restart network",
    ]

    connection {
     type     = "ssh"
     user     = "root"
     password = "${var.ssh_root_password}"
     }
}

}

Debug Output

Should all be in crash log

Crash Output

crash.log

Expected Behavior

Should have reported none to add, change or delete

Actual Behavior

crash error message

Steps to Reproduce

  1. Reboot Windows host
  2. 'terraform init'
  3. 'terraform plan' - The wrong vCenter password was specified in terraform.tfvars
  4. 'terraform plan' - (again) The wrong vCenter password was specified in terraform.tfvars
  5. corrected password
  6. 'terraform plan' - bang.
vancluever commented 6 years ago

Hey @JamesTGrant, just FYI we have a new PR coming in soon which should address these issues.

After that is in I will probably close this issue on advice that you try out the new version of the resource, or have you confirm if building from master fixes things before closing (if it's possible for you to do so).

Stay tune on #244 which should be in in the next week or two (thanksgiving schedules pending).

Thanks!

JamesTGrant commented 6 years ago

using terraform 0.11 with the new vSphere provider 0.4.2 I can confirm this issue is fixed. Also - the new provider is sooo much better and more reliable - not had a single crash in the past few days

vancluever commented 6 years ago

Looks like we forgot to close this issue when #244 was completed - closing it now.