diff --git a/README.md b/README.md index 59e67ad..964d58d 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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. @@ -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" @@ -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" diff --git a/examples/linux/README.md b/examples/linux/README.md index ca8a19c..498f96f 100644 --- a/examples/linux/README.md +++ b/examples/linux/README.md @@ -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" @@ -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" diff --git a/examples/linux/example-depend_on.tf b/examples/linux/example-depend_on.tf new file mode 100644 index 0000000..fca7342 --- /dev/null +++ b/examples/linux/example-depend_on.tf @@ -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" + } +} + diff --git a/examples/linux/main.tf b/examples/linux/main.tf index ed1dc19..ffe81a9 100644 --- a/examples/linux/main.tf +++ b/examples/linux/main.tf @@ -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" @@ -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" @@ -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" diff --git a/examples/windows/README.md b/examples/windows/README.md index 515b318..ad5a46d 100644 --- a/examples/windows/README.md +++ b/examples/windows/README.md @@ -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" @@ -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" diff --git a/examples/windows/main.tf b/examples/windows/main.tf index 2a14da6..1c68ab1 100644 --- a/examples/windows/main.tf +++ b/examples/windows/main.tf @@ -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 @@ -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" @@ -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" diff --git a/main.tf b/main.tf index 6b0c045..bc73698 100644 --- a/main.tf +++ b/main.tf @@ -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 @@ -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 diff --git a/variables.tf b/variables.tf index 408f9d1..1c70218 100644 --- a/variables.tf +++ b/variables.tf @@ -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 = "" @@ -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 @@ -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 @@ -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 +}