Skip to content

Commit 1482768

Browse files
Merge pull request #56 from Terraform-VMWare-Modules/rc/v2.0.0
v2.0.0
2 parents ac4bdd1 + d4e84b9 commit 1482768

22 files changed

+601
-665
lines changed

CHANGELOG.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# ChanegLog
2+
3+
## v2.0.0
4+
__New Variables__
5+
```hcl
6+
variable "network" {
7+
description = "Define PortGroup and IPs for each VM"
8+
type = map(list(string))
9+
default = {}
10+
}
11+
variable "data_disk" {
12+
description = "Storage data disk parameter, example"
13+
type = map(map(string))
14+
default = {}
15+
}
16+
```
17+
__Removed varsiables__
18+
19+
```hcl
20+
#Network Section
21+
variable "network_cards" {
22+
description = ""
23+
type = list(string)
24+
default = null
25+
}
26+
27+
variable "ipv4" {
28+
description = "host(VM) IP address in map format, support more than one IP. Should correspond to number of instances."
29+
type = map
30+
default = {}
31+
}
32+
33+
#Data Disk Section
34+
data "vsphere_datastore" "data_disk_datastore" {
35+
for_each = toset(var.data_disk_datastore)
36+
name = each.key
37+
datacenter_id = data.vsphere_datacenter.dc.id
38+
}
39+
40+
41+
variable "data_disk_label" {
42+
description = "Storage data disk labels."
43+
type = list
44+
default = []
45+
}
46+
47+
variable "data_disk_size_gb" {
48+
description = "List of Storage data disk size."
49+
type = list
50+
default = []
51+
}
52+
53+
variable "thin_provisioned" {
54+
description = "If true, this disk is thin provisioned, with space for the file being allocated on an as-needed basis."
55+
type = list
56+
default = null
57+
}
58+
59+
variable "eagerly_scrub" {
60+
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."
61+
type = list
62+
default = null
63+
}
64+
65+
variable "data_disk_datastore" {
66+
description = "Define where the data disk should be stored, should be equal to number of defined data disks."
67+
type = list
68+
default = []
69+
# validation {
70+
# condition = length(var.disk_datastore) == 0 || length(var.disk_datastore) == length(var.data_disk_size_gb)
71+
# error_message = "The list of disk datastore must be equal in length to disk_size_gb"
72+
# }
73+
}
74+
75+
variable "data_disk_scsi_controller" {
76+
description = "scsi_controller number for the data disk, should be equal to number of defined data disk."
77+
type = list
78+
default = []
79+
# validation {
80+
# condition = max(var.data_disk_scsi_controller...) < 4 && max(var.data_disk_scsi_controller...) > -1
81+
# error_message = "The scsi_controller must be between 0 and 3"
82+
# }
83+
}
84+
```

CONTRIBUTING.md

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ We love your input! We want to make contributing to this project as easy and tra
77
- Proposing new features
88
- Becoming a maintainer
99

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

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

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

2628
## Any contributions you make will be under the MIT Software License
2729
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.
2830

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

