Skip to content

Commit

Permalink
Merge pull request #28 from Terraform-VMWare-Modules/dependon-v1
Browse files Browse the repository at this point in the history
Dependon v1
  • Loading branch information
Arman-Keyoumarsi authored Jun 23, 2020
2 parents 155295e + 3f43d1d commit df7bebd
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 49 deletions.
10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ For Virtual Machine Provisioning with (Linux/Windows) customization. Thanks to t

:warning: The new version of this module only works with terraform version 0.12.6 and above :warning:

> This module now replace the functionality of the following modules:
>
> - [`Terraform-VMWare-Modules-vm2nic`](https://registry.terraform.io/modules/Terraform-VMWare-Modules/vm2nic/vsphere/0.1.0)
> - [`Terraform-VMWare-Modules-vm3nic`](https://registry.terraform.io/modules/Terraform-VMWare-Modules/vm3nic/vsphere/0.1.0)
## Deploys (Single/Multiple) Virtual Machines to your vSphere environment

This Terraform module deploys single or multiple virtual machines of type (Linux/Windows) with following features:
Expand All @@ -30,6 +25,7 @@ This Terraform module deploys single or multiple virtual machines of type (Linux
- Ability to define different datastores for data disks.
- Ability to define different scsi_controllers per disk, including data disks.
- Ability to define network type per interface and disk label per attached disk.
- Ability to define depend on using variable vm_depends_on

> Note: For module to work it needs number of required variables corresponding to an existing resources in vSphere. Please refer to variable section for the list of required variables.
Expand All @@ -42,7 +38,7 @@ You can also download the entire module and use your own predefined variables to
```hcl
module "example-server-linuxvm" {
source = "Terraform-VMWare-Modules/vm/vsphere"
version = "1.2.0"
version = "1.3.0"
vmtemp = "TemplateName"
instances = 1
vmname = "example-server-windows"
Expand Down Expand Up @@ -95,7 +91,7 @@ Below is an example of windows deployment with some of the available feature set
```hcl
module "example-server-windowsvm-advanced" {
source = "Terraform-VMWare-Modules/vm/vsphere"
version = "1.2.0"
version = "1.3.0"
dc = "Datacenter"
vmrp = "cluster/Resources" #Works with ESXi/Resources
vmfolder = "Cattle"
Expand Down
4 changes: 2 additions & 2 deletions examples/linux/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Following example contains the bare minimum options to be configured for the Lin
```hcl
module "example-server-linuxvm" {
source = "Terraform-VMWare-Modules/vm/vsphere"
version = "1.2.0"
version = "Latest X.X.X"
vmtemp = "TemplateName"
instances = 1
vmname = "example-server-windows"
Expand All @@ -36,7 +36,7 @@ Below example will deploy 2 instance of a virtual machine from a linux template.
```hcl
module "example-server-linuxvm-withdatadisk" {
source = "Terraform-VMWare-Modules/vm/vsphere"
version = "1.2.0"
version = "Latest X.X.X"
dc = "Datacenter"
vmrp = "cluster/Resources"
vmfolder = "Cattle"
Expand Down
57 changes: 57 additions & 0 deletions examples/linux/example-depend_on.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Simple Linux VM deployment
module "example-server-linuxvm" {
source = "Terraform-VMWare-Modules/vm/vsphere"
version = "Latest X.X.X"
vmtemp = "TemplateName"
instances = 1
vmname = "example-server-windows"
vmrp = "esxi/Resources"
network_cards = ["Name of the Port Group in vSphere"]
ipv4 = {
"Name of the Port Group in vSphere" = ["10.0.0.1"] # To use DHCP create empty string for each instance
}
dc = "Datacenter"
datastore = "Data Store name(use ds_cluster for datastore cluster)"
}
// Example of Linux VM with more Advanced Features
module "example-server-linuxvm-advanced" {
source = "Terraform-VMWare-Modules/vm/vsphere"
vm_depends_on = [module.example-server-linuxvm] # This force the second module to wait for first VM to be created first
version = "Latest X.X.X"
dc = "Datacenter"
vmrp = "cluster/Resources"
vmfolder = "Cattle"
ds_cluster = "Datastore Cluster"
vmtemp = "TemplateName"
instances = 2
cpu_number = 2
ram_size = 2096
cpu_hot_add_enabled = "true"
cpu_hot_remove_enabled = "true"
memory_hot_add_enabled = "true"
vmname = "AdvancedVM"
vmdomain = "somedomain.com"
network_cards = ["VM Network", "test-network"]
ipv4submask = ["24", "8"]
ipv4 = {
"VM Network" = ["192.168.0.4", ""] // Here the first instance will use Static Ip and Second set to DHCP
"test" = ["", "192.168.0.3"]
}
disk_label = ["tpl-disk-1"]
data_disk_label = ["label1", "label2"]
scsi_type = "lsilogic" # "pvscsi"
scsi_controller = 0
data_disk_scsi_controller = [0, 1]
disk_datastore = "vsanDatastore"
data_disk_datastore = ["vsanDatastore", "nfsDatastore"]
data_disk_size_gb = [10, 5] // Aditional Disks to be used
thin_provisioned = ["true", "false"]
vmdns = ["192.168.0.2", "192.168.0.1"]
vmgateway = "192.168.0.1"
network_type = ["vmxnet3", "vmxnet3"]
tags = {
"terraform-test-category" = "terraform-test-tag"
"terraform-test-category-02" = "terraform-test-tag-02"
}
}

28 changes: 14 additions & 14 deletions examples/linux/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Simple Linux VM deployment
module "example-server-linuxvm" {
source = "Terraform-VMWare-Modules/vm/vsphere"
version = "1.1.0"
version = "Latest X.X.X"
vmtemp = "TemplateName"
instances = 1
vmname = "example-server-windows"
Expand All @@ -16,7 +16,7 @@ module "example-server-linuxvm" {
// Example of Linux VM with more Advanced Features
module "example-server-linuxvm-advanced" {
source = "Terraform-VMWare-Modules/vm/vsphere"
version = "1.1.0"
version = "Latest X.X.X"
dc = "Datacenter"
vmrp = "cluster/Resources"
vmfolder = "Cattle"
Expand All @@ -36,18 +36,18 @@ module "example-server-linuxvm-advanced" {
"VM Network" = ["192.168.0.4", ""] // Here the first instance will use Static Ip and Second set to DHCP
"test" = ["", "192.168.0.3"]
}
disk_label = ["tpl-disk-1"]
data_disk_label = ["label1", "label2"]
scsi_type = "lsilogic" # "pvscsi"
scsi_controller = 0
data_disk_scsi_controller = [0, 1]
disk_datastore = "vsanDatastore"
data_disk_datastore = ["vsanDatastore", "nfsDatastore"]
data_disk_size_gb = [10, 5] // Aditional Disks to be used
thin_provisioned = ["true", "false"]
vmdns = ["192.168.0.2", "192.168.0.1"]
vmgateway = "192.168.0.1"
network_type = ["vmxnet3", "vmxnet3"]
disk_label = ["tpl-disk-1"]
data_disk_label = ["label1", "label2"]
scsi_type = "lsilogic" # "pvscsi"
scsi_controller = 0
data_disk_scsi_controller = [0, 1]
disk_datastore = "vsanDatastore"
data_disk_datastore = ["vsanDatastore", "nfsDatastore"]
data_disk_size_gb = [10, 5] // Aditional Disks to be used
thin_provisioned = ["true", "false"]
vmdns = ["192.168.0.2", "192.168.0.1"]
vmgateway = "192.168.0.1"
network_type = ["vmxnet3", "vmxnet3"]
tags = {
"terraform-test-category" = "terraform-test-tag"
"terraform-test-category-02" = "terraform-test-tag-02"
Expand Down
4 changes: 2 additions & 2 deletions examples/windows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Following example contains the bare minimum options to be configured for the Win
```hcl
module "example-server-windowsvm-withdatadisk" {
source = "Terraform-VMWare-Modules/vm/vsphere"
version = "1.2.0"
version = "Latest X.X.X"
vmtemp = "TemplateName"
instances = 1
vmname = "example-server-windows"
Expand All @@ -32,7 +32,7 @@ module "example-server-windowsvm-withdatadisk" {
```hcl
module "example-server-windowsvm-advanced" {
source = "Terraform-VMWare-Modules/vm/vsphere"
version = "1.2.0"
version = "Latest X.X.X"
dc = "Datacenter"
vmrp = "cluster/Resources"
vmfolder = "Cattle"
Expand Down
28 changes: 14 additions & 14 deletions examples/windows/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Example of basic Windows VM
module "example-server-windowsvm-withdatadisk" {
source = "Terraform-VMWare-Modules/vm/vsphere"
version = "1.1.0"
version = "Latest X.X.X"
vmtemp = "TemplateName"
is_windows_image = "true"
instances = 1
Expand Down Expand Up @@ -36,7 +36,7 @@ module "example-server-windowsvm-withdatadisk" {
//Example of Windows VM customization with advanced features
module "example-server-windowsvm-advanced" {
source = "Terraform-VMWare-Modules/vm/vsphere"
version = "1.1.0"
version = "Latest X.X.X"
dc = "Datacenter"
vmrp = "cluster/Resources"
vmfolder = "Cattle"
Expand All @@ -56,18 +56,18 @@ module "example-server-windowsvm-advanced" {
"VM Network" = ["192.168.0.4", ""] // Here the first instance will use Static Ip and Second DHCP
"test" = ["", "192.168.0.3"]
}
disk_label = ["tpl-disk-1"]
data_disk_label = ["label1", "label2"]
scsi_type = "lsilogic" # "pvscsi"
scsi_controller = 0
data_disk_scsi_controller = [0, 3]
disk_datastore = "vsanDatastore"
data_disk_datastore = ["vsanDatastore", "nfsDatastore"]
data_disk_size_gb = [10, 5] // Aditional Disks to be used
thin_provisioned = ["true", "false"]
vmdns = ["192.168.0.2", "192.168.0.1"]
vmgateway = "192.168.0.1"
network_type = ["vmxnet3", "vmxnet3"]
disk_label = ["tpl-disk-1"]
data_disk_label = ["label1", "label2"]
scsi_type = "lsilogic" # "pvscsi"
scsi_controller = 0
data_disk_scsi_controller = [0, 3]
disk_datastore = "vsanDatastore"
data_disk_datastore = ["vsanDatastore", "nfsDatastore"]
data_disk_size_gb = [10, 5] // Aditional Disks to be used
thin_provisioned = ["true", "false"]
vmdns = ["192.168.0.2", "192.168.0.1"]
vmgateway = "192.168.0.1"
network_type = ["vmxnet3", "vmxnet3"]
tags = {
"terraform-test-category" = "terraform-test-tag"
"terraform-test-category-02" = "terraform-test-tag-02"
Expand Down
12 changes: 6 additions & 6 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ locals {

// Cloning a Linux VM from a given template. Note: This is the default option!!
resource "vsphere_virtual_machine" "Linux" {
count = var.is_windows_image != "true" ? var.instances : 0

name = "%{if var.vmnameliteral != ""}${var.vmnameliteral}%{else}${var.vmname}${count.index + 1}${var.vmnamesuffix}%{endif}"
count = var.is_windows_image != "true" ? var.instances : 0
depends_on = [var.vm_depends_on]
name = "%{if var.vmnameliteral != ""}${var.vmnameliteral}%{else}${var.vmname}${count.index + 1}${var.vmnamesuffix}%{endif}"

resource_pool_id = data.vsphere_resource_pool.pool.id
folder = var.vmfolder
Expand Down Expand Up @@ -153,9 +153,9 @@ resource "vsphere_virtual_machine" "Linux" {
}

resource "vsphere_virtual_machine" "Windows" {
count = var.is_windows_image == "true" ? var.instances : 0

name = "%{if var.vmnameliteral != ""}${var.vmnameliteral}%{else}${var.vmname}${count.index + 1}${var.vmnamesuffix}%{endif}"
count = var.is_windows_image == "true" ? var.instances : 0
depends_on = [var.vm_depends_on]
name = "%{if var.vmnameliteral != ""}${var.vmnameliteral}%{else}${var.vmname}${count.index + 1}${var.vmnamesuffix}%{endif}"

resource_pool_id = data.vsphere_resource_pool.pool.id
folder = var.vmfolder
Expand Down
14 changes: 10 additions & 4 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ variable "data_disk_size_gb" {
default = []
}

variable "disk_datastore"{
variable "disk_datastore" {
description = "Define where the OS disk should be stored"
type = string
default = ""
Expand Down Expand Up @@ -199,7 +199,7 @@ variable "scsi_type" {
default = ""
}

variable "scsi_controller"{
variable "scsi_controller" {
description = "scsi_controller number for the main OS disk"
type = number
default = 0
Expand Down Expand Up @@ -228,8 +228,8 @@ variable "enable_disk_uuid" {

variable "network_type" {
description = "Define network type for each network interface"
type = list
default = null
type = list
default = null
}

#Linux Customization Variables
Expand Down Expand Up @@ -328,3 +328,9 @@ variable "wait_for_guest_net_timeout" {
default = 5
type = number
}

variable "vm_depends_on" {
description = "Add any external depend on module here like vm_depends_on = [module.fw_core01.firewall]"
type = any
default = null
}

0 comments on commit df7bebd

Please sign in to comment.