-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvsphere.tf
97 lines (78 loc) · 2.76 KB
/
vsphere.tf
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
#===============================================================================
# vSphere Provider
#===============================================================================
terraform {
required_providers {
vsphere = {
source = "registry.terraform.io/hashicorp/vsphere"
version = "2.2.0"
}
}
}
provider "vsphere" {
vsphere_server = "${var.vsphere_vcenter}"
user = "${var.vsphere_user}"
password = "${var.vsphere_password}"
allow_unverified_ssl = "${var.vsphere_unverified_ssl}"
}
#===============================================================================
# vSphere Data
#===============================================================================
data "vsphere_datacenter" "dc" {
name = "${var.vsphere_datacenter}"
}
data "vsphere_compute_cluster" "cluster" {
name = "${var.vsphere_cluster}"
datacenter_id = "${data.vsphere_datacenter.dc.id}"
}
data "vsphere_datastore" "datastore" {
name = "${var.vm_datastore}"
datacenter_id = "${data.vsphere_datacenter.dc.id}"
}
data "vsphere_network" "network" {
name = "${var.vm_network}"
datacenter_id = "${data.vsphere_datacenter.dc.id}"
distributed_virtual_switch_uuid = "${var.vm_switch_uuid}"
}
data "vsphere_virtual_machine" "template" {
name = "${var.vm_template}"
datacenter_id = "${data.vsphere_datacenter.dc.id}"
}
#===============================================================================
# vSphere Resources
#===============================================================================
resource "vsphere_virtual_machine" "standalone" {
name = "${var.vm_name}"
resource_pool_id = "${data.vsphere_compute_cluster.cluster.resource_pool_id}"
datastore_id = "${data.vsphere_datastore.datastore.id}"
num_cpus = "${var.vm_cpu}"
memory = "${var.vm_ram}"
guest_id = "${data.vsphere_virtual_machine.template.guest_id}"
firmware = "efi"
network_interface {
network_id = "${data.vsphere_network.network.id}"
}
disk {
label = "${var.vm_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}"
linked_clone = "${var.vm_linked_clone}"
customize {
timeout = "20"
linux_options {
host_name = "${var.vm_name}"
domain = "${var.vm_domain}"
}
network_interface {
ipv4_address = "${var.vm_ip}"
ipv4_netmask = "${var.vm_netmask}"
}
ipv4_gateway = "${var.vm_gateway}"
dns_server_list = ["${var.vm_dns}"]
}
}
}