josenk / terraform-provider-esxi

Terraform-provider-esxi plugin
GNU General Public License v3.0
544 stars 154 forks source link

ovf_properties parameters are not passed correctly to the ovftool command #90

Closed tounefr closed 4 years ago

tounefr commented 4 years ago

Hello,

First of all, thank you for this project which allows us to use Terraform with ESXI without VCenter! I can't get the example "06 OVF Properties /" to work: the parameters are not well passed or interpreted by ovftool.

By manually executing the command executed by terraform-provider, the virtual machine is well provisioned with the given parameters. (I get the command with ps aux | grep ovftool during the execution of "terraform apply"). I also notice that spaces are not supported on the parameters given to the ovftool command.

Maybe the parameters to the ovftool command must be passed in quotes doubles rather than just simple quotes? https://github.com/josenk/terraform-provider-esxi/blob/9242a422f3f985f8c0c2738568d9836894e46ef0/esxi/guest-create.go#L235

My environment is Debian 9 with Bash and version 1.6.1 of terraform-provider-esxi I am using the Ubuntu cloud image "bionic-server-cloudimg-amd64.ova" Terraform version: thomas @ bastion: ~ / i $ terraform version Terraform v0.12.18 provider.esxi v1.6.1 provider.template v2.1.2

Thank you

josenk commented 4 years ago

Please update this thread with your main.tf (or relevant terraform files). Are you using single quotes in your ovf_properties?

BTW: You can enable debugging using the following environment variable. $ export TF_LOG=DEBUG

tounefr commented 4 years ago

I'm using doubles quotes in my ovf_properties. I've just updated variables.tf to connected to my ESXI.

export TF_LOG=DEBUG command result

2019-12-21T14:04:58.922Z [DEBUG] plugin.terraform-provider-esxi_v1.6.1: pid-4175-guest-create.go:286: [guestCREATE] ovf_cmd: ovftool --acceptAllEulas --noSSLVerify --X:useMacNaming=false --X:injectOvfEnv --allowExtraConfig --powerOn --prop:password='Passw0rd1' --prop:hostname='HelloWorld' --prop:user-data='I2Nsb3VkLWNvbmZpZwoKcGFja2FnZXM6CiAtIG50cAogLSBudHBkYXRlCiAtIGN1cmwKCiMgT3ZlcnJpZGUgbnRwIHdpdGggY2hyb255IGNvbmZpZ3VyYXRpb24gb24gVWJ1bnR1Cm50cDoKICBlbmFibGVkOiB0cnVlCiAgbnRwX2NsaWVudDogY2hyb255ICAjIFVzZXMgY2xvdWQtaW5pdCBkZWZhdWx0IGNocm9ueSBjb25maWd1cmF0aW9uCgpydW5jbWQ6CiAgLSBkYXRlID4vcm9vdC9jbG91ZGluaXQubG9nCiAgLSBlY2hvIEhlbGxvIEVYU0kgV29ybGQhID4+L3Jvb3QvY2xvdWRpbml0LmxvZwogIC0gZWNobyAiRG9uZSBjbG91ZC1pbml0IiA+Pi9yb290L2Nsb3VkaW5pdC5sb2cK' -dm=thin --name='vmtest-ubuntu' --overwrite -ds='vm-datastore' --network='LAN' 'ubuntu-19.04-server-cloudimg-amd64.ova' 'vi://root:xxxxxx@192.168.x.x/'

terraform apply then ps aux | aux result