3234
## Write bug reports with detail, background, and sample code
33-
[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.
3435

3536
**Great Bug Reports** tend to have:
3637

3738
- A quick summary and/or background
3839
- Steps to reproduce
3940
- Be specific!
40-
- 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
41+
- Give sample code if you can.
4142
- What you expected would happen
4243
- What actually happens
4344
- Notes (possibly including why you think this might be happening, or stuff you tried that didn't work)
4445

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

47-
## Use a Consistent Coding Style
48-
I'm again borrowing these from [Facebook's Guidelines](https://github.com/facebook/draft-js/blob/a9316a723f9e918afde44dea68b5f9f39b7d9b00/CONTRIBUTING.md)
49-
50-
* 2 spaces for indentation rather than tabs
51-
* You can try running `npm run lint` for style unification
52-
5348
## License
5449
By contributing, you agree that your contributions will be licensed under its MIT License.

README.md

Lines changed: 58 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,77 @@
11
# Terraform vSphere Module
22

3-
![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)
3+
![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)
44

5-
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`.
5+
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`.
66

77
## Deploys (Single/Multiple) Virtual Machines to your vSphere environment
88

99
This Terraform module deploys single or multiple virtual machines of type (Linux/Windows) with following features:
1010

1111
- Ability to specify Linux or Windows VM customization.
12-
- Ability to add extra data disk (up to 15) to the VM.
13-
- Ability to deploy Multiple instances.
14-
- Ability to set IP and Gateway configuration for the VM.
15-
- Ability to add multiple network cards for the VM
16-
- Ability to choose vSphere resource pool or fall back to Cluster/ESXi root resource pool.
17-
- Ability to deploy Windows images to WorkGroup or Domain.
18-
- Ability to output VM names and IPs per module.
19-
- Ability assign tags and custom variables.
12+
- Ability to add multiple network cards for the VM
13+
- Ability to assign tags and custom variables.
2014
- Ability to configure advance features for the vm.
2115
- Ability to deploy either a datastore or a datastore cluster.
22-
- Ability to enable cpu and memory hot plug features for the VM.
23-
- Ability to enable cpu and memory reservations for the VM.
24-
- Ability to define different datastores for data disks.
25-
- Ability to define different scsi_controllers per disk, including data disks.
26-
- Ability to define network type per interface and disk label per attached disk.
27-
- Ability to define depend on using variable vm_depends_on
16+
- Add extra data disk (up to 15) to the VM.
17+
- Different datastores for data disks (datastore_id).
18+
- Different scsi_controllers per disk, including data disks.
19+
- Ability to define depend on using variable vm_depends_on & tag_depends_on
2820

2921
> 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.
3022
31-
## Usage
23+
## Getting started
3224

3325
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.
3426

3527
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.
3628

29+
__Create a main.tf file and copy the following code. fill the required data and run terraform plan.__
30+
3731
```hcl
32+
33+
# Configure the VMware vSphere Provider
34+
provider "vsphere" {
35+
user = "fill"
36+
password = "fill"
37+
vsphere_server = "fill"
38+
39+
# if you have a self-signed cert
40+
allow_unverified_ssl = true
41+
}
42+
43+
# Deploy 2 linux VMs
3844
module "example-server-linuxvm" {
3945
source = "Terraform-VMWare-Modules/vm/vsphere"
4046
version = "X.X.X"
41-
vmtemp = "TemplateName"
42-
instances = 1
47+
vmtemp = "VM Template Name (Should Alrerady exist)"
48+
instances = 2
4349
vmname = "example-server-linux"
44-
vmrp = "esxi/Resources"
45-
network_cards = ["Name of the Port Group in vSphere"]
46-
ipv4 = {
47-
"Name of the Port Group in vSphere" = ["10.0.0.1"] # To use DHCP create Empty list for each instance
50+
vmrp = "esxi/Resources - or name of a resource pool"
51+
network = {
52+
"Name of the Port Group in vSphere" = ["10.13.113.2", "10.13.113.3"] # To use DHCP create Empty list ["",""]
4853
}
54+
vmgateway = "10.13.113.1"
4955
dc = "Datacenter"
5056
datastore = "Data Store name(use ds_cluster for datastore cluster)"
5157
}
5258
53-
module "example-server-windowsvm" {
54-
source = "Terraform-VMWare-Modules/vm/vsphere"
55-
version = "X.X.X"
56-
vmtemp = "TemplateName"
57-
is_windows_image = true
58-
instances = 1
59-
vmname = "example-server-windows"
60-
vmrp = "esxi/Resources"
61-
network_cards = ["Name of the Port Group in vSphere"]
62-
ipv4 = {
63-
"Name of the Port Group in vSphere" = ["10.0.0.1"] # To use DHCP create Empty list for each instance
64-
}
65-
dc = "Datacenter"
66-
datastore = "Data Store name(use ds_cluster for datastore cluster)"
67-
}
6859
```
6960

70-
> 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.
71-
7261
## Advance Usage
7362

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

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

88-
Below is an example of windows deployment with some of the available feature sets.
72+
> 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.
73+
74+
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)
8975

9076
```hcl
9177
module "example-server-windowsvm-advanced" {
@@ -97,38 +83,35 @@ module "example-server-windowsvm-advanced" {
9783
ds_cluster = "Datastore Cluster" #You can use datastore variable instead
9884
vmtemp = "TemplateName"
9985
instances = 2
100-
cpu_number = 2
101-
ram_size = 2096
102-
cpu_reservation = 2000
103-
memory_reservation = 2000
104-
cpu_hot_add_enabled = true
105-
cpu_hot_remove_enabled = true
106-
memory_hot_add_enabled = true
10786
vmname = "AdvancedVM"
10887
vmdomain = "somedomain.com"
109-
network_cards = ["VM Network", "test-network"] #Assign multiple cards
110-
network_type = ["vmxnet3", "vmxnet3"]
88+
network = {
89+
"Name of the Port Group in vSphere" = ["10.13.113.2", "10.13.113.3"] # To use DHCP create Empty list ["",""]
90+
"Second Network Card" = ["", ""]
91+
}
11192
ipv4submask = ["24", "8"]
112-
ipv4 = { #assign IPs per card
113-
"VM Network" = ["192.168.0.4", ""] // Here the first instance will use Static Ip and Second DHCP
114-
"test" = ["", "192.168.0.3"]
93+
network_type = ["vmxnet3", "vmxnet3"]
94+
tags = {
95+
"terraform-test-category" = "terraform-test-tag"
96+
}
97+
data_disk = {
98+
disk1 = {
99+
size_gb = 30,
100+
thin_provisioned = false,
101+
data_disk_scsi_controller = 0,
102+
},
103+
disk2 = {
104+
size_gb = 70,
105+
thin_provisioned = true,
106+
data_disk_scsi_controller = 1,
107+
datastore_id = "datastore-90679"
108+
}
115109
}
116-
data_disk_size_gb = [10, 5] // Aditional Disk to be used
117-
thin_provisioned = [true, false]
118-
disk_label = ["tpl-disk-1"]
119-
data_disk_label = ["label1", "label2"]
120-
disk_datastore = "vsanDatastore" // This will store Template disk in the defined disk_datastore
121-
data_disk_datastore = ["vsanDatastore", "nfsDatastore"] // Datastores for additional data disks
122110
scsi_bus_sharing = "physicalSharing" // The modes are physicalSharing, virtualSharing, and noSharing
123111
scsi_type = "lsilogic" // Other acceptable value "pvscsi"
124112
scsi_controller = 0 // This will assign OS disk to controller 0
125-
data_disk_scsi_controller = [0, 1] // This will create a new controller and assign second data disk to controller 1
126113
vmdns = ["192.168.0.2", "192.168.0.1"]
127114
vmgateway = "192.168.0.1"
128-
tags = {
129-
"terraform-test-category" = "terraform-test-tag"
130-
"terraform-test-category-02" = "terraform-test-tag-02"
131-
}
132115
enable_disk_uuid = true
133116
auto_logon = true
134117
run_once = ["command01", "command02"] // You can also run Powershell commands
@@ -146,9 +129,14 @@ output "vmnames" {
146129
output "vmnameswip" {
147130
value = "${module.example-server-windowsvm-advanced.Windows-ip}"
148131
}
149-
150132
```
151133

134+
## Contributing
135+
136+
This module is the work of many contributors. We appreciate your help!
137+
138+
To contribute, please read the [contribution guidelines](https://github.com/Terraform-VMWare-Modules/terraform-vsphere-vm/blob/master/CONTRIBUTING.md)
139+
152140
## Authors
153141

154142
Originally created by [Arman Keyoumarsi](https://github.com/Arman-Keyoumarsi)

examples/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Terraform vSphere examples
2+
3+
This directory contains various examples for deplpyong Linux/Windows VMs to a vSphere vCenter.
4+
5+
## Getting started
6+
7+
__Create a connection.tf file and copy the following code.__
8+
9+
```hcl
10+
11+
# Configure the VMware vSphere Provider
12+
provider "vsphere" {
13+
user = "fill"
14+
password = "fill"
15+
vsphere_server = "fill"
16+
17+
# if you have a self-signed cert
18+
allow_unverified_ssl = true
19+
}
20+
```
21+
22+
__Copy any of the exmpale tf files and fill the required data then run terraform init/plan/apply.__
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
module "example-server-windowsvm-advanced" {
2+
source = "Terraform-VMWare-Modules/vm/vsphere"
3+
version = "X.X.X"
4+
dc = "Datacenter"
5+
vmrp = "cluster/Resources" #Works with ESXi/Resources
6+
vmfolder = "Cattle"
7+
ds_cluster = "Datastore Cluster" #You can use datastore variable instead
8+
vmtemp = "TemplateName"
9+
instances = 2
10+
vmname = "AdvancedVM"
11+
vmdomain = "somedomain.com"
12+
network = {
13+
"Name of the Port Group in vSphere" = ["10.13.113.2", "10.13.113.3"] # To use DHCP create Empty list ["",""]
14+
}
15+
data_disk = {
16+
disk1 = {
17+
size_gb = 30,
18+
thin_provisioned = false,
19+
data_disk_scsi_controller = 0,
20+
},
21+
disk2 = {
22+
size_gb = 70,
23+
thin_provisioned = true,
24+
data_disk_scsi_controller = 1,
25+
datastore_id = "datastore-90679"
26+
}
27+
}
28+
scsi_bus_sharing = "physicalSharing" // The modes are physicalSharing, virtualSharing, and noSharing
29+
scsi_type = "lsilogic" // Other acceptable value "pvscsi"
30+
scsi_controller = 0 // This will assign OS disk to controller 0
31+
vmdns = ["192.168.0.2", "192.168.0.1"]
32+
vmgateway = "192.168.0.1"
33+
enable_disk_uuid = true
34+
orgname = "Terraform-Module"
35+
workgroup = "Module-Test"
36+
is_windows_image = true
37+
firmware = "efi"
38+
local_adminpass = "Password@Strong"
39+
}

0 commit comments

Comments
 (0)