Skip to content

Commit

Permalink
Merge pull request #56 from Terraform-VMWare-Modules/rc/v2.0.0
Browse files Browse the repository at this point in the history
v2.0.0
  • Loading branch information
Arman-Keyoumarsi authored Nov 14, 2020
2 parents ac4bdd1 + d4e84b9 commit 1482768
Show file tree
Hide file tree
Showing 22 changed files with 601 additions and 665 deletions.
84 changes: 84 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# ChanegLog

## v2.0.0
__New Variables__
```hcl
variable "network" {
description = "Define PortGroup and IPs for each VM"
type = map(list(string))
default = {}
}
variable "data_disk" {
description = "Storage data disk parameter, example"
type = map(map(string))
default = {}
}
```
__Removed varsiables__

```hcl
#Network Section
variable "network_cards" {
description = ""
type = list(string)
default = null
}
variable "ipv4" {
description = "host(VM) IP address in map format, support more than one IP. Should correspond to number of instances."
type = map
default = {}
}
#Data Disk Section
data "vsphere_datastore" "data_disk_datastore" {
for_each = toset(var.data_disk_datastore)
name = each.key
datacenter_id = data.vsphere_datacenter.dc.id
}
variable "data_disk_label" {
description = "Storage data disk labels."
type = list
default = []
}
variable "data_disk_size_gb" {
description = "List of Storage data disk size."
type = list
default = []
}
variable "thin_provisioned" {
description = "If true, this disk is thin provisioned, with space for the file being allocated on an as-needed basis."
type = list
default = null
}
variable "eagerly_scrub" {
description = "if set to true, the disk space is zeroed out on VM creation. This will delay the creation of the disk or virtual machine. Cannot be set to true when thin_provisioned is true."
type = list
default = null
}
variable "data_disk_datastore" {
description = "Define where the data disk should be stored, should be equal to number of defined data disks."
type = list
default = []
# validation {
# condition = length(var.disk_datastore) == 0 || length(var.disk_datastore) == length(var.data_disk_size_gb)
# error_message = "The list of disk datastore must be equal in length to disk_size_gb"
# }
}
variable "data_disk_scsi_controller" {
description = "scsi_controller number for the data disk, should be equal to number of defined data disk."
type = list
default = []
# validation {
# condition = max(var.data_disk_scsi_controller...) < 4 && max(var.data_disk_scsi_controller...) > -1
# error_message = "The scsi_controller must be between 0 and 3"
# }
}
```
17 changes: 6 additions & 11 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ We love your input! We want to make contributing to this project as easy and tra
- Proposing new features
- Becoming a maintainer

