Closed dglinder closed 4 years ago
Additional context
Running this main.cf
:
terraform {
required_version = ">= 0.12"
}
provider "esxi" {
esxi_hostname = "esx.lab.linder.org"
esxi_hostport = "22"
esxi_hostssl = "443"
esxi_username = "root"
esxi_password = "q7-19ezx"
}
resource "null_resource" "esxi_network" {
provisioner "remote-exec" {
inline = [
"whoami > /tmp/test.out",
]
}
}
resource "esxi_guest" "vmtest" {
guest_name = "vmtest"
disk_store = "datastore1"
network_interfaces {
virtual_network = "VM Network"
}
}
And executing these commands with TRACE level logging:
export TF_LOG=TRACE
export TF_LOG_PATH=/tmp/tf.log
terraform init
terraform destroy -auto-approve
rm -f /tmp/tf.log
terraform apply -auto-approve
I let it repeat the SSH connection until 10 seconds have elapsed, then press Ctrl-C until it exits.
The tf.log
file is attached.
tf.log
The Provisioner block needs to be inside the resource esxi_guest block.
Your resource esxi_guest block doesn't have a clone_from_vm or ovf_source, so that VM will be built with no OS. remote_exec will only run if the resource block is able to build a VM and it's IP address is set. Use terraform show.
Thanks @josenk , I'll look into that. I was using this example from this repo: https://github.com/TribalNightOwl/okd4-esxi-infra
Can you ssh into your source (when it's powered up)? If you cannot, I don't think you can expect to ssh into the newly created vm...
At this point I'm not attempting to run a command on the new VM, rather these commands need to run on the ESXi host itself. By enabling Terraform logging it looks like it is attempting to ssh to the ESXi server, but that is failing for some reason.
I ran out of time this weekend to play with this - I'll try to test further as time permits.
This forum is for the esxi provider plugin to create vms, storage and resource pools. Sorry, I don't support remote-exec provisioner. If you have a problem using the provider, please open a new issue.
Describe the bug Adding a remote exec provisioner causes SSH connection errors.
To Reproduce Steps to reproduce the behavior:
Starting with the example in the README.md (https://github.com/josenk/terraform-provider-esxi/blob/master/README.md#how-to-use-and-configure-a-maintf-file)
Add this code between the
provider "esxi"
andresource "esxi_guest" "vmtest"
:Run
terraform init && terraform destroy --auto-approve && terraform apply -auto-approve
The
terraform apply
output repeats this until it times out:NOTE: Even with the
inline = [ ... ]
block commented out, the error still occurs.Expected behavior The command is executed on the ESXi system and the
/tmp/test.out
is created.Terraform files Here is the Terraform file I'm using:
Desktop (please complete the following information):
terraform version
: