Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using ISO pre-install template #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions alternative/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# vSphere terraform unify os for customize ip hostname setting

The original repository using ova package, the alternative way using ISO pre-install VM
convert VM to template for customize.

For pre-install VM step:

1. Just install VM by ISO in normal way.
2. Left most option default.
3. Check below critiria, ensure you setup VM template correct.

Some point you may need to know before using vSphere plugin

1. vmware tool is required for clone customize
2. perl is required(if you search you will see a lot of user failed because perl
3. please aware the support matrix, some essential OS may failed the guestOS check.

Note: if you are using CentOS, sometime may failed because /etc/redhat-release not match.
There is a trick hint: for me using **Red Hat Enterprise Linux Server release 7.0 (Maipo)**
, it will work and not effect function.
79 changes: 79 additions & 0 deletions alternative/terraform.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
provider "vsphere" {
user = "${var.user}"
password = "${var.password}"
vsphere_server = "${var.vsphere_server}"

allow_unverified_ssl = true
}

data "vsphere_datacenter" "dc" {
name = "${var.datacenter}"
}

data "vsphere_datastore" "datastore" {
name = "${var.datastore}"
datacenter_id = "${data.vsphere_datacenter.dc.id}"
}

data "vsphere_resource_pool" "pool" {
name = "${var.resource_pool}"
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" {
name = "${var.template}"
datacenter_id = "${data.vsphere_datacenter.dc.id}"
}

resource "vsphere_virtual_machine" "vm" {
count = "${var.vm_numbers}"
name = "${var.name}-${count.index+1}"
resource_pool_id = "${data.vsphere_resource_pool.pool.id}"
datastore_id = "${data.vsphere_datastore.datastore.id}"

num_cpus = 4
memory = 8192
guest_id = "${data.vsphere_virtual_machine.template.guest_id}"

scsi_type = "${data.vsphere_virtual_machine.template.scsi_type}"

network_interface {
network_id = "${data.vsphere_network.network.id}"
adapter_type = "${data.vsphere_virtual_machine.template.network_interface_types[0]}"
}

disk {
label = "disk0"
size = "${data.vsphere_virtual_machine.template.disks.0.size}"
eagerly_scrub = "${data.vsphere_virtual_machine.template.disks.0.eagerly_scrub}"
thin_provisioned = "${data.vsphere_virtual_machine.template.disks.0.thin_provisioned}"
}

cdrom {
client_device = true
}

clone {
template_uuid = "${data.vsphere_virtual_machine.template.id}"
customize {
linux_options {
host_name = "${var.name}${count.index+1}"
domain = "${var.virtual_machine_domain}"
}

network_interface {
ipv4_address = "${cidrhost(var.virtual_machine_network_address, var.virtual_machine_ip_address_start + count.index)}"
ipv4_netmask = "${element(split("/", var.virtual_machine_network_address), 1)}"
}

ipv4_gateway = "${var.virtual_machine_network_gateway}"
dns_suffix_list = ["${var.virtual_machine_domain}"]
dns_server_list = ["${var.virtual_machine_dns_servers}"]
}
}
}
38 changes: 38 additions & 0 deletions alternative/terraform.tfvars.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# General vCenter data
user = "FILL_ME_IN" # VC User

password = "FILL_ME_IN" # vSphere Password

vsphere_server = "FILL_ME_IN" # VC URL (IP, hostname or FQDN)

datacenter = "FILL_ME_IN" # vSphere datacenter

datastore = "FILL_ME_IN" # vSphere datastore

resource_pool = "FILL_ME_IN" # vSphere Resourcepool

# Virtual Machine configuration
name = "FILL_ME_IN" # name of the virtual machine

template = "FILL_ME_IN" # chosen name of the template

network = "FILL_ME_IN" # network for the VM to reside in

cpus = 2 # CPU cores of the VM

memory = 1024 # Memory of the VM in Mb

vm_numbers = 4 # VM numbers you want to create

virtual_machine_network_address = "FILL_ME_IN" # VM cidr ex: 192.168.1.0/24

virtual_machine_ip_address_start = "FILL_ME_IN" # ex: 100

virtual_machine_domain = "FILL_ME_IN" # domain ex: example.com

virtual_machine_network_gateway = "FILL_ME_IN" # ex: 192.168.1.254

virtual_machine_dns_servers = [
"8.8.8.8",
"8.8.4.4",
]
62 changes: 62 additions & 0 deletions alternative/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# General vCenter data
# vCenter / ESXi Username
variable "user" {}

# vCenter / ESXi Password
variable "password" {}

# vCenter / ESXi Endpoint
variable "vsphere_server" {}

# vCenter / ESXi Datacenter
variable "datacenter" {}

# vCenter / ESXi Datastore
variable "datastore" {}

# vCenter / ESXi ResourcePool
variable "resource_pool" {}

# Virtual Machine configuration
# VM Name
variable "name" {}

# Name of OVA template (chosen in import process)
variable "template" {}

# VM Network
variable "network" {}

# VM Number of CPU's
variable "cpus" {}

# VM Memory in MB
variable "memory" {}
# VM numbers
variable "vm_numbers" {}

// The network address for the virtual machines, in the form of 10.0.0.0/24.
variable "virtual_machine_network_address" {
type = "string"
}

variable "virtual_machine_network_gateway" {
type = "string"
}

variable "virtual_machine_domain" {
type = "string"
}

// The last octect that serves as the start of the IP addresses for the virtual
// machines. Given the default value here of 100, if the network address is
// 10.0.0.0/24, the 3 virtual machines will be assigned addresses 10.0.0.100,
// 10.0.0.101, and 10.0.0.102.
variable "virtual_machine_ip_address_start" {
type = "string"
}

// The DNS servers for the network the virtual machines reside in.
variable "virtual_machine_dns_servers" {
type = "list"
}