## We Do have Dedicated Slack Channel
## We Do have a Dedicated Slack Channel
You can join the channel using the following [link](https://join.slack.com/t/terraformvmware/shared_invite/zt-elw5yhds-kPT_QMBWaHGLCPkPJKxYeA).

## We Develop with Github
Expand All @@ -18,37 +18,32 @@ Pull requests are the best way to propose changes to the codebase (we use [Githu

1. Fork the repo and create your branch from `master`.
2. If you've added code that should be tested, add tests.
3. If you've changed APIs, update the documentation.
1. This should be done via sanity test section.
2. Attach copy of the passed TF Plan. (Remove sensitive info if necessary)
3. If you've changed variables/functionality, update the documentation.
4. Ensure the test suite passes.
5. Make sure your code lints.
6. Issue that pull request!

## Any contributions you make will be under the MIT Software License
In short, when you submit code changes, your submissions are understood to be under the same [MIT License](http://choosealicense.com/licenses/mit/) that covers the project. Feel free to contact the maintainers if that's a concern.

## Report bugs using Github's [issues](https://github.com/briandk/transcriptase-atom/issues)
## Report bugs using Github's [issues](https://github.com/Terraform-VMWare-Modules/terraform-vsphere-vm/issues)
We use GitHub issues to track public bugs. Report a bug by [opening a new issue](); it's that easy!

## Write bug reports with detail, background, and sample code
[This is an example](http://stackoverflow.com/q/12488905/180626) of a bug report I wrote, and I think it's not a bad model. Here's [another example from Craig Hockenberry](http://www.openradar.me/11905408), an app developer whom I greatly respect.

**Great Bug Reports** tend to have:

- A quick summary and/or background
- Steps to reproduce
- Be specific!
- Give sample code if you can. [My stackoverflow question](http://stackoverflow.com/q/12488905/180626) includes sample code that *anyone* with a base R setup can run to reproduce what I was seeing
- Give sample code if you can.
- What you expected would happen
- What actually happens
- Notes (possibly including why you think this might be happening, or stuff you tried that didn't work)

People *love* thorough bug reports. I'm not even kidding.

## Use a Consistent Coding Style
I'm again borrowing these from [Facebook's Guidelines](https://github.com/facebook/draft-js/blob/a9316a723f9e918afde44dea68b5f9f39b7d9b00/CONTRIBUTING.md)

* 2 spaces for indentation rather than tabs
* You can try running `npm run lint` for style unification

## License
By contributing, you agree that your contributions will be licensed under its MIT License.
128 changes: 58 additions & 70 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,91 +1,77 @@
# Terraform vSphere Module

![Terraform Version](https://img.shields.io/badge/Terraform-0.12.6-green.svg) [![TF Registry](https://img.shields.io/badge/terraform-registry-blue.svg)](https://registry.terraform.io/modules/Terraform-VMWare-Modules/vm/vsphere/) [![Changelog](https://img.shields.io/badge/changelog-release-green.svg)](https://github.com/Terraform-VMWare-Modules/terraform-vsphere-vm/releases) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
![Terraform Version](https://img.shields.io/badge/Terraform-0.13.5-green.svg) [![TF Registry](https://img.shields.io/badge/terraform-registry-blue.svg)](https://registry.terraform.io/modules/Terraform-VMWare-Modules/vm/vsphere/) [![Changelog](https://img.shields.io/badge/changelog-release-green.svg)](https://github.com/Terraform-VMWare-Modules/terraform-vsphere-vm/releases) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)

For Virtual Machine Provisioning with (Linux/Windows) customization. Thanks to the new enhancements introduced in Terraform v0.12.6 this module include most of the advance features that are available in the resource `vsphere_virtual_machine`.
For Virtual Machine Provisioning with (Linux/Windows) customization. Based on Terraform v0.13, this module include most of the advance features that are available in the resource `vsphere_virtual_machine`.

## 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:

- Ability to specify Linux or Windows VM customization.
- Ability to add extra data disk (up to 15) to the VM.
- Ability to deploy Multiple instances.
- Ability to set IP and Gateway configuration for the VM.
- Ability to add multiple network cards for the VM
- Ability to choose vSphere resource pool or fall back to Cluster/ESXi root resource pool.
- Ability to deploy Windows images to WorkGroup or Domain.
- Ability to output VM names and IPs per module.
- Ability assign tags and custom variables.
- Ability to add multiple network cards for the VM
- Ability to assign tags and custom variables.
- Ability to configure advance features for the vm.
- Ability to deploy either a datastore or a datastore cluster.
- Ability to enable cpu and memory hot plug features for the VM.
- Ability to enable cpu and memory reservations for the VM.
- 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
- Add extra data disk (up to 15) to the VM.
- Different datastores for data disks (datastore_id).
- Different scsi_controllers per disk, including data disks.
- Ability to define depend on using variable vm_depends_on & tag_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.
## Usage
## Getting started

Following example contains the bare minimum options to be configured for (Linux/Windows) VM deployment. You can choose between windows and linux customization by simply using the ´is_windows_image´ boolean switch.

You can also download the entire module and use your own predefined variables to map your entire vSphere environment and use it within this module.

__Create a main.tf file and copy the following code. fill the required data and run terraform plan.__

```hcl
# Configure the VMware vSphere Provider
provider "vsphere" {
user = "fill"
password = "fill"
vsphere_server = "fill"
# if you have a self-signed cert
allow_unverified_ssl = true
}
# Deploy 2 linux VMs
module "example-server-linuxvm" {
source = "Terraform-VMWare-Modules/vm/vsphere"
version = "X.X.X"
vmtemp = "TemplateName"
instances = 1
vmtemp = "VM Template Name (Should Alrerady exist)"
instances = 2
vmname = "example-server-linux"
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 list for each instance
vmrp = "esxi/Resources - or name of a resource pool"
network = {
"Name of the Port Group in vSphere" = ["10.13.113.2", "10.13.113.3"] # To use DHCP create Empty list ["",""]
}
vmgateway = "10.13.113.1"
dc = "Datacenter"
datastore = "Data Store name(use ds_cluster for datastore cluster)"
}
module "example-server-windowsvm" {
source = "Terraform-VMWare-Modules/vm/vsphere"
version = "X.X.X"
vmtemp = "TemplateName"
is_windows_image = true
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 list for each instance
}
dc = "Datacenter"
datastore = "Data Store name(use ds_cluster for datastore cluster)"
}
```

> Note: When deploying a windows server in WorkGroup, we recommend to keep the Local Admin password set to its default and change it later via an script. Unfortunately Terraform redeploy the entire server if you change the local admin password within your code.
## Advance Usage

There are number of switches defined in the module, where you can use to enable different features for VM provisioning.

### Main Feature Switches

- You can use `is_windows_image = true` to set the customization type to Windows (By default it is set to Linux customization)
- You can use `data_disk_size_gb = [20,30]` to add additional data disks (Supported in both Linux and Windows deployment)
- Above switch will create two additional disk of capacity 10 and 30gb for the VM.
- You can include `thin_provisioned` switch to define disk type for each additional disk.
- You can use `windomain = "somedomain.com"` to join a windows server to AD domain.
- Requires following additional variables
- `domainuser` Domain account with necessary privileges to join a computer to the domain.
- `domainpass` Domain user password.
- `is_windows_image` needs to be set to `true` to force the module to use Windows customization.

Below is an example of windows deployment with some of the available feature sets.
> Note: When deploying a windows server in WorkGroup, we recommend to keep the Local Admin password set to its default and change it later via an script. Unfortunately Terraform redeploy the entire server if you change the local admin password within your code.
Below is an example of windows deployment with some of the available feature sets. For complete list of available features please refer to [variable.tf](https://github.com/Terraform-VMWare-Modules/terraform-vsphere-vm/blob/master/variables.tf)

```hcl
module "example-server-windowsvm-advanced" {
Expand All @@ -97,38 +83,35 @@ module "example-server-windowsvm-advanced" {
ds_cluster = "Datastore Cluster" #You can use datastore variable instead
vmtemp = "TemplateName"
instances = 2
cpu_number = 2
ram_size = 2096
cpu_reservation = 2000
memory_reservation = 2000
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"] #Assign multiple cards
network_type = ["vmxnet3", "vmxnet3"]
network = {
"Name of the Port Group in vSphere" = ["10.13.113.2", "10.13.113.3"] # To use DHCP create Empty list ["",""]
"Second Network Card" = ["", ""]
}
ipv4submask = ["24", "8"]
ipv4 = { #assign IPs per card
"VM Network" = ["192.168.0.4", ""] // Here the first instance will use Static Ip and Second DHCP
"test" = ["", "192.168.0.3"]
network_type = ["vmxnet3", "vmxnet3"]
tags = {
"terraform-test-category" = "terraform-test-tag"
}
data_disk = {
disk1 = {
size_gb = 30,
thin_provisioned = false,
data_disk_scsi_controller = 0,
},
disk2 = {
size_gb = 70,
thin_provisioned = true,
data_disk_scsi_controller = 1,
datastore_id = "datastore-90679"
}
}
data_disk_size_gb = [10, 5] // Aditional Disk to be used
thin_provisioned = [true, false]
disk_label = ["tpl-disk-1"]
data_disk_label = ["label1", "label2"]
disk_datastore = "vsanDatastore" // This will store Template disk in the defined disk_datastore
data_disk_datastore = ["vsanDatastore", "nfsDatastore"] // Datastores for additional data disks
scsi_bus_sharing = "physicalSharing" // The modes are physicalSharing, virtualSharing, and noSharing
scsi_type = "lsilogic" // Other acceptable value "pvscsi"
scsi_controller = 0 // This will assign OS disk to controller 0
data_disk_scsi_controller = [0, 1] // This will create a new controller and assign second data disk to controller 1
vmdns = ["192.168.0.2", "192.168.0.1"]
vmgateway = "192.168.0.1"
tags = {
"terraform-test-category" = "terraform-test-tag"
"terraform-test-category-02" = "terraform-test-tag-02"
}
enable_disk_uuid = true
auto_logon = true
run_once = ["command01", "command02"] // You can also run Powershell commands
Expand All @@ -146,9 +129,14 @@ output "vmnames" {
output "vmnameswip" {
value = "${module.example-server-windowsvm-advanced.Windows-ip}"
}
```

## Contributing

This module is the work of many contributors. We appreciate your help!

To contribute, please read the [contribution guidelines](https://github.com/Terraform-VMWare-Modules/terraform-vsphere-vm/blob/master/CONTRIBUTING.md)

## Authors

Originally created by [Arman Keyoumarsi](https://github.com/Arman-Keyoumarsi)
Expand Down
22 changes: 22 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Terraform vSphere examples

This directory contains various examples for deplpyong Linux/Windows VMs to a vSphere vCenter.

## Getting started

__Create a connection.tf file and copy the following code.__

```hcl
# Configure the VMware vSphere Provider
provider "vsphere" {
user = "fill"
password = "fill"
vsphere_server = "fill"
# if you have a self-signed cert
allow_unverified_ssl = true
}
```

__Copy any of the exmpale tf files and fill the required data then run terraform init/plan/apply.__
39 changes: 39 additions & 0 deletions examples/example-Windows-data_disk.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module "example-server-windowsvm-advanced" {
source = "Terraform-VMWare-Modules/vm/vsphere"
version = "X.X.X"
dc = "Datacenter"
vmrp = "cluster/Resources" #Works with ESXi/Resources
vmfolder = "Cattle"
ds_cluster = "Datastore Cluster" #You can use datastore variable instead
vmtemp = "TemplateName"
instances = 2
vmname = "AdvancedVM"
vmdomain = "somedomain.com"
network = {
"Name of the Port Group in vSphere" = ["10.13.113.2", "10.13.113.3"] # To use DHCP create Empty list ["",""]
}
data_disk = {
disk1 = {
size_gb = 30,
thin_provisioned = false,
data_disk_scsi_controller = 0,
},
disk2 = {
size_gb = 70,
thin_provisioned = true,
data_disk_scsi_controller = 1,
datastore_id = "datastore-90679"
}
}
scsi_bus_sharing = "physicalSharing" // The modes are physicalSharing, virtualSharing, and noSharing
scsi_type = "lsilogic" // Other acceptable value "pvscsi"
scsi_controller = 0 // This will assign OS disk to controller 0
vmdns = ["192.168.0.2", "192.168.0.1"]
vmgateway = "192.168.0.1"
enable_disk_uuid = true
orgname = "Terraform-Module"
workgroup = "Module-Test"
is_windows_image = true
firmware = "efi"
local_adminpass = "Password@Strong"
}
Loading

0 comments on commit 1482768

Please sign in to comment.