Initial draft w/ new vsphere provider
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Danny Bessems 2021-03-31 09:27:34 +02:00
parent c66d489865
commit eb19e05995
7 changed files with 125 additions and 102 deletions

View File

@ -1,11 +1,26 @@
resource "vsphere_virtual_machine" "TF-DC01" {
name = "TF-DC01"
data "vsphere_ovf_vm_template" {
name = "ovf-dc"
resource_pool_id = data.vsphere_resource_pool.pool.id
datastore_id = data.vsphere_datastore.vmdatastore.id
datastore_id = data.vpshere_datastore.datastore.id
host_system_id = data.vsphere_host.host.id
remote_ovf_url = "https://${var.repo_username}:${var.repo_password}@sn.itch.fyi/Repository/rel/ADDS-appliance.ova"
deployment_option = "standalone"
}
resource "vsphere_virtual_machine" "vm-dc" {
name = "TF-DC01"
num_cpus = var.vm_numcpu
memory = var.vm_memory
datacenter_id = data.vsphere_datacenter.dc.id
folder = var.vsphere_vmfolder
num_cpus = 2
memory = 4096
guest_id = data.vsphere_ovf_vm_template.ovf-dc.guest_id
resource_pool_id = data.vsphere_ovf_vm_template.ovf-dc.resource_pool_id
datastore_id = data.vsphere_ovf_vm_template.ovf-dc.datastore_id
host_system_id = data.vsphere_ovf_vm_template.ovf-dc.host_system_id
network_interface {
network_id = data.vsphere_network.network.id
@ -18,34 +33,32 @@ resource "vsphere_virtual_machine" "TF-DC01" {
thin_provisioned = true
}
ovf_deploy {
remote_ovf_url = data.vsphere_ovf_vm_template.ovf-dc.remote_ovf_url
deployment_option = data.vsphere_ovf_vm_template.ovf-dc.deployment_option
}
vapp {
properties = {
# "deployment.type" = "primary"
"guestinfo.hostname" = "TF-DC01"
"guestinfo.ipaddress" = "10.0.0.21"
"guestinfo.prefixlength" = "24"
# "guestinfo.dnsserver" = "0.0.0.0"
"guestinfo.gateway" = "10.0.0.1"
"addsconfig.domainname" = "srv.io"
"addsconfig.netbiosname" = "SRV"
"addsconfig.domainname" = var.adds_domainname
"addsconfig.netbiosname" = var.adds_netbiosname
"addsconfig.administratorpw" = var.adds_password
"addsconfig.safemodepw" = var.adds_password
"addsconfig.ntpserver" = "0.pool.ntp.org,1.pool.ntp.org,2.pool.ntp.org"
"addsconfig.ntpserver" = var.adds_ntpserver
# "dhcpconfig.startip" = "10.0.0.50"
# "dhcpconfig.endip" = "10.0.0.250"
# "dhcpconfig.subnetmask" = "255.255.255.0"
# "dhcpconfig.gateway" = "10.0.0.1"
# "dhcpconfig.leaseduration" = "01:00:00.00"
"dhcpconfig.startip" = var.dhcp_startip
"dhcpconfig.endip" = var.dhcp_endip
"dhcpconfig.subnetmask" = var.dhcp_subnetmask
"dhcpconfig.gateway" = var.dhcp_gateway
"dhcpconfig.leaseduration" = var.dhcp_leaseduration
}
}
clone {
template_uuid = vsphere_content_library_item.ADDS.id
}
# # This does not actually achieve protection from destruction, see https://github.com/hashicorp/terraform/issues/17599
# lifecycle {
# prevent_destroy = true

View File

@ -1,11 +1,26 @@
resource "vsphere_virtual_machine" "TF-SRV01" {
name = "TF-SRV01"
data "vsphere_ovf_vm_template" {
name = "ovf-srv"
resource_pool_id = data.vsphere_resource_pool.pool.id
datastore_id = data.vsphere_datastore.vmdatastore.id
datastore_id = data.vpshere_datastore.datastore.id
host_system_id = data.vsphere_host.host.id
remote_ovf_url = "https://${var.repo_username}:${var.repo_password}@sn.itch.fyi/Repository/rel/Windows-Server-2019-LTSC.ova"
deployment_option = "domainmember"
}
resource "vsphere_virtual_machine" "vm-srv" {
name = "TF-SRV01"
num_cpus = var.vm_numcpu
memory = var.vm_memory
datacenter_id = data.vsphere_datacenter.dc.id
folder = var.vsphere_vmfolder
num_cpus = 2
memory = 4096
guest_id = data.vsphere_ovf_vm_template.ovf-srv.guest_id
resource_pool_id = data.vsphere_ovf_vm_template.ovf-srv.resource_pool_id
datastore_id = data.vsphere_ovf_vm_template.ovf-srv.datastore_id
host_system_id = data.vsphere_ovf_vm_template.ovf-srv.host_system_id
network_interface {
network_id = data.vsphere_network.network.id
@ -24,30 +39,27 @@ resource "vsphere_virtual_machine" "TF-SRV01" {
thin_provisioned = true
}
ovf_deploy {
remote_ovf_url = data.vsphere_ovf_vm_template.ovf-srv.remote_ovf_url
deployment_option = data.vsphere_ovf_vm_template.ovf-srv.deployment_option
}
vapp {
properties = {
# "deployment.type" = "standalone"
"guestinfo.hostname" = "TF-SRV01"
"guestinfo.ipaddress" = "10.0.0.42"
"guestinfo.prefixlength" = "24"
"guestinfo.dnsserver" = "10.0.0.21"
"guestinfo.gateway" = "10.0.0.1"
"guestinfo.hostname" = "TF-SRV01"
# "guestinfo.administratorpw" = "Secret123!"
# "guestinfo.ntpserver" = "0.pool.ntp.org,1.pool.ntp.org,2.pool.ntp.org"
"guestinfo.ipaddress" = "10.0.0.42"
"guestinfo.prefixlength" = "24"
"guestinfo.dnsserver" = "10.0.0.21"
"guestinfo.gateway" = "10.0.0.1"
"addsconfig.domainname" = "srv.io"
"addsconfig.username" = "SRV\\Administrator"
"addsconfig.password" = var.adds_password
"addsconfig.domainname" = var.adds_domainname
"addsconfig.username" = var.adds_username
"addsconfig.password" = var.adds_password
}
}
clone {
template_uuid = vsphere_content_library_item.Server2019.id
}
depends_on = [
vsphere_virtual_machine.TF-DC01
vsphere_virtual_machine.vm-dc
]
# # This does not actually achieve protection from destruction, see https://github.com/hashicorp/terraform/issues/17599

View File

@ -1,28 +0,0 @@
resource "vsphere_content_library" "library" {
name = "OVA appliances"
storage_backing = flatten([
data.vsphere_datastore.cldatastore.id
])
}
resource "vsphere_content_library_item" "Server2019" {
name = "Windows-Server-2019-LTSC"
library_id = vsphere_content_library.library.id
file_url = "https://${var.repo_username}:${var.repo_password}@sn.itch.fyi/Repository/rel/Windows-Server-2019-LTSC.ova"
}
resource "vsphere_content_library_item" "ADCS" {
name = "ADCS-appliance"
library_id = vsphere_content_library.library.id
file_url = "https://${var.repo_username}:${var.repo_password}@sn.itch.fyi/Repository/rel/ADCS-appliance.ova"
}
resource "vsphere_content_library_item" "ADDS" {
name = "ADDS-appliance"
library_id = vsphere_content_library.library.id
file_url = "https://${var.repo_username}:${var.repo_password}@sn.itch.fyi/Repository/rel/ADDS-appliance.ova"
}
resource "vsphere_content_library_item" "Win10" {
name = "Windows 10"
library_id = vsphere_content_library.library.id
file_url = "https://${var.repo_username}:${var.repo_password}@sn.itch.fyi/Repository/rel/Windows10.ova"
}

View File

@ -4,38 +4,39 @@ terraform {
required_providers {
vsphere = {
source = "hashicorp/vsphere"
version = "~> 1.24.3"
version = "~> 1.25.0"
}
}
}
provider "vsphere" {
vsphere_server = var.vcenter_server
user = var.vsphere_username
password = var.vsphere_password
vsphere_server = var.hv_fqdn
user = var.hv_username
password = var.hv_password
allow_unverified_ssl = true
}
data "vsphere_datacenter" "dc" {
name = var.vsphere_datacenter
name = var.hv_datacenter
}
data "vsphere_resource_pool" "pool" {
name = "/${var.vsphere_datacenter}/host/${var.vsphere_host}/Resources"
name = "/${var.hv_datacenter}/host/${var.hv_host}/Resources"
datacenter_id = data.vsphere_datacenter.dc.id
}
data "vsphere_datastore" "vmdatastore" {
name = var.vsphere_vmdatastore
datacenter_id = data.vsphere_datacenter.dc.id
data "vsphere_host" "host" {
name = var.hv_host
datacenter = data.vsphere_datacenter.dc.id
}
data "vsphere_datastore" "cldatastore" {
name = var.vsphere_cldatastore
data "vsphere_datastore" "datastore" {
name = var.hv_datastore
datacenter_id = data.vsphere_datacenter.dc.id
}
data "vsphere_network" "network" {
name = var.vsphere_network
name = var.hv_network
datacenter_id = data.vsphere_datacenter.dc.id
}

View File

@ -1,17 +1,29 @@
variable "vcenter_server" {}
variable "vsphere_username" {}
variable "vsphere_password" {}
variable "hv_fqdn" {}
variable "hv_username" {}
variable "hv_password" {}
variable "vsphere_datacenter" {}
variable "vsphere_host" {}
variable "vsphere_hostip" {}
variable "hv_datacenter" {}
variable "hv_host" {}
variable "hv_hostip" {}
variable "vsphere_vmdatastore" {}
variable "vsphere_cldatastore" {}
variable "vsphere_vmfolder" {}
variable "vsphere_network" {}
variable "hv_datastore" {}
variable "hv_vmfolder" {}
variable "hv_network" {}
variable "repo_username" {}
variable "repo_password" {}
variable "adds_password" {}
variable "vm_numcpu" {}
variable "vm_memory" {}
variable "adds_domainname" {}
variable "adds_netbiosname" {}
variable "adds_username" {}
variable "adds_password" {}
variable "adds_ntpserver" {}
variable "dhcp_startip" {}
variable "dhcp_endip" {}
variable "dhcp_subnetmask" {}
variable "dhcp_gateway" {}
variable "dhcp_leaseduration" {}

13
terraform/vm.tfvars Normal file
View File

@ -0,0 +1,13 @@
vm_numcpu = 2
vm_memory = 4096
adds_domainname = "srv.io"
adds_netbiosname = "SRV"
adds_username = "SRV\\Administrator"
adds_ntpserver = "0.pool.ntp.org,1.pool.ntp.org,2.pool.ntp.org"
dhcp_startip = "10.0.0.50"
dhcp_endip = "10.0.0.250"
dhcp_subnetmask = "255.255.255.0"
dhcp_gateway = "10.0.0.1"
dhcp_leaseduration = "01:00:00.00"

View File

@ -1,9 +1,9 @@
vcenter_server = "bv11-vc01.bessems.lan"
vsphere_username = "administrator@vsphere.local"
vsphere_datacenter = "DeSchakel"
vsphere_host = "bv11-esx.bessems.eu"
vsphere_hostip = "192.168.11.200"
vsphere_vmdatastore = "Datastore02.SSD"
vsphere_cldatastore = "Datastore01.NAS"
vsphere_vmfolder = "/Terraform"
vsphere_network = "Isolated"
hv_server = "bv11-vc01.bessems.lan"
hv_username = "administrator@vsphere.local"
hv_datacenter = "DeSchakel"
hv_host = "bv11-esx.bessems.eu"
hv_hostip = "192.168.11.200"
hv_vmdatastore = "Datastore02.SSD"
hv_cldatastore = "Datastore01.NAS"
hv_vmfolder = "/Terraform"
hv_network = "Isolated"