-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.tf
More file actions
144 lines (116 loc) · 3.56 KB
/
main.tf
File metadata and controls
144 lines (116 loc) · 3.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
##################### Variables ###############################
variable "ibm_stack_name" {
description = "Name of the Virtual Machine"
}
variable "ibm_stack_id" {
description = "Name of the Virtual Machine"
}
variable "name" {
description = "Name of the Virtual Machine"
}
variable "datacenter" {
description = "Target vSphere datacenter for Virtual Machine creation"
}
variable "vcpu" {
description = "Number of Virtual CPU for the Virtual Machine"
default = 1
}
variable "memory" {
description = "Memory for Virtual Machine in MBs"
default = 1024
}
variable "cluster" {
description = "Target vSphere Cluster to host the Virtual Machine"
}
variable "network_label" {
description = "vSphere Port Group or Network label for Virtual Machine's vNIC"
}
variable "ipv4_address" {
description = "IPv4 address for vNIC configuration"
}
variable "ipv4_gateway" {
description = "IPv4 gateway for vNIC configuration"
}
variable "dns_suffixes" {
type = "list"
description = "DNS Suffixes"
}
variable "dns_server_list" {
type = "list"
description = "DNS Servers"
}
variable "ipv4_prefix_length" {
description = "IPv4 Prefix length for vNIC configuration"
}
variable "storage" {
description = "Data store or storage cluster name for target VMs disks"
}
variable "vm_template" {
description = "Source VM or Template label for cloning"
}
variable "allow_selfsigned_cert" {
description = "Communication with vsphere server with self signed certificate"
default = true
}
############### Optinal settings in provider ##########
provider "vsphere" {
version = "~> 1.1"
allow_unverified_ssl = "${var.allow_selfsigned_cert}"
}
data "vsphere_datacenter" "datacenter" {
name = "${var.datacenter}"
}
data "vsphere_virtual_machine" "template" {
name = "${var.vm_template}"
datacenter_id = "${data.vsphere_datacenter.datacenter.id}"
}
data "vsphere_datastore" "datastore" {
name = "${var.storage}"
datacenter_id = "${data.vsphere_datacenter.datacenter.id}"
}
data "vsphere_resource_pool" "pool" {
name = "${var.cluster}/Resources"
datacenter_id = "${data.vsphere_datacenter.datacenter.id}"
}
data "vsphere_network" "network" {
name = "840"
datacenter_id = "${data.vsphere_datacenter.datacenter.id}"
}
################## Resources ###############################
#
# Create VM with single vnic on a network label by cloning
#
resource "vsphere_virtual_machine" "vm_1" {
name = "${var.name}"
resource_pool_id = "${data.vsphere_resource_pool.pool.id}"
datastore_id = "${data.vsphere_datastore.datastore.id}"
num_cpus = "${var.vcpu}"
memory = "${var.memory}"
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}"
}
disk {
name = "${var.name}.vmdk"
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}"
}
clone {
template_uuid = "${data.vsphere_virtual_machine.template.id}"
customize {
linux_options {
host_name = "${var.name}"
domain = "test.internal"
}
network_interface {
ipv4_address = "${var.ipv4_address}"
ipv4_netmask = "${var.ipv4_prefix_length}"
}
ipv4_gateway = "${var.ipv4_gateway}"
dns_suffix_list = "${var.dns_suffixes}"
dns_server_list = "${var.dns_server_list}"
}
}
}