rakutentech / terraform-provider-vsphere

[DEPRECATED] Terraform Custom Provider for VMware vSphere
Mozilla Public License 2.0
82 stars 30 forks source link

host connection info #23

Closed lesaux closed 9 years ago

lesaux commented 9 years ago

The host connection info doesn't seem to be set for provisioners. i.e. you need to configure give 'host' a value like below.

connection {
        type = "ssh"
        user = "ubuntu"
        password = "password"
        host = "${vsphere_virtual_machine.test.network_interfaces.0.ip_address}"
    }

and this is not possible if you use dhcp.

I'll try to work something out but I'm afraid it won't be pretty as my go skills are non existent.

lesaux commented 9 years ago

So I ran into another issue while adding the host info: When using dhcp, it sometimes takes a while for the correct ip to be read by govmomi - the ip outputed by virtual_machine.go is not the true dhcp lease (in my template, the ip is set statically to 192.168.66.111 to speed up the boot process until dhcp finally kicks in). I've added a "boot_delay" parameter to the vsphere_virtual_ressource and I use to it to read the mvm.Summary.Guest.IpAddress again after that time has passed (this time will depend on vpshere performance and vm template). I then encountered another issue when my "boot_delay" was too short: I pulled an empty string from mvm.Summary.Guest.IpAddress (I guess this momentarily happens when the vmware-tools are updating the guest ip in vcenter). Nevertheless this is what a debug log looks like in this scenario:

2015/07/01 12:02:17 terraform-provider-vsphere: 2015/07/01 12:02:17 [DEBUG] ip address: 192.168.66.111
2015/07/01 12:02:17 terraform-provider-vsphere: 2015/07/01 12:02:17 [INFO] Created virtual machine: trusty
2015/07/01 12:02:17 terraform-provider-vsphere: 2015/07/01 12:02:17 [DEBUG] vm booted at 2015-07-01 16:02:10.961052 +0000 UTC
2015/07/01 12:02:17 terraform-provider-vsphere: 2015/07/01 12:02:17 [DEBUG] it has been 6.412988
2015/07/01 12:02:17 terraform-provider-vsphere: 2015/07/01 12:02:17 [DEBUG] configured boot_time delay is 30
2015/07/01 12:02:17 terraform-provider-vsphere: 2015/07/01 12:02:17 [DEBUG] remaining time to wait 23.587012
2015/07/01 12:02:17 terraform-provider-vsphere: 2015/07/01 12:02:17 [DEBUG] boot delay has been enabled, waiting another 23
2015/07/01 12:02:40 terraform-provider-vsphere: 2015/07/01 12:02:40 [DEBUG] problem getting ip address, retrying
2015/07/01 12:02:41 terraform-provider-vsphere: 2015/07/01 12:02:41 [DEBUG] problem getting ip address, retrying
2015/07/01 12:02:42 terraform-provider-vsphere: 2015/07/01 12:02:42 [DEBUG] problem getting ip address, retrying
2015/07/01 12:02:43 terraform-provider-vsphere: 2015/07/01 12:02:43 [DEBUG] problem getting ip address, retrying
2015/07/01 12:02:44 terraform-provider-vsphere: 2015/07/01 12:02:44 [DEBUG] problem getting ip address, retrying
2015/07/01 12:02:45 terraform-provider-vsphere: 2015/07/01 12:02:45 [DEBUG] problem getting ip address, retrying
2015/07/01 12:02:46 terraform-provider-vsphere: 2015/07/01 12:02:46 [DEBUG] problem getting ip address, retrying
2015/07/01 12:02:47 terraform-provider-vsphere: 2015/07/01 12:02:47 [DEBUG] problem getting ip address, retrying
2015/07/01 12:02:48 terraform-provider-vsphere: 2015/07/01 12:02:48 [DEBUG] ip address is 192.168.0.84

You can see that the first ip_address read is 192.168.66.111. I then wait 30seconds after mvm.Summary.Runtime.BootTime to read it again. I obtain an empty string during a few times, but finally get the proper ip 192.168.0.84 after a few seconds.

I'm guessing mvm.Summary.Guest.IpAddress will always output the primary network ip address, in the case where you have multiple NICs defined.

Once this is done I set the ConnInfo Host value to this ip - but I haven't looked into updating vsphere_virtual_machine.name.network_interface.0.ip_address yet. My code is very ugly, and is not a candidate for a PR, but I will provided a link to what I have done shortly.

lesaux commented 9 years ago

d458d2b1f7df3cea248f2b2c3c0adb3a4834c927 152e4436483f3c3f9eaa5f3a9e5a80f3b990ee7d and ec45c1145fca9fab0bfd17511c4c2afffdabe613 show what I've done.

Don't hesitate to give me feedback, good or bad!

tkak commented 9 years ago

Thank you for your trying contributions! I like one argument for IP address better than two arguments such as ip_address and network_interface.0.ip_address. If you don't mind, can you try to use network_interface.0.ip_address for primary IP address instead of new ip_address?

lesaux commented 9 years ago

I will definitely give it a try. In fact I did it this way because d.Set("network_interface.0.ip_address", ip_address) didn't work! I think I have to figure out how to update a key value in a map.

tkak commented 9 years ago

I'm sorry for the late response. I tried to fix this issue in #27 and merged into the pre-release version. Do you mind checking the host connection in your environment?

https://github.com/rakutentech/terraform-provider-vsphere/releases

lesaux commented 9 years ago

Hi, sorry for the late response as I have been travelling, and thanks for your follow up.

1) It seems that the network_interface.0.ip_address variable is not available anymore?

* Resource 'vsphere_virtual_machine.trusty' does not have attribute 'network_interface.0.ip_address' for variable 'vsphere_virtual_machine.trusty.network_interface.0.ip_address'
2015/08/01 21:53:10 [ERROR] root: eval: *terraform.EvalSequence, err: 1 error(s) occurred:

2) the host parameter for connection info is not set. It think this should default to network_interface.0.ip_address. Here it seems this is unset.

3) I don't think you are addressing the fact that getting the ip address through dhcp can sometimes be slow. see my previous comment: https://github.com/rakutentech/terraform-provider-vsphere/issues/23#issuecomment-117736237

tkak commented 9 years ago

Thanks for your check.

1) Could you try to use self.network_interface attribute?

https://www.terraform.io/docs/configuration/interpolation.html

2) and 3) Agreed, I'll try to look into this over the weekend.

tkak commented 9 years ago

@lesaux

Hi, I tried to add default host connection support and boot_delay option in #29. Could you check that with pre-release version?

lesaux commented 9 years ago

Hi tkak, sorry for the very long delay. I just built the provider from master branch, and it seems everything works well!!

Thanks a lot for your work on this!

tkak commented 9 years ago

👍