thomas 4191 0.0 0.6 115472 24336 pts/0 R+ 14:04 0:00 /usr/lib/vmware-ovftool/ovftool.bin --acceptAllEulas --noSSLVerify --X:useMacNaming=false --X:injectOvfEnv --allowExtraConfig --powerOn --prop:password=Passw0rd1 --prop:hostname=HelloWorld --prop:user-data=I2Nsb3VkLWNvbmZpZwoKcGFja2FnZXM6CiAtIG50cAogLSBudHBkYXRlCiAtIGN1cmwKCiMgT3ZlcnJpZGUgbnRwIHdpdGggY2hyb255IGNvbmZpZ3VyYXRpb24gb24gVWJ1bnR1Cm50cDoKICBlbmFibGVkOiB0cnVlCiAgbnRwX2NsaWVudDogY2hyb255ICAjIFVzZXMgY2xvdWQtaW5pdCBkZWZhdWx0IGNocm9ueSBjb25maWd1cmF0aW9uCgpydW5jbWQ6CiAgLSBkYXRlID4vcm9vdC9jbG91ZGluaXQubG9nCiAgLSBlY2hvIEhlbGxvIEVYU0kgV29ybGQhID4+L3Jvb3QvY2xvdWRpbml0LmxvZwogIC0gZWNobyAiRG9uZSBjbG91ZC1pbml0IiA+Pi9yb290L2Nsb3VkaW5pdC5sb2cK -dm=thin --name=vmtest-ubuntu --overwrite -ds=vm-datastore --network=LAN ubuntu-19.04-server-cloudimg-amd64.ova vi://root:xxxxx@192.168.x.x/

Here my ovftool version installed from VMware website

thomas@bastion:~$ ovftool --version VMware ovftool 4.3.0 (build-7948156)

When i'm executing manually the command with bash and ovftool with the same arguments, the ovf_properties are transmited successfully.

thomas@bastion:~$ /usr/lib/vmware-ovftool/ovftool.bin --acceptAllEulas --noSSLVerify --X:useMacNaming=false --X:injectOvfEnv --allowExtraConfig --powerOn --prop:password=Passw0rd1 --prop:hostname=HelloWorld --prop:user-data=I2Nsb3VkLWNvbmZpZwoKcGFja2FnZXM6CiAtIG50cAogLSBudHBkYXRlCiAtIGN1cmwKCiMgT3ZlcnJpZGUgbnRwIHdpdGggY2hyb255IGNvbmZpZ3VyYXRpb24gb24gVWJ1bnR1Cm50cDoKICBlbmFibGVkOiB0cnVlCiAgbnRwX2NsaWVudDogY2hyb255ICAjIFVzZXMgY2xvdWQtaW5pdCBkZWZhdWx0IGNocm9ueSBjb25maWd1cmF0aW9uCgpydW5jbWQ6CiAgLSBkYXRlID4vcm9vdC9jbG91ZGluaXQubG9nCiAgLSBlY2hvIEhlbGxvIEVYU0kgV29ybGQhID4+L3Jvb3QvY2xvdWRpbml0LmxvZwogIC0gZWNobyAiRG9uZSBjbG91ZC1pbml0IiA+Pi9yb290L2Nsb3VkaW5pdC5sb2cK -dm=thin --name=vmtest-ubuntu --overwrite -ds=vm-datastore --network=LAN ubuntu-19.04-server-cloudimg-amd64.ova vi://root:xxxx@192.168.x.x/

/usr/lib/vmware-ovftool/ovftool.bin: error while loading shared libraries: libgoogleurl.so.59: cannot open shared object file: No such file or directory

thomas@bastion:~$ export LD_LIBRARY_PATH=/usr/lib/vmware-ovftool/

