From 4a3555c62273fbd1701fa9f8f420212df33b4522 Mon Sep 17 00:00:00 2001 From: Jonathan Senkerik Date: Thu, 13 Aug 2020 23:14:30 -0400 Subject: [PATCH] v1.7.1, update docs and examples --- README.md | 35 ++++-- .../01 Simple Guest/variables.tf | 0 .../variables.tf | 0 .../variables.tf | 0 .../04 CoreOS and Ignition/example.service | 0 .../04 CoreOS and Ignition/output.tf | 0 .../04 CoreOS and Ignition/variables.tf | 0 .../05 CloudInit and Templates/output.tf | 0 .../05 CloudInit and Templates/userdata.tpl | 0 .../05 CloudInit and Templates/variables.tf | 0 {examples-legacy => examples-0.11}/README.md | 0 .../01 Simple Guest/variables.tf | 0 .../01 Simple Guest/versions.tf | 0 .../variables.tf | 0 .../versions.tf | 0 .../variables.tf | 0 .../versions.tf | 0 .../04 CoreOS and Ignition/example.service | 0 .../04 CoreOS and Ignition/output.tf | 0 .../04 CoreOS and Ignition/variables.tf | 0 .../04 CoreOS and Ignition/versions.tf | 0 .../05 CloudInit and Templates/output.tf | 0 .../05 CloudInit and Templates/userdata.tpl | 0 .../05 CloudInit and Templates/userinit.tpl | 0 .../05 CloudInit and Templates/variables.tf | 0 .../05 CloudInit and Templates/versions.tf | 0 .../06 OVF Properties/README.md | 0 .../06 OVF Properties/outputs.tf | 0 .../06 OVF Properties/userdata.tpl | 0 .../06 OVF Properties/variables.tf | 0 .../06 OVF Properties/versions.tf | 0 {examples => examples-0.12}/README.md | 0 examples-0.13/01 Simple Guest/variables.tf | 25 +++++ examples-0.13/01 Simple Guest/versions.tf | 15 +++ .../variables.tf | 25 +++++ .../versions.tf | 15 +++ .../variables.tf | 30 +++++ .../versions.tf | 15 +++ .../04 CoreOS and Ignition/example.service | 6 + .../04 CoreOS and Ignition/output.tf | 4 + .../04 CoreOS and Ignition/variables.tf | 30 +++++ .../04 CoreOS and Ignition/versions.tf | 15 +++ .../05 CloudInit and Templates/output.tf | 4 + .../05 CloudInit and Templates/userdata.tpl | 27 +++++ .../05 CloudInit and Templates/userinit.tpl | 34 ++++++ .../05 CloudInit and Templates/variables.tf | 38 +++++++ .../05 CloudInit and Templates/versions.tf | 15 +++ examples-0.13/06 OVF Properties/README.md | 75 +++++++++++++ examples-0.13/06 OVF Properties/outputs.tf | 8 ++ examples-0.13/06 OVF Properties/userdata.tpl | 16 +++ examples-0.13/06 OVF Properties/variables.tf | 42 +++++++ examples-0.13/06 OVF Properties/versions.tf | 15 +++ examples-0.13/README.md | 6 + examples-legacy/01 Simple Guest/main.tf | 32 ------ .../02 Cloned Guest - Complete build/main.tf | 56 ---------- .../main.tf | 104 ------------------ .../04 CoreOS and Ignition/main.tf | 81 -------------- .../05 CloudInit and Templates/main.tf | 60 ---------- examples/01 Simple Guest/main.tf | 30 ----- .../02 Cloned Guest - Complete build/main.tf | 56 ---------- .../main.tf | 99 ----------------- examples/04 CoreOS and Ignition/main.tf | 80 -------------- examples/05 CloudInit and Templates/main.tf | 55 --------- examples/06 OVF Properties/main.tf | 53 --------- 64 files changed, 487 insertions(+), 714 deletions(-) rename {examples-legacy => examples-0.11}/01 Simple Guest/variables.tf (100%) rename {examples-legacy => examples-0.11}/02 Cloned Guest - Complete build/variables.tf (100%) rename {examples-legacy => examples-0.11}/03 Resource Pools - Additional Storage/variables.tf (100%) rename {examples-legacy => examples-0.11}/04 CoreOS and Ignition/example.service (100%) rename {examples-legacy => examples-0.11}/04 CoreOS and Ignition/output.tf (100%) rename {examples-legacy => examples-0.11}/04 CoreOS and Ignition/variables.tf (100%) rename {examples-legacy => examples-0.11}/05 CloudInit and Templates/output.tf (100%) rename {examples-legacy => examples-0.11}/05 CloudInit and Templates/userdata.tpl (100%) rename {examples-legacy => examples-0.11}/05 CloudInit and Templates/variables.tf (100%) rename {examples-legacy => examples-0.11}/README.md (100%) rename {examples => examples-0.12}/01 Simple Guest/variables.tf (100%) rename {examples => examples-0.12}/01 Simple Guest/versions.tf (100%) rename {examples => examples-0.12}/02 Cloned Guest - Complete build/variables.tf (100%) rename {examples => examples-0.12}/02 Cloned Guest - Complete build/versions.tf (100%) rename {examples => examples-0.12}/03 Resource Pools - Additional Storage/variables.tf (100%) rename {examples => examples-0.12}/03 Resource Pools - Additional Storage/versions.tf (100%) rename {examples => examples-0.12}/04 CoreOS and Ignition/example.service (100%) rename {examples => examples-0.12}/04 CoreOS and Ignition/output.tf (100%) rename {examples => examples-0.12}/04 CoreOS and Ignition/variables.tf (100%) rename {examples => examples-0.12}/04 CoreOS and Ignition/versions.tf (100%) rename {examples => examples-0.12}/05 CloudInit and Templates/output.tf (100%) rename {examples => examples-0.12}/05 CloudInit and Templates/userdata.tpl (100%) rename {examples => examples-0.12}/05 CloudInit and Templates/userinit.tpl (100%) rename {examples => examples-0.12}/05 CloudInit and Templates/variables.tf (100%) rename {examples => examples-0.12}/05 CloudInit and Templates/versions.tf (100%) rename {examples => examples-0.12}/06 OVF Properties/README.md (100%) rename {examples => examples-0.12}/06 OVF Properties/outputs.tf (100%) rename {examples => examples-0.12}/06 OVF Properties/userdata.tpl (100%) rename {examples => examples-0.12}/06 OVF Properties/variables.tf (100%) rename {examples => examples-0.12}/06 OVF Properties/versions.tf (100%) rename {examples => examples-0.12}/README.md (100%) create mode 100644 examples-0.13/01 Simple Guest/variables.tf create mode 100644 examples-0.13/01 Simple Guest/versions.tf create mode 100644 examples-0.13/02 Cloned Guest - Complete build/variables.tf create mode 100644 examples-0.13/02 Cloned Guest - Complete build/versions.tf create mode 100644 examples-0.13/03 Resource Pools - Additional Storage/variables.tf create mode 100644 examples-0.13/03 Resource Pools - Additional Storage/versions.tf create mode 100644 examples-0.13/04 CoreOS and Ignition/example.service create mode 100644 examples-0.13/04 CoreOS and Ignition/output.tf create mode 100644 examples-0.13/04 CoreOS and Ignition/variables.tf create mode 100644 examples-0.13/04 CoreOS and Ignition/versions.tf create mode 100644 examples-0.13/05 CloudInit and Templates/output.tf create mode 100644 examples-0.13/05 CloudInit and Templates/userdata.tpl create mode 100644 examples-0.13/05 CloudInit and Templates/userinit.tpl create mode 100644 examples-0.13/05 CloudInit and Templates/variables.tf create mode 100644 examples-0.13/05 CloudInit and Templates/versions.tf create mode 100644 examples-0.13/06 OVF Properties/README.md create mode 100644 examples-0.13/06 OVF Properties/outputs.tf create mode 100644 examples-0.13/06 OVF Properties/userdata.tpl create mode 100644 examples-0.13/06 OVF Properties/variables.tf create mode 100644 examples-0.13/06 OVF Properties/versions.tf create mode 100644 examples-0.13/README.md delete mode 100644 examples-legacy/01 Simple Guest/main.tf delete mode 100644 examples-legacy/02 Cloned Guest - Complete build/main.tf delete mode 100644 examples-legacy/03 Resource Pools - Additional Storage/main.tf delete mode 100644 examples-legacy/04 CoreOS and Ignition/main.tf delete mode 100644 examples-legacy/05 CloudInit and Templates/main.tf delete mode 100644 examples/01 Simple Guest/main.tf delete mode 100644 examples/02 Cloned Guest - Complete build/main.tf delete mode 100644 examples/03 Resource Pools - Additional Storage/main.tf delete mode 100644 examples/04 CoreOS and Ignition/main.tf delete mode 100644 examples/05 CloudInit and Templates/main.tf delete mode 100644 examples/06 OVF Properties/main.tf diff --git a/README.md b/README.md index dc23015..bae650b 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ Requirements Building The Provider --------------------- +In general, you don't normally need to build the provider. A release can be downloaded from github, or can automatically be downloaded with terraform 0.13. You first must set your GOPATH. If you are unsure, please review the documentation at. >https://github.com/golang/go/wiki/SettingGOPATH @@ -42,6 +43,7 @@ CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -ldflags '-w -extldflags "-sta sudo cp terraform-provider-esxi_`cat version` /usr/local/bin ``` + Terraform-provider-esxi plugin ============================== * This is a Terraform plugin that adds a VMware ESXi provider support. This allows Terraform to control and provision VMs directly on an ESXi hypervisor without a need for vCenter or VShpere. ESXi hypervisor is a free download from VMware! @@ -54,14 +56,10 @@ Terraform-provider-esxi plugin >https://configmax.vmware.com/guest - - What's New: ----------- -* Terraform can import existing Guest VMs, Virtual Disks & Resource pools by name. See wiki page for more info. ->https://github.com/josenk/terraform-provider-esxi/wiki/How-to-import -* Added support for GuestInfo. (Thanks for the contribution silasb.) - * This adds great provisioning options like Ignition and Cloud-Init! +* Terraform 0.13 support. This provider is now in the terraform registry. +>https://registry.terraform.io/providers/josenk/esxi @@ -73,6 +71,7 @@ Features and Compatibility * Terraform will Create, Destroy, Update & Read Guest VMs. * Terraform will Create, Destroy, Update & Read Extra Storage for Guests. + This is a provider! NOT a provisioner. --------------------------------------- * This plugin does not configure your guest VM, it creates it. @@ -81,6 +80,7 @@ This is a provider! NOT a provisioner. * To help you get started, there is are examples in a separate repo I created. You can create a Pull Request if you would like to contribute. * https://github.com/josenk/terraform-provider-esxi-wiki + Vagrant vs Terraform. --------------------- If you are using vagrant as a deployment tool (infa as code), you may want to consider a better tool. Terraform. Vagrant is better for development environments, while Terraform is better at managing infrastructure. Please give my terraform plugin a try and give me some feedback. What you're trying to do, what's missing, what works, what doesn't work, etc... @@ -96,8 +96,27 @@ Not everyone has vCenter, vSphere, expensive APIs... These cost $$$. ESXi is f How to install -------------- -Download and install Terraform on your local system using instructions from https://www.terraform.io/downloads.html. -Clone this plugin from github, build and place a copy of it in your path or current directory of your terraform project. Or download pre-built binaries from https://github.com/josenk/terraform-provider-esxi/releases. +* Install terraform + * Download and install Terraform on your local system using instructions from https://www.terraform.io/downloads.html. +* Automatic install + * Add the required_providers block to your terraform project. + ``` +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 + } + } +} +``` +* Manual installation + * Download pre-built binaries from https://github.com/josenk/terraform-provider-esxi/releases. Place a copy of it in your path or current directory of your terraform project. + How to use and configure a main.tf file diff --git a/examples-legacy/01 Simple Guest/variables.tf b/examples-0.11/01 Simple Guest/variables.tf similarity index 100% rename from examples-legacy/01 Simple Guest/variables.tf rename to examples-0.11/01 Simple Guest/variables.tf diff --git a/examples-legacy/02 Cloned Guest - Complete build/variables.tf b/examples-0.11/02 Cloned Guest - Complete build/variables.tf similarity index 100% rename from examples-legacy/02 Cloned Guest - Complete build/variables.tf rename to examples-0.11/02 Cloned Guest - Complete build/variables.tf diff --git a/examples-legacy/03 Resource Pools - Additional Storage/variables.tf b/examples-0.11/03 Resource Pools - Additional Storage/variables.tf similarity index 100% rename from examples-legacy/03 Resource Pools - Additional Storage/variables.tf rename to examples-0.11/03 Resource Pools - Additional Storage/variables.tf diff --git a/examples-legacy/04 CoreOS and Ignition/example.service b/examples-0.11/04 CoreOS and Ignition/example.service similarity index 100% rename from examples-legacy/04 CoreOS and Ignition/example.service rename to examples-0.11/04 CoreOS and Ignition/example.service diff --git a/examples-legacy/04 CoreOS and Ignition/output.tf b/examples-0.11/04 CoreOS and Ignition/output.tf similarity index 100% rename from examples-legacy/04 CoreOS and Ignition/output.tf rename to examples-0.11/04 CoreOS and Ignition/output.tf diff --git a/examples-legacy/04 CoreOS and Ignition/variables.tf b/examples-0.11/04 CoreOS and Ignition/variables.tf similarity index 100% rename from examples-legacy/04 CoreOS and Ignition/variables.tf rename to examples-0.11/04 CoreOS and Ignition/variables.tf diff --git a/examples-legacy/05 CloudInit and Templates/output.tf b/examples-0.11/05 CloudInit and Templates/output.tf similarity index 100% rename from examples-legacy/05 CloudInit and Templates/output.tf rename to examples-0.11/05 CloudInit and Templates/output.tf diff --git a/examples-legacy/05 CloudInit and Templates/userdata.tpl b/examples-0.11/05 CloudInit and Templates/userdata.tpl similarity index 100% rename from examples-legacy/05 CloudInit and Templates/userdata.tpl rename to examples-0.11/05 CloudInit and Templates/userdata.tpl diff --git a/examples-legacy/05 CloudInit and Templates/variables.tf b/examples-0.11/05 CloudInit and Templates/variables.tf similarity index 100% rename from examples-legacy/05 CloudInit and Templates/variables.tf rename to examples-0.11/05 CloudInit and Templates/variables.tf diff --git a/examples-legacy/README.md b/examples-0.11/README.md similarity index 100% rename from examples-legacy/README.md rename to examples-0.11/README.md diff --git a/examples/01 Simple Guest/variables.tf b/examples-0.12/01 Simple Guest/variables.tf similarity index 100% rename from examples/01 Simple Guest/variables.tf rename to examples-0.12/01 Simple Guest/variables.tf diff --git a/examples/01 Simple Guest/versions.tf b/examples-0.12/01 Simple Guest/versions.tf similarity index 100% rename from examples/01 Simple Guest/versions.tf rename to examples-0.12/01 Simple Guest/versions.tf diff --git a/examples/02 Cloned Guest - Complete build/variables.tf b/examples-0.12/02 Cloned Guest - Complete build/variables.tf similarity index 100% rename from examples/02 Cloned Guest - Complete build/variables.tf rename to examples-0.12/02 Cloned Guest - Complete build/variables.tf diff --git a/examples/02 Cloned Guest - Complete build/versions.tf b/examples-0.12/02 Cloned Guest - Complete build/versions.tf similarity index 100% rename from examples/02 Cloned Guest - Complete build/versions.tf rename to examples-0.12/02 Cloned Guest - Complete build/versions.tf diff --git a/examples/03 Resource Pools - Additional Storage/variables.tf b/examples-0.12/03 Resource Pools - Additional Storage/variables.tf similarity index 100% rename from examples/03 Resource Pools - Additional Storage/variables.tf rename to examples-0.12/03 Resource Pools - Additional Storage/variables.tf diff --git a/examples/03 Resource Pools - Additional Storage/versions.tf b/examples-0.12/03 Resource Pools - Additional Storage/versions.tf similarity index 100% rename from examples/03 Resource Pools - Additional Storage/versions.tf rename to examples-0.12/03 Resource Pools - Additional Storage/versions.tf diff --git a/examples/04 CoreOS and Ignition/example.service b/examples-0.12/04 CoreOS and Ignition/example.service similarity index 100% rename from examples/04 CoreOS and Ignition/example.service rename to examples-0.12/04 CoreOS and Ignition/example.service diff --git a/examples/04 CoreOS and Ignition/output.tf b/examples-0.12/04 CoreOS and Ignition/output.tf similarity index 100% rename from examples/04 CoreOS and Ignition/output.tf rename to examples-0.12/04 CoreOS and Ignition/output.tf diff --git a/examples/04 CoreOS and Ignition/variables.tf b/examples-0.12/04 CoreOS and Ignition/variables.tf similarity index 100% rename from examples/04 CoreOS and Ignition/variables.tf rename to examples-0.12/04 CoreOS and Ignition/variables.tf diff --git a/examples/04 CoreOS and Ignition/versions.tf b/examples-0.12/04 CoreOS and Ignition/versions.tf similarity index 100% rename from examples/04 CoreOS and Ignition/versions.tf rename to examples-0.12/04 CoreOS and Ignition/versions.tf diff --git a/examples/05 CloudInit and Templates/output.tf b/examples-0.12/05 CloudInit and Templates/output.tf similarity index 100% rename from examples/05 CloudInit and Templates/output.tf rename to examples-0.12/05 CloudInit and Templates/output.tf diff --git a/examples/05 CloudInit and Templates/userdata.tpl b/examples-0.12/05 CloudInit and Templates/userdata.tpl similarity index 100% rename from examples/05 CloudInit and Templates/userdata.tpl rename to examples-0.12/05 CloudInit and Templates/userdata.tpl diff --git a/examples/05 CloudInit and Templates/userinit.tpl b/examples-0.12/05 CloudInit and Templates/userinit.tpl similarity index 100% rename from examples/05 CloudInit and Templates/userinit.tpl rename to examples-0.12/05 CloudInit and Templates/userinit.tpl diff --git a/examples/05 CloudInit and Templates/variables.tf b/examples-0.12/05 CloudInit and Templates/variables.tf similarity index 100% rename from examples/05 CloudInit and Templates/variables.tf rename to examples-0.12/05 CloudInit and Templates/variables.tf diff --git a/examples/05 CloudInit and Templates/versions.tf b/examples-0.12/05 CloudInit and Templates/versions.tf similarity index 100% rename from examples/05 CloudInit and Templates/versions.tf rename to examples-0.12/05 CloudInit and Templates/versions.tf diff --git a/examples/06 OVF Properties/README.md b/examples-0.12/06 OVF Properties/README.md similarity index 100% rename from examples/06 OVF Properties/README.md rename to examples-0.12/06 OVF Properties/README.md diff --git a/examples/06 OVF Properties/outputs.tf b/examples-0.12/06 OVF Properties/outputs.tf similarity index 100% rename from examples/06 OVF Properties/outputs.tf rename to examples-0.12/06 OVF Properties/outputs.tf diff --git a/examples/06 OVF Properties/userdata.tpl b/examples-0.12/06 OVF Properties/userdata.tpl similarity index 100% rename from examples/06 OVF Properties/userdata.tpl rename to examples-0.12/06 OVF Properties/userdata.tpl diff --git a/examples/06 OVF Properties/variables.tf b/examples-0.12/06 OVF Properties/variables.tf similarity index 100% rename from examples/06 OVF Properties/variables.tf rename to examples-0.12/06 OVF Properties/variables.tf diff --git a/examples/06 OVF Properties/versions.tf b/examples-0.12/06 OVF Properties/versions.tf similarity index 100% rename from examples/06 OVF Properties/versions.tf rename to examples-0.12/06 OVF Properties/versions.tf diff --git a/examples/README.md b/examples-0.12/README.md similarity index 100% rename from examples/README.md rename to examples-0.12/README.md diff --git a/examples-0.13/01 Simple Guest/variables.tf b/examples-0.13/01 Simple Guest/variables.tf new file mode 100644 index 0000000..c8a3b3f --- /dev/null +++ b/examples-0.13/01 Simple Guest/variables.tf @@ -0,0 +1,25 @@ +# +# 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 +} + diff --git a/examples-0.13/01 Simple Guest/versions.tf b/examples-0.13/01 Simple Guest/versions.tf new file mode 100644 index 0000000..b047755 --- /dev/null +++ b/examples-0.13/01 Simple Guest/versions.tf @@ -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 + # + } + } +} diff --git a/examples-0.13/02 Cloned Guest - Complete build/variables.tf b/examples-0.13/02 Cloned Guest - Complete build/variables.tf new file mode 100644 index 0000000..c8a3b3f --- /dev/null +++ b/examples-0.13/02 Cloned Guest - Complete build/variables.tf @@ -0,0 +1,25 @@ +# +# 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 +} + diff --git a/examples-0.13/02 Cloned Guest - Complete build/versions.tf b/examples-0.13/02 Cloned Guest - Complete build/versions.tf new file mode 100644 index 0000000..b047755 --- /dev/null +++ b/examples-0.13/02 Cloned Guest - Complete build/versions.tf @@ -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 + # + } + } +} diff --git a/examples-0.13/03 Resource Pools - Additional Storage/variables.tf b/examples-0.13/03 Resource Pools - Additional Storage/variables.tf new file mode 100644 index 0000000..877a097 --- /dev/null +++ b/examples-0.13/03 Resource Pools - Additional Storage/variables.tf @@ -0,0 +1,30 @@ +# +# 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 "disk_store" { + default = "DS_001" +} + diff --git a/examples-0.13/03 Resource Pools - Additional Storage/versions.tf b/examples-0.13/03 Resource Pools - Additional Storage/versions.tf new file mode 100644 index 0000000..b047755 --- /dev/null +++ b/examples-0.13/03 Resource Pools - Additional Storage/versions.tf @@ -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 + # + } + } +} diff --git a/examples-0.13/04 CoreOS and Ignition/example.service b/examples-0.13/04 CoreOS and Ignition/example.service new file mode 100644 index 0000000..209a049 --- /dev/null +++ b/examples-0.13/04 CoreOS and Ignition/example.service @@ -0,0 +1,6 @@ +[Service] +Type=oneshot +ExecStart=/usr/bin/echo Hello World + +[Install] +WantedBy=multi-user.target diff --git a/examples-0.13/04 CoreOS and Ignition/output.tf b/examples-0.13/04 CoreOS and Ignition/output.tf new file mode 100644 index 0000000..7f01a81 --- /dev/null +++ b/examples-0.13/04 CoreOS and Ignition/output.tf @@ -0,0 +1,4 @@ +output "ip" { + value = [esxi_guest.coreos.ip_address] +} + diff --git a/examples-0.13/04 CoreOS and Ignition/variables.tf b/examples-0.13/04 CoreOS and Ignition/variables.tf new file mode 100644 index 0000000..6262bd1 --- /dev/null +++ b/examples-0.13/04 CoreOS and Ignition/variables.tf @@ -0,0 +1,30 @@ +# +# 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 "disk_store" { + default = "datastore0" +} + diff --git a/examples-0.13/04 CoreOS and Ignition/versions.tf b/examples-0.13/04 CoreOS and Ignition/versions.tf new file mode 100644 index 0000000..b047755 --- /dev/null +++ b/examples-0.13/04 CoreOS and Ignition/versions.tf @@ -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 + # + } + } +} diff --git a/examples-0.13/05 CloudInit and Templates/output.tf b/examples-0.13/05 CloudInit and Templates/output.tf new file mode 100644 index 0000000..9268c3d --- /dev/null +++ b/examples-0.13/05 CloudInit and Templates/output.tf @@ -0,0 +1,4 @@ +output "ip" { + value = [esxi_guest.Default.ip_address] +} + diff --git a/examples-0.13/05 CloudInit and Templates/userdata.tpl b/examples-0.13/05 CloudInit and Templates/userdata.tpl new file mode 100644 index 0000000..80c7417 --- /dev/null +++ b/examples-0.13/05 CloudInit and Templates/userdata.tpl @@ -0,0 +1,27 @@ +#cloud-config + +packages: + - ntp + - ntpdate + + +# Add yum repository configuration to the system +yum_repos: + # The name of the repository + epel-testing: + # Any repository configuration options + # See: man yum.conf + # + # This one is required! + baseurl: http://download.fedoraproject.org/pub/epel/testing/5/$basearch + enabled: false + failovermethod: priority + gpgcheck: true + gpgkey: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL + name: Extra Packages for Enterprise Linux 5 - Testing + +runcmd: + - date >/root/cloudinit.log + - hostnamectl set-hostname ${HOSTNAME} + - echo ${HELLO} >>/root/cloudinit.log + - echo "Done cloud-init" >>/root/cloudinit.log diff --git a/examples-0.13/05 CloudInit and Templates/userinit.tpl b/examples-0.13/05 CloudInit and Templates/userinit.tpl new file mode 100644 index 0000000..e0cb490 --- /dev/null +++ b/examples-0.13/05 CloudInit and Templates/userinit.tpl @@ -0,0 +1,34 @@ +#cloud-config + +packages: + - ntp + - ntpdate + + +# Override ntp with chrony configuration on Ubuntu +ntp: + enabled: true + ntp_client: chrony # Uses cloud-init default chrony configuration + + +# Add yum repository configuration to the system +yum_repos: + # The name of the repository + epel-testing: + # Any repository configuration options + # See: man yum.conf + # + # This one is required! + baseurl: http://download.fedoraproject.org/pub/epel/testing/5/$basearch + enabled: false + failovermethod: priority + gpgcheck: true + gpgkey: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL + name: Extra Packages for Enterprise Linux 5 - Testing + +runcmd: + - date >/root/cloudinit.log + - hostnamectl set-hostname ${HOSTNAME} + - echo ${HELLO} >>/root/cloudinit.log + - echo "Done cloud-init" >>/root/cloudinit.log + diff --git a/examples-0.13/05 CloudInit and Templates/variables.tf b/examples-0.13/05 CloudInit and Templates/variables.tf new file mode 100644 index 0000000..f8142f1 --- /dev/null +++ b/examples-0.13/05 CloudInit and Templates/variables.tf @@ -0,0 +1,38 @@ +# +# 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 = "vmtest05" +} + diff --git a/examples-0.13/05 CloudInit and Templates/versions.tf b/examples-0.13/05 CloudInit and Templates/versions.tf new file mode 100644 index 0000000..b047755 --- /dev/null +++ b/examples-0.13/05 CloudInit and Templates/versions.tf @@ -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 + # + } + } +} diff --git a/examples-0.13/06 OVF Properties/README.md b/examples-0.13/06 OVF Properties/README.md new file mode 100644 index 0000000..3111220 --- /dev/null +++ b/examples-0.13/06 OVF Properties/README.md @@ -0,0 +1,75 @@ +# Terraform esxi Provider (06 OVF Properties) +--- + +## Notes on ovf_properties. +* There are a few caveats using this method of configuring your guest. + * This method of injecting properties into the VM works with ovf/ova sources only. The guestinfo method ("05 CloudInit and Templates" example) can be used with any source type (vmx, ovf, ova, clone_from_vm), but requires "Cloud-Init for VMware" to be pre-installed on the source. + + * 'terraform apply' takes longer to deploy when using ovf_properties because the guest will be booted twice. The default length of time to allow ovf_properties to run is 90 seconds. If your configuration requires more time, set ovf_properties_timer to a higher value. + * You cannot configure additional virtual_disks in userdata using the ovf_properties method. Userdata in ovf_properties runs before the additional virtual_disks are added. If this is a requirement, use the guestinfo (Cloud-Init for VMware) method. + + * This method only works on ovf/ova sources that have properties available to configure. Not all ovf/ova files will have properties or their Key naming convention may not be consistent between sources. + +## How to use ovf_properties. +* Some ovf/ova files have available properties. These key/value properties can be retrieved from the ovf/ova file. The default values of the guest can be over written using the ovf_properties configuration option in your terraform code. + +* To list the OVF properties in a specific ovf/ova file, use the following command. + +``` +ovftool --hideEula image.ova +``` + +Example output + +``` +Properties: + Key: instance-id + Label: A Unique Instance ID for this instance + Type: string + Description: Specifies the instance id. This is required and used to + determine if the machine should take "first boot" actions + Value: id-ovf + + Key: hostname + Type: string + Description: Specifies the hostname for the appliance + Value: ubuntuguest + + Key: user-data + Label: Encoded user-data + Type: string + Description: In order to fit into a xml attribute, this value is base64 + encoded . It will be decoded, and then processed normally as + user-data. + + Key: password + Label: Default User's password + Type: string + Description: If set, the default user's password will be set to this value to + allow password based login. The password will be good for only + a single login. If set to the string 'RANDOM' then a random + password will be generated, and written to the console. + Value: q + +``` + +* The `user-data` key allows you to inject user-data via ovf_properties. This works with images that have cloud-init included. + * For example: Ubuntu cloud-images. https://cloud-images.ubuntu.com/ + +* The following example will set the "Default User's Password" and hostname. It will also pass the rendered userdata.tpl file to the vm. +``` + ovf_properties { + key = "password" + value = "Passw0rd1" + } + + ovf_properties { + key = "hostname" + value = "vmtest06" + } + + ovf_properties { + key = "user-data" + value = base64encode(data.template_file.userdata_default.rendered) + } + ``` diff --git a/examples-0.13/06 OVF Properties/outputs.tf b/examples-0.13/06 OVF Properties/outputs.tf new file mode 100644 index 0000000..cf7ff2c --- /dev/null +++ b/examples-0.13/06 OVF Properties/outputs.tf @@ -0,0 +1,8 @@ + +output "ip" { + value = esxi_guest.vmtest.ip_address +} + +output "cloudinit" { + value = data.template_file.userdata_default.rendered +} diff --git a/examples-0.13/06 OVF Properties/userdata.tpl b/examples-0.13/06 OVF Properties/userdata.tpl new file mode 100644 index 0000000..eb0e5a8 --- /dev/null +++ b/examples-0.13/06 OVF Properties/userdata.tpl @@ -0,0 +1,16 @@ +#cloud-config + +packages: + - ntp + - ntpdate + - curl + +# Override ntp with chrony configuration on Ubuntu +ntp: + enabled: true + ntp_client: chrony # Uses cloud-init default chrony configuration + +runcmd: + - date >/root/cloudinit.log + - echo ${HELLO} >>/root/cloudinit.log + - echo "Done cloud-init" >>/root/cloudinit.log diff --git a/examples-0.13/06 OVF Properties/variables.tf b/examples-0.13/06 OVF Properties/variables.tf new file mode 100644 index 0000000..0a40acf --- /dev/null +++ b/examples-0.13/06 OVF Properties/variables.tf @@ -0,0 +1,42 @@ +# +# 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" +} + +varaible "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" +} + +# Example downloaded from https://cloud-images.ubuntu.com/ +variable "ovf_file" { + default = "ubuntu-19.04-server-cloudimg-amd64.ova" +} + +variable "vm_hostname" { + default = "vmtest06" +} diff --git a/examples-0.13/06 OVF Properties/versions.tf b/examples-0.13/06 OVF Properties/versions.tf new file mode 100644 index 0000000..b047755 --- /dev/null +++ b/examples-0.13/06 OVF Properties/versions.tf @@ -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 + # + } + } +} diff --git a/examples-0.13/README.md b/examples-0.13/README.md new file mode 100644 index 0000000..090bff3 --- /dev/null +++ b/examples-0.13/README.md @@ -0,0 +1,6 @@ +Terraform esxi Provider +======================= + + +This directory hold the examples for terraform 0.12.x+ +------------------------------------------------------ diff --git a/examples-legacy/01 Simple Guest/main.tf b/examples-legacy/01 Simple Guest/main.tf deleted file mode 100644 index 1d0bf79..0000000 --- a/examples-legacy/01 Simple Guest/main.tf +++ /dev/null @@ -1,32 +0,0 @@ -######################################### -# ESXI Provider host/login details -######################################### -# -# Use of variables here to hide/move the variables to a separate file -# -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 Guest resource -######################################### -# -# This Guest VM is "bare-metal". It will be powered on by default -# by terraform, but it will not boot to any OS. It will however attempt -# to network boot. -# -resource "esxi_guest" "vmtest01" { - guest_name = "vmtest01" # Required, Specify the Guest Name - disk_store = "DS_001" # Required, Specify an existing Disk Store - network_interfaces = [ - { - virtual_network = "VM Network" # Required for each network interface, Specify the Virtual Network name. - }, - ] -} diff --git a/examples-legacy/02 Cloned Guest - Complete build/main.tf b/examples-legacy/02 Cloned Guest - Complete build/main.tf deleted file mode 100644 index e45ba85..0000000 --- a/examples-legacy/02 Cloned Guest - Complete build/main.tf +++ /dev/null @@ -1,56 +0,0 @@ -######################################### -# ESXI Provider host/login details -######################################### -# -# Use of variables here to hide/move the variables to a separate file -# -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 Guest resource -######################################### -# -# This Guest VM is a clone of an existing Guest VM named "centos7" (must exist and -# be powered off), located in the "Templates" resource pool. vmtest02 will be powered -# on by default by terraform. The virtual network "VM Network", must already exist on -# your esxi host! -# -resource "esxi_guest" "vmtest02" { - guest_name = "vmtest02" - disk_store = "DS_001" - guestos = "centos-64" - - boot_disk_type = "thin" - boot_disk_size = "35" - - memsize = "2048" - numvcpus = "2" - resource_pool_name = "/" - power = "on" - - # clone_from_vm uses ovftool to clone an existing Guest on your esxi host. This example will clone a Guest VM named "centos7", located in the "Templates" resource pool. - # ovf_source uses ovftool to produce a clone from an ovf or vmx image. (typically produced using the ovf_tool). - # Basically clone_from_vm clones from sources on the esxi host and ovf_source clones from sources on your local hard disk. - # These two options are mutually exclusive. - clone_from_vm = "Templates/centos7" - #ovf_source = "/my_local_system_path/centos-7-min/centos-7.vmx" - - network_interfaces = [ - { - virtual_network = "VM Network" - mac_address = "00:50:56:a1:b1:c2" - nic_type = "e1000" - - }, - ] - - guest_startup_timeout = 45 - guest_shutdown_timeout = 30 -} diff --git a/examples-legacy/03 Resource Pools - Additional Storage/main.tf b/examples-legacy/03 Resource Pools - Additional Storage/main.tf deleted file mode 100644 index 2b2a099..0000000 --- a/examples-legacy/03 Resource Pools - Additional Storage/main.tf +++ /dev/null @@ -1,104 +0,0 @@ -######################################### -# ESXI Provider host/login details -######################################### -# -# Use of variables here to hide/move the variables to a separate file -# -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}" -} - -######################################### -# Resource Pools -######################################### -resource "esxi_resource_pool" "Terraform" { - resource_pool_name = "Terraform" - cpu_min = "100" - cpu_min_expandable = "true" - cpu_max = "8000" - cpu_shares = "normal" - mem_min = "200" - mem_min_expandable = "false" - mem_max = "8192" - mem_shares = "normal" -} - -resource "esxi_resource_pool" "pool2" { - resource_pool_name = "${esxi_resource_pool.Terraform.resource_pool_name}/pool2" -} - -######################################### -# Virtual Disks -######################################### -resource "esxi_virtual_disk" "vdisk1" { - virtual_disk_disk_store = "${var.disk_store}" - virtual_disk_dir = "Terraform" - virtual_disk_name = "vdisk_1.vmdk" - virtual_disk_size = 10 - virtual_disk_type = "zeroedthick" -} -resource "esxi_virtual_disk" "vdisk2" { - virtual_disk_disk_store = "${var.disk_store}" - virtual_disk_dir = "Terraform" - virtual_disk_size = 15 - virtual_disk_type = "eagerzeroedthick" -} - - - -######################################### -# ESXI Guest resource -######################################### -# -# This Guest VM is a clone of an existing Guest VM named "centos7" (must exist and -# be powered off), located in the "Templates" resource pool. vmtest03 will be powered -# on by default by terraform. The virtual network "VM Network", must already exist on -# your esxi host! -# -resource "esxi_guest" "vmtest03" { - guest_name = "vmtes03" - disk_store = "${var.disk_store}" - guestos = "centos-64" - - boot_disk_type = "thin" - boot_disk_size = "35" - - memsize = "2048" - numvcpus = "2" - resource_pool_name = "${esxi_resource_pool.pool2.resource_pool_name}" - power = "on" - - # clone_from_vm uses ovftool to clone an existing Guest on your esxi host. This example will clone a Guest VM named "centos7", located in the "Templates" resource pool. - # ovf_source uses ovftool to produce a clone from an ovf or vmx image. (typically produced using the ovf_tool). - # Basically clone_from_vm clones from sources on the esxi host and ovf_source clones from sources on your local hard disk. - # These two options are mutually exclusive. - clone_from_vm = "Templates/centos7" - #ovf_source = "/my_local_system_path/centos-7-min/centos-7.vmx" - - network_interfaces = [ - { - virtual_network = "VM Network" - mac_address = "00:50:56:a1:b1:c3" - nic_type = "e1000" - - }, - ] - - guest_startup_timeout = 45 - guest_shutdown_timeout = 30 - - virtual_disks = [ - { - virtual_disk_id = "${esxi_virtual_disk.vdisk1.id}" - slot = "0:1" - }, - { - virtual_disk_id = "${esxi_virtual_disk.vdisk2.id}" - slot = "0:2" - }, - ] -} diff --git a/examples-legacy/04 CoreOS and Ignition/main.tf b/examples-legacy/04 CoreOS and Ignition/main.tf deleted file mode 100644 index a74dbb1..0000000 --- a/examples-legacy/04 CoreOS and Ignition/main.tf +++ /dev/null @@ -1,81 +0,0 @@ -######################################### -# ESXI Provider host/login details -######################################### -# -# Use of variables here to hide/move the variables to a separate file -# -provider "esxi" { - version = "~> 1.3" - 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}" -} - - -######################################### -# coreos and Ignition -# See: https://coreos.com/ignition/docs/latest/ -# -# - To use this example, you must download the latest ova from coreos site. -# - curl -LO https://stable.release.core-os.net/amd64-usr/current/coreos_production_vmware_ova.ova -######################################### - - -data "ignition_user" "cluster_user" { - name = "core" - # used to calculate a password hash below if you want password: mkpasswd --method=SHA-512 --rounds=4096 - #password_hash = "$6$rounds=4096$v28up9xdAO$aLCyf/FfGU72QsOlJN60CyXH5yuyJ/f6WWeW3wyvPjHt4uDOUFbFCxchrf9FCUkUdng7bwZbonBk7aOFQ8Bcm0" # test1234 - ssh_authorized_keys = ["${file("~/.ssh/id_rsa.pub")}"] -} - -data "ignition_systemd_unit" "example" { - name = "example.service" - content = "${file("example.service")}" -} - -data "ignition_config" "coreos" { - users = [ - "${data.ignition_user.cluster_user.id}" - ] - - systemd = [ - "${data.ignition_systemd_unit.example.id}" - ] -} - -resource "esxi_guest" "coreos" { - guest_name = "${terraform.workspace}-coreos" - disk_store = "${var.disk_store}" - - guestinfo = { - coreos.config.data.encoding = "base64" - coreos.config.data = "${base64encode(data.ignition_config.coreos.rendered)}" - } - - ovf_source = "coreos_production_vmware_ova.ova" - power = "on" - memsize = "2048" - numvcpus = "2" - network_interfaces = [ - { - virtual_network = "VM Network" # Required for each network interface, Specify the Virtual Network name. - }, - ] - - connection { - host = "${self.ip_address}" - type = "ssh" - user = "core" - private_key = "${file("~/.ssh/id_rsa")}" - timeout = "60s" - } - - provisioner "remote-exec" { - inline = [ - "echo success", - #"update_engine_client -update", - ] - } -} diff --git a/examples-legacy/05 CloudInit and Templates/main.tf b/examples-legacy/05 CloudInit and Templates/main.tf deleted file mode 100644 index 96d08b8..0000000 --- a/examples-legacy/05 CloudInit and Templates/main.tf +++ /dev/null @@ -1,60 +0,0 @@ -######################################### -# ESXI Provider host/login details -######################################### -# -# Use of variables here to hide/move the variables to a separate file -# -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}" -} - -######################################### -# cloud-init for vmware! -# You must install it on your source VM before cloning it! -# See https://github.com/vmware/cloud-init-vmware-guestinfo for more details. -# and https://cloudinit.readthedocs.io/en/latest/topics/examples.html# -# -# -# yum install https://github.com/vmware/cloud-init-vmware-guestinfo/releases/download/v1.1.0/cloud-init-vmware-guestinfo-1.1.0-1.el7.noarch.rpm -# cloud-init clean -######################################### - - -# -# Template for initial configuration bash script -# template_file is a great way to pass variables to -# cloud-init -data "template_file" "Default" { - template = "${file("userdata.tpl")}" - vars = { - HOSTNAME = "${var.vm_hostname}" - HELLO = "Hello World!" - } -} - - -######################################### -# ESXI Guest resource -######################################### -resource "esxi_guest" "Default" { - guest_name = "${var.vm_hostname}" - disk_store = "${var.disk_store}" - - clone_from_vm = "Templates/centos7" - - network_interfaces = [ - { - virtual_network = "${var.virtual_network}" - }, - ] - - guestinfo = { - userdata.encoding = "gzip+base64" - userdata = "${base64gzip(data.template_file.Default.rendered)}" - } - -} diff --git a/examples/01 Simple Guest/main.tf b/examples/01 Simple Guest/main.tf deleted file mode 100644 index bed14cf..0000000 --- a/examples/01 Simple Guest/main.tf +++ /dev/null @@ -1,30 +0,0 @@ -######################################### -# ESXI Provider host/login details -######################################### -# -# Use of variables here to hide/move the variables to a separate file -# -provider "esxi" { - esxi_hostname = var.esxi_hostname - esxi_hostport = var.esxi_hostport - esxi_hostssl = var.exsi_hostssl - esxi_username = var.esxi_username - esxi_password = var.esxi_password -} - -######################################### -# ESXI Guest resource -######################################### -# -# This Guest VM is "bare-metal". It will be powered on by default -# by terraform, but it will not boot to any OS. It will however attempt -# to network boot. -# -resource "esxi_guest" "vmtest01" { - guest_name = "vmtest01" # Required, Specify the Guest Name - disk_store = "DS_001" # Required, Specify an existing Disk Store - network_interfaces { - virtual_network = "VM Network" # Required for each network interface, Specify the Virtual Network name. - } -} - diff --git a/examples/02 Cloned Guest - Complete build/main.tf b/examples/02 Cloned Guest - Complete build/main.tf deleted file mode 100644 index e1b78ab..0000000 --- a/examples/02 Cloned Guest - Complete build/main.tf +++ /dev/null @@ -1,56 +0,0 @@ -######################################### -# ESXI Provider host/login details -######################################### -# -# Use of variables here to hide/move the variables to a separate file -# -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 Guest resource -######################################### -# -# This Guest VM is a clone of an existing Guest VM named "centos7" (must exist and -# be powered off), located in the "Templates" resource pool. vmtest02 will be powered -# on by default by terraform. The virtual network "VM Network", must already exist on -# your esxi host! -# -resource "esxi_guest" "vmtest02" { - guest_name = "vmtest02" - disk_store = "DS_001" - guestos = "centos-64" - - boot_disk_type = "thin" - boot_disk_size = "35" - - memsize = "2048" - numvcpus = "2" - resource_pool_name = "/" - power = "on" - - # clone_from_vm uses ovftool to clone an existing Guest on your esxi host. This example will clone a Guest VM named "centos7", located in the "Templates" resource pool. - # ovf_source uses ovftool to produce a clone from an ovf or vmx image. (typically produced using the ovf_tool). - # Basically clone_from_vm clones from sources on the esxi host and ovf_source clones from sources on your local hard disk or a URL. - # These two options are mutually exclusive. - clone_from_vm = "Templates/centos7" - - #ovf_source = "/my_local_system_path/centos-7-min/centos-7.vmx" - - network_interfaces { - virtual_network = "VM Network" - mac_address = "00:50:56:a1:b1:c2" - nic_type = "e1000" - } - network_interfaces { - virtual_network = "VM Network2" - } - - guest_startup_timeout = 45 - guest_shutdown_timeout = 30 -} diff --git a/examples/03 Resource Pools - Additional Storage/main.tf b/examples/03 Resource Pools - Additional Storage/main.tf deleted file mode 100644 index 96bec5d..0000000 --- a/examples/03 Resource Pools - Additional Storage/main.tf +++ /dev/null @@ -1,99 +0,0 @@ -######################################### -# ESXI Provider host/login details -######################################### -# -# Use of variables here to hide/move the variables to a separate file -# -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 -} - -######################################### -# Resource Pools -######################################### -resource "esxi_resource_pool" "Terraform" { - resource_pool_name = "Terraform" - cpu_min = "100" - cpu_min_expandable = "true" - cpu_max = "8000" - cpu_shares = "normal" - mem_min = "200" - mem_min_expandable = "false" - mem_max = "8192" - mem_shares = "normal" -} - -resource "esxi_resource_pool" "pool2" { - resource_pool_name = "${esxi_resource_pool.Terraform.resource_pool_name}/pool2" -} - -######################################### -# Virtual Disks -######################################### -resource "esxi_virtual_disk" "vdisk1" { - virtual_disk_disk_store = var.disk_store - virtual_disk_dir = "Terraform" - virtual_disk_name = "vdisk_1.vmdk" - virtual_disk_size = 10 - virtual_disk_type = "zeroedthick" -} - -resource "esxi_virtual_disk" "vdisk2" { - virtual_disk_disk_store = var.disk_store - virtual_disk_dir = "Terraform" - virtual_disk_size = 15 - virtual_disk_type = "eagerzeroedthick" -} - -######################################### -# ESXI Guest resource -######################################### -# -# This Guest VM is a clone of an existing Guest VM named "centos7" (must exist and -# be powered off), located in the "Templates" resource pool. vmtest03 will be powered -# on by default by terraform. The virtual network "VM Network", must already exist on -# your esxi host! -# -resource "esxi_guest" "vmtest03" { - guest_name = "vmtes03" - disk_store = var.disk_store - guestos = "centos-64" - - boot_disk_type = "thin" - boot_disk_size = "35" - - memsize = "2048" - numvcpus = "2" - resource_pool_name = esxi_resource_pool.pool2.resource_pool_name - power = "on" - - # clone_from_vm uses ovftool to clone an existing Guest on your esxi host. This example will clone a Guest VM named "centos7", located in the "Templates" resource pool. - # ovf_source uses ovftool to produce a clone from an ovf or vmx image. (typically produced using the ovf_tool). - # Basically clone_from_vm clones from sources on the esxi host and ovf_source clones from sources on your local hard disk or URL. - # These two options are mutually exclusive. - clone_from_vm = "Templates/centos7" - - #ovf_source = "/my_local_system_path/centos-7-min/centos-7.vmx" - - network_interfaces { - virtual_network = "VM Network" - mac_address = "00:50:56:a1:b1:c3" - nic_type = "e1000" - } - - guest_startup_timeout = 45 - guest_shutdown_timeout = 30 - - virtual_disks { - virtual_disk_id = esxi_virtual_disk.vdisk1.id - slot = "0:1" - } - virtual_disks { - virtual_disk_id = esxi_virtual_disk.vdisk2.id - slot = "0:2" - } -} diff --git a/examples/04 CoreOS and Ignition/main.tf b/examples/04 CoreOS and Ignition/main.tf deleted file mode 100644 index 9fc85f3..0000000 --- a/examples/04 CoreOS and Ignition/main.tf +++ /dev/null @@ -1,80 +0,0 @@ -######################################### -# ESXI Provider host/login details -######################################### -# -# Use of variables here to hide/move the variables to a separate file -# -provider "esxi" { - version = "~> 1.5" - 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 -} - -######################################### -# coreos and Ignition -# See: https://coreos.com/ignition/docs/latest/ -# -# - To use this example, you must download the latest ova from coreos site. -# - curl -LO https://stable.release.core-os.net/amd64-usr/current/coreos_production_vmware_ova.ova -######################################### - -data "ignition_user" "cluster_user" { - name = "core" - - # used to calculate a password hash below if you want password: mkpasswd --method=SHA-512 --rounds=4096 - #password_hash = "$6$rounds=4096$v28up9xdAO$aLCyf/FfGU72QsOlJN60CyXH5yuyJ/f6WWeW3wyvPjHt4uDOUFbFCxchrf9FCUkUdng7bwZbonBk7aOFQ8Bcm0" # test1234 - ssh_authorized_keys = [file("~/.ssh/id_rsa.pub")] -} - -data "ignition_systemd_unit" "example" { - name = "example.service" - content = file("example.service") -} - -data "ignition_config" "coreos" { - users = [ - data.ignition_user.cluster_user.id, - ] - - systemd = [ - data.ignition_systemd_unit.example.id, - ] -} - -resource "esxi_guest" "coreos" { - guest_name = "${terraform.workspace}-coreos" - disk_store = var.disk_store - guest_startup_timeout = 180 - - guestinfo = { - "coreos.config.data.encoding" = "base64" - "coreos.config.data" = base64encode(data.ignition_config.coreos.rendered) - } - - ovf_source = "../../coreos_production_vmware_ova.ova" - power = "on" - memsize = "2048" - numvcpus = "2" - network_interfaces { - virtual_network = "VM Network" # Required for each network interface, Specify the Virtual Network name. - } - - connection { - host = self.ip_address - type = "ssh" - user = "core" - private_key = file("~/.ssh/id_rsa") - timeout = "180s" - } - - provisioner "remote-exec" { - inline = [ - "echo success", - ] - #"update_engine_client -update", - } -} - diff --git a/examples/05 CloudInit and Templates/main.tf b/examples/05 CloudInit and Templates/main.tf deleted file mode 100644 index 8821912..0000000 --- a/examples/05 CloudInit and Templates/main.tf +++ /dev/null @@ -1,55 +0,0 @@ -######################################### -# ESXI Provider host/login details -######################################### -# -# Use of variables here to hide/move the variables to a separate file -# -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 -} - -######################################### -# cloud-init for vmware! -# You must install it on your source VM before cloning it! -# See https://github.com/vmware/cloud-init-vmware-guestinfo for more details. -# and https://cloudinit.readthedocs.io/en/latest/topics/examples.html# -# -# -# yum install https://github.com/vmware/cloud-init-vmware-guestinfo/releases/download/v1.1.0/cloud-init-vmware-guestinfo-1.1.0-1.el7.noarch.rpm -# cloud-init clean -######################################### - -# -# Template for initial configuration bash script -# template_file is a great way to pass variables to -# cloud-init -data "template_file" "Default" { - template = file("userdata.tpl") - vars = { - HOSTNAME = var.vm_hostname - HELLO = "Hello World!" - } -} - -######################################### -# ESXI Guest resource -######################################### -resource "esxi_guest" "Default" { - guest_name = var.vm_hostname - disk_store = var.disk_store - - clone_from_vm = "Templates/centos7" - - network_interfaces { - virtual_network = var.virtual_network - } - - guestinfo = { - "userdata.encoding" = "gzip+base64" - "userdata" = base64gzip(data.template_file.Default.rendered) - } -} diff --git a/examples/06 OVF Properties/main.tf b/examples/06 OVF Properties/main.tf deleted file mode 100644 index 603f1ad..0000000 --- a/examples/06 OVF Properties/main.tf +++ /dev/null @@ -1,53 +0,0 @@ -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 -} - -# -# 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) - } -}