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

Add support for running ovftool directly on ESXi #187

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions examples/08 ovftool on ESXi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Terraform esxi Provider (08 ovftool on ESXi)
---

Since we have SSH enabled on ESXi, it's possible to install ovftool directly on the ESXi host and avoid large network copies
by hosting the OVA/OVFs locally.

To use this functionality, perform the following steps:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How to Do that man , there are only win and linux files meanwhile esxi is not linux , tho you do it with host client ? i dont found any console or sth to some cmds , am a beginner..

1. Install ovftool somewhere on the ESXi host. For example, ``/vmfs/volumes/datastore1/ovftool`` (directory)
2. Add the ``esxi_remote_ovftool_path`` to provider config:
```
provider "esxi" {
esxi_hostname = "${var.esxi_server}"
esxi_username = "${var.esxi_user}"
esxi_password = "${var.esxi_password}"
esxi_remote_ovftool_path = "/vmfs/volumes/datastore1/ovftool/ovftool"
}
```
3. Install an OVA somewhere on the ESXi host. For example, /vmfs/volumes/datastore1/ovas/ubuntu-22.04-server-cloudimg-amd64.ova
4. Use the ``host_ovf://`` prefix to tell the plugin where to find the local image. Example:
```
resource "esxi_guest" "vmtest" {
...
ovf_source = "host_ovf:///vmfs/volumes/datastore1/isos/ubuntu-22.04-server-cloudimg-amd64.ova"
}
```

Now, when creating the vmtest instance, terraform will run the ovftool on the ESXi host directly and will pull the image on that
same host, avoiding massive copies over the network.

Note that ovf_properties and guestinfo directives will work as expected. We highly recommend using guestinfo directive w/ cloud-init
configs where possible (anything using cloud-init 21.2+ should work) and avoid the overhead of rebooting the instance multiple
times.
23 changes: 23 additions & 0 deletions examples/08 ovftool on ESXi/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
provider "esxi" {
esxi_hostname = var.esxi_hostname
esxi_hostport = var.esxi_hostport
esxi_hostssl = var.esxi_hostssl
esxi_username = var.esxi_username
esxi_password = var.esxi_password

esxi_remote_ovftool_path = "/vmfs/volumes/datastore1/ovftool/ovftool"
}

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

network_interfaces {
virtual_network = var.virtual_network
}

#
# Specify an ovf file to use as a source.
#
ovf_source = "host_ovf:///vmfs/volumes/datastore1/ovas/ubuntu-22.04-server-cloudimg-amd64.ova"
}
37 changes: 37 additions & 0 deletions examples/08 ovftool on ESXi/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#
# See https://www.terraform.io/intro/getting-started/variables.html for more details.
#

# Change these defaults to fit your needs!

variable "esxi_hostname" {
default = "esxi"
}

variable "esxi_hostport" {
default = "22"
}

variable "esxi_hostssl" {
default = "443"
}

variable "esxi_username" {
default = "root"
}

variable "esxi_password" {
# Unspecified will prompt
}

variable "virtual_network" {
default = "VM Network"
}

variable "disk_store" {
default = "DiskStore01"
}

variable "vm_hostname" {
default = "vmtest06"
}
15 changes: 15 additions & 0 deletions examples/08 ovftool on ESXi/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

terraform {
required_version = ">= 0.13"
required_providers {
esxi = {
source = "registry.terraform.io/josenk/esxi"
#
# For more information, see the provider source documentation:
#
# https://github.com/josenk/terraform-provider-esxi
# https://registry.terraform.io/providers/josenk/esxi
#
}
}
}