-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from Mirantis/vmware
Add basic Terraform example for VMware
- Loading branch information
Showing
8 changed files
with
287 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.terraform/ | ||
cluster.yaml | ||
terraform.tfstate* | ||
*.tfvars |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
provider "vsphere" { | ||
version = "~> 1.21" | ||
vsphere_server = var.vsphere_server | ||
user = var.vsphere_user | ||
password = var.vsphere_password | ||
|
||
# Enable this if your vSphere server has a self-signed certificate | ||
# allow_unverified_ssl = true | ||
} | ||
|
||
data "vsphere_datacenter" "dc" { | ||
name = var.datacenter | ||
} | ||
|
||
data "vsphere_resource_pool" "resource_pool" { | ||
name = var.resource_pool | ||
datacenter_id = data.vsphere_datacenter.dc.id | ||
} | ||
|
||
data "vsphere_datastore_cluster" "datastore_cluster" { | ||
name = var.datastore_cluster | ||
datacenter_id = data.vsphere_datacenter.dc.id | ||
} | ||
|
||
data "vsphere_network" "network" { | ||
name = var.network | ||
datacenter_id = data.vsphere_datacenter.dc.id | ||
} | ||
|
||
data "vsphere_virtual_machine" "template_vm_linux" { | ||
name = var.template_vm_linux | ||
datacenter_id = data.vsphere_datacenter.dc.id | ||
} | ||
|
||
# data "vsphere_virtual_machine" "template_vm_windows" { | ||
# name = "" | ||
# datacenter_id = data.vsphere_datacenter.dc.id | ||
# } | ||
|
||
module "managers" { | ||
source = "./modules/virtual_machine" | ||
quantity = var.quantity_managers | ||
name_prefix = "manager" | ||
resource_pool_id = data.vsphere_resource_pool.resource_pool.id | ||
datastore_cluster_id = data.vsphere_datastore_cluster.datastore_cluster.id | ||
folder = var.folder | ||
network_id = data.vsphere_network.network.id | ||
template_vm = data.vsphere_virtual_machine.template_vm_linux | ||
disk_size = 16 | ||
} | ||
|
||
module "workers" { | ||
source = "./modules/virtual_machine" | ||
quantity = var.quantity_workers | ||
name_prefix = "worker" | ||
resource_pool_id = data.vsphere_resource_pool.resource_pool.id | ||
datastore_cluster_id = data.vsphere_datastore_cluster.datastore_cluster.id | ||
folder = var.folder | ||
network_id = data.vsphere_network.network.id | ||
template_vm = data.vsphere_virtual_machine.template_vm_linux | ||
disk_size = 16 | ||
} | ||
|
||
# module "workers_windows" { | ||
# source = "./modules/virtual_machine" | ||
# quantity = var.quantity_workers_windows | ||
# name_prefix = "worker" | ||
# resource_pool_id = data.vsphere_resource_pool.resource_pool.id | ||
# datastore_cluster_id = data.vsphere_datastore_cluster.datastore_cluster.id | ||
# folder = "Launchpad team" | ||
# network_id = data.vsphere_network.network.id | ||
# template_vm = data.vsphere_virtual_machine.template_windows | ||
# disk_size = 16 | ||
# } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
resource "vsphere_virtual_machine" "vm" { | ||
count = var.quantity | ||
|
||
name = "${var.name_prefix}${count.index}" | ||
resource_pool_id = var.resource_pool_id | ||
datastore_cluster_id = var.datastore_cluster_id | ||
|
||
folder = var.folder | ||
|
||
guest_id = var.template_vm.guest_id | ||
|
||
network_interface { | ||
network_id = var.network_id | ||
} | ||
|
||
disk { | ||
label = "${var.name_prefix}${count.index}" | ||
size = var.disk_size | ||
thin_provisioned = var.template_vm.disks.0.thin_provisioned | ||
} | ||
|
||
clone { | ||
template_uuid = var.template_vm.id | ||
|
||
customize { | ||
network_interface{} | ||
|
||
# Hmm, the linux and windows options might make it tricky to have | ||
# a single module for handling virtual machines. | ||
linux_options { | ||
host_name = "${var.name_prefix}${count.index}" | ||
domain = "test.internal" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
output "machines" { | ||
value = vsphere_virtual_machine.vm | ||
} |
31 changes: 31 additions & 0 deletions
31
examples/terraform/vmware/modules/virtual_machine/variables.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
variable "quantity" { | ||
description = "Number of VMs to create" | ||
} | ||
|
||
variable "name_prefix" { | ||
description = "The name of the VMs will be this plus a counter value" | ||
} | ||
|
||
variable "resource_pool_id" { | ||
description = "ID of the resource pool to create the VMs in" | ||
} | ||
|
||
variable "datastore_cluster_id" { | ||
description = "ID of the datastore cluster to create the VMs in" | ||
} | ||
|
||
variable "folder" { | ||
description = "Subfolder in the datacenter at which to create the VMs" | ||
} | ||
|
||
variable "network_id" { | ||
description = "ID of the network to attach the VMs to" | ||
} | ||
|
||
variable "template_vm" { | ||
description = "The template VM which will be cloned as the base for the new VMs" | ||
} | ||
|
||
variable "disk_size" { | ||
description = "Size of the disk drive for the VMs" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
locals { | ||
managers = [ | ||
for host in module.managers.machines : { | ||
address = host.default_ip_address | ||
user = "ubuntu" # "TODO: Probably make this a variable" | ||
role = "manager" | ||
privateInterface = "ens5" # Is this supposed to be a constant? | ||
sshKeyPath = var.ssh_private_key_file | ||
} | ||
] | ||
workers = [ | ||
for host in module.workers.machines : { | ||
address = host.default_ip_address | ||
user = "ubuntu" # "TODO: Probably make this a variable" | ||
role = "worker" | ||
privateInterface = "ens5" # Is this supposed to be a constant? | ||
sshKeyPath = var.ssh_private_key_file | ||
} | ||
] | ||
# workers_windows = [ | ||
# for host in module.workers_windows.machines : { | ||
# address = host.public_ip | ||
# user = "administrator" # "TODO: Probably make this a variable" | ||
# role = "worker" | ||
# privateInterface = "Ethernet 2" # Is this supposed to be a constant? | ||
# sshKeyPath = var.ssh_private_key_file | ||
# } | ||
# ] | ||
} | ||
|
||
output "ucp_cluster" { | ||
value = { | ||
apiVersion = "launchpad.mirantis.com/v1beta1" | ||
kind = "UCP" | ||
spec = { | ||
ucp = { | ||
installFlags: [ | ||
"--admin-username=${var.ucp_admin_username}", | ||
"--admin-password=${var.ucp_admin_password}", | ||
"--default-node-orchestrator=kubernetes", | ||
"--san=${var.ucp_lb_dns_name}", | ||
] | ||
} | ||
hosts = concat(local.managers, local.workers) #, local.windows_workers) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# You may wish to populate some of the below variables from sources other than | ||
# this file (e.g. passwords). Other options include sourcing from the command | ||
# line or from environment variables. See the following page for more info: | ||
# https://www.terraform.io/docs/configuration/variables.html#assigning-values-to-root-module-variables | ||
|
||
vsphere_server = "vcenter.ingen.org" | ||
vsphere_user = "dennis.nedry" | ||
vsphere_password = "theM@gicW0rd" | ||
|
||
datacenter = "" | ||
resource_pool = "security-resources" | ||
folder = "main-ops" | ||
datastore_cluster = "main-datastore" | ||
network = "primary_network" | ||
template_vm_linux = "ubnutu-18.04" | ||
|
||
ssh_private_key_file = "./ssh_keys/id_rsa" | ||
ucp_admin_username = "admin" | ||
ucp_admin_password = "ButterF1nger$" | ||
ucp_lb_dns_name = "ucp.ingen.org" | ||
|
||
quantity_managers = 3 | ||
quantity_workers = 10 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
variable "vsphere_server" { | ||
description = "URL of vSphere server" | ||
} | ||
|
||
variable "vsphere_user" { | ||
description = "Username for connecting to vSphere" | ||
} | ||
|
||
variable "vsphere_password" { | ||
description = "Password for vSphere connection" | ||
} | ||
|
||
variable "datacenter" { | ||
default = "" | ||
} | ||
|
||
variable "resource_pool" { | ||
} | ||
|
||
variable "folder" { | ||
default = "" | ||
} | ||
|
||
variable "datastore_cluster" { | ||
} | ||
|
||
variable "network" { | ||
} | ||
|
||
variable "template_vm_linux" { | ||
description = "VM to use as a template for the linux nodes (managers, workers)" | ||
} | ||
|
||
# variable "template_vm_windows" { | ||
# description = "VM to use as a template for the Windows nodes (Windows workers)" | ||
# } | ||
|
||
variable "ssh_private_key_file" { | ||
description = "Private key for SSH connections to created virtual machines; currently all machines must use the same key" | ||
} | ||
|
||
variable "ucp_admin_username" { | ||
description = "Desired username for the UCP admin account" | ||
default = "admin" | ||
} | ||
|
||
variable "ucp_admin_password" { | ||
description = "Desired password for the UCP admin account" | ||
} | ||
|
||
variable "ucp_lb_dns_name" { | ||
description = "DNS name of the UCP load balancer" | ||
} | ||
|
||
variable "quantity_managers" { | ||
description = "Number of UCP manager VMs to create" | ||
default = 3 | ||
} | ||
|
||
variable "quantity_workers" { | ||
description = "Number of UCP worker VMs to create" | ||
default = 3 | ||
} | ||
|
||
# variable "quantity_workers_windows" { | ||
# description = "Number of UCP worker VMs to create (Windows)" | ||
# default = 0 | ||
# } |