thomas@bastion:~/terraform-provider-esxi/examples/06 OVF Properties$ /usr/lib/vmware-ovftool/ovftool.bin --acceptAllEulas --noSSLVerify --X:useMacNaming=false --X:injectOvfEnv --allowExtraConfig --powerOn --prop:password=Passw0rd1 --prop:hostname=HelloWorld --prop:user-data=I2Nsb3VkLWNvbmZpZwoKcGFja2FnZXM6CiAtIG50cAogLSBudHBkYXRlCiAtIGN1cmwKCiMgT3ZlcnJpZGUgbnRwIHdpdGggY2hyb255IGNvbmZpZ3VyYXRpb24gb24gVWJ1bnR1Cm50cDoKICBlbmFibGVkOiB0cnVlCiAgbnRwX2NsaWVudDogY2hyb255ICAjIFVzZXMgY2xvdWQtaW5pdCBkZWZhdWx0IGNocm9ueSBjb25maWd1cmF0aW9uCgpydW5jbWQ6CiAgLSBkYXRlID4vcm9vdC9jbG91ZGluaXQubG9nCiAgLSBlY2hvIEhlbGxvIEVYU0kgV29ybGQhID4+L3Jvb3QvY2xvdWRpbml0LmxvZwogIC0gZWNobyAiRG9uZSBjbG91ZC1pbml0IiA+Pi9yb290L2Nsb3VkaW5pdC5sb2cK -dm=thin --name=vmtest-ubuntu --overwrite -ds=vm-datastore --network=LAN ubuntu-19.04-server-cloudimg-amd64.ova vi://root:xxxx@192.168.x.x/

`Opening OVA source: ubuntu-19.04-server-cloudimg-amd64.ova The manifest validates Opening VI target: vi://root@192.168.x.x:443/ Warning:

josenk commented 4 years ago

Please update this thread with your main.tf and relevant files...

tounefr commented 4 years ago

main.tf

provider "esxi" {
  esxi_hostname      = "192.168.xx.xx"
  esxi_hostport      = "22"
  esxi_username      = "root"
  esxi_password      = "xxxxxx"
}

#
# Template for initial configuration bash script
#    template_file is a great way to pass variables to
#    cloud-init
data "template_file" "userdata_default" {
  template = file("userdata.tpl")
  vars = {
    HOSTNAME = var.vm_hostname
    HELLO    = "Hello EXSI World!"
  }
}

resource "esxi_guest" "vmtest" {
  guest_name         = var.vm_hostname
  disk_store         = var.disk_store

  network_interfaces {
     virtual_network = var.virtual_network
  }

  guestinfo = {
    "userdata.encoding" = "gzip+base64"
    "userdata"          = base64gzip(data.template_file.userdata_default.rendered)
  }

  #
  #  Specify an ovf file to use as a source.
  #
  ovf_source        = var.ovf_file

  ovf_properties {
    key = "password"
    value = "Passw0rd1"
  }

  ovf_properties {
    key = "hostname"
    value = "HelloWorld"
  }

  ovf_properties {
    key = "user-data"
    value = base64encode(data.template_file.userdata_default.rendered)
  }
}

outputs.tf


output "ip" {
  value = esxi_guest.vmtest.ip_address
}

output "cloudinit" {
  value = data.template_file.userdata_default.rendered
}

variables.tf

#
#  See https://www.terraform.io/intro/getting-started/variables.html for more details.
#

#  Change these defaults to fit your needs!

variable "esxi_hostname" {
  default = "192.168.xx.xx"
}

variable "esxi_hostport" {
  default = "22"
}

variable "esxi_username" {
  default = "root"
}

variable "esxi_password" {
  default = "xxxxxx"
}

variable "virtual_network" {
  default = "LAN"
}

variable "disk_store" {
  default = "vm-datastore"
}

# Example downloaded from https://cloud-images.ubuntu.com/
variable "ovf_file" {
#   default = "ubuntu-19.04-server-cloudimg-amd64.ova"
    default = "bionic-server-cloudimg-amd64.ova"
}

variable "vm_hostname" {
  default = "vmtest06"
}

versions.tf

terraform {
  required_version = ">= 0.12"
}
josenk commented 4 years ago

You forgot userdata.tpl.

Btw, your ovftool is giving you an error. You need to fix that.

/usr/lib/vmware-ovftool/ovftool.bin: error while loading shared libraries: libgoogleurl.so.59: cannot open shared object file: No such file or directory

josenk commented 4 years ago

abandoned