Skip to content
New issue

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

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

Already on GitHub? # to your account

Fixup VSAN #1820

Merged
merged 9 commits into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 2 additions & 0 deletions scripts/packet/devrc.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export TF_VAR_ESXI_VERSION="vmware_esxi_7_0"
export TF_VAR_VSPHERE_NAS_HOST=${nas_host}
export TF_VAR_VSPHERE_ESXI1=${esxi_host_1}
export TF_VAR_VSPHERE_ESXI2=${esxi_host_2}
export TF_VAR_VSPHERE_ESXI3=${esxi_host_3}
export TF_VAR_VSPHERE_ESXI4=${esxi_host_4}
export VSPHERE_SERVER=${vsphere_host}

export TF_VAR_VSPHERE_VMFS_REGEXP='naa.'
Expand Down
42 changes: 42 additions & 0 deletions scripts/packet/main.tf.phase1
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,34 @@ resource "metal_device_network_type" "esxi2" {
type = "hybrid"
}

resource "metal_device" "esxi3" {
hostname = "${var.LAB_PREFIX}esxi3.vspheretest.internal"
plan = var.ESXI_PLAN
metro = var.PACKET_FACILITY
operating_system = var.ESXI_VERSION
billing_cycle = "hourly"
project_id = local.project_id
}

resource "metal_device_network_type" "esxi3" {
device_id = metal_device.esxi3.id
type = "hybrid"
}

resource "metal_device" "esxi4" {
hostname = "${var.LAB_PREFIX}esxi4.vspheretest.internal"
plan = var.ESXI_PLAN
metro = var.PACKET_FACILITY
operating_system = var.ESXI_VERSION
billing_cycle = "hourly"
project_id = local.project_id
}

resource "metal_device_network_type" "esxi4" {
device_id = metal_device.esxi4.id
type = "hybrid"
}

resource "metal_device" "storage1" {
hostname = "${var.LAB_PREFIX}storage1.vspheretest.internal"
plan = var.STORAGE_PLAN
Expand Down Expand Up @@ -137,6 +165,18 @@ resource "metal_port_vlan_attachment" "vmvlan_esxi2" {
vlan_vnid = metal_vlan.vmvlan.vxlan
}

resource "metal_port_vlan_attachment" "vmvlan_esxi3" {
device_id = metal_device.esxi3.id
port_name = "eth1"
vlan_vnid = metal_vlan.vmvlan.vxlan
}

resource "metal_port_vlan_attachment" "vmvlan_esxi4" {
device_id = metal_device.esxi4.id
port_name = "eth1"
vlan_vnid = metal_vlan.vmvlan.vxlan
}

# data "metal_precreated_ip_block" "private" {
# metro = var.PACKET_FACILITY
# project_id = local.project_id
Expand Down Expand Up @@ -192,6 +232,8 @@ resource "local_file" "devrc" {
nas_host = metal_device.storage1.network.0.address
esxi_host_1 = metal_device.esxi1.network.0.address
esxi_host_2 = metal_device.esxi2.network.0.address
esxi_host_3 = metal_device.esxi3.network.0.address
esxi_host_4 = metal_device.esxi4.network.0.address
vsphere_host = cidrhost("${metal_device.esxi1.network.0.address}/${metal_device.esxi1.network.0.cidr}",3)
vmfs_disk_0 = ""
vmfs_disk_1 = ""
Expand Down
167 changes: 158 additions & 9 deletions scripts/packet/main.tf.phase2
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ variable "PRIV_KEY" {}
variable "ESXI_VERSION" {
default = "vmware_esxi_7_0"
}

variable "PACKET_FACILITY" {
default = "sv"
}
Expand All @@ -53,25 +54,26 @@ provider "metal" {
auth_token = var.PACKET_AUTH
}

locals {
project_id = var.PACKET_PROJECT
}

provider "vsphere" {
user = "administrator@vcenter.vspheretest.internal"
password = "Password123!"
vsphere_server = cidrhost("${data.metal_device.esxi1.network.0.address}/${data.metal_device.esxi1.network.0.cidr}",3)
allow_unverified_ssl = true
}

output "ip" {
value = cidrhost("${data.metal_device.esxi1.network.0.address}/${data.metal_device.esxi1.network.0.cidr}",3)
}

locals {
project_id = var.PACKET_PROJECT
}

data "metal_device" "esxi1" {
project_id = local.project_id
hostname = "${var.LAB_PREFIX}esxi1.vspheretest.internal"
}

output "ip" {
value = cidrhost("${data.metal_device.esxi1.network.0.address}/${data.metal_device.esxi1.network.0.cidr}",3)
}

resource "metal_device" "esxi1" {
hostname = "${var.LAB_PREFIX}esxi1.vspheretest.internal"
Expand Down Expand Up @@ -101,6 +103,34 @@ resource "metal_device_network_type" "esxi2" {
type = "hybrid"
}

resource "metal_device" "esxi3" {
hostname = "${var.LAB_PREFIX}esxi3.vspheretest.internal"
plan = var.ESXI_PLAN
metro = var.PACKET_FACILITY
operating_system = var.ESXI_VERSION
billing_cycle = "hourly"
project_id = local.project_id
}

resource "metal_device_network_type" "esxi3" {
device_id = metal_device.esxi3.id
type = "hybrid"
}

resource "metal_device" "esxi4" {
hostname = "${var.LAB_PREFIX}esxi4.vspheretest.internal"
plan = var.ESXI_PLAN
metro = var.PACKET_FACILITY
operating_system = var.ESXI_VERSION
billing_cycle = "hourly"
project_id = local.project_id
}

resource "metal_device_network_type" "esxi4" {
device_id = metal_device.esxi4.id
type = "hybrid"
}

resource "metal_device" "storage1" {
hostname = "${var.LAB_PREFIX}storage1.vspheretest.internal"
plan = var.STORAGE_PLAN
Expand Down Expand Up @@ -143,6 +173,18 @@ resource "metal_port_vlan_attachment" "vmvlan_esxi2" {
vlan_vnid = metal_vlan.vmvlan.vxlan
}

resource "metal_port_vlan_attachment" "vmvlan_esxi3" {
device_id = metal_device.esxi3.id
port_name = "eth1"
vlan_vnid = metal_vlan.vmvlan.vxlan
}

resource "metal_port_vlan_attachment" "vmvlan_esxi4" {
device_id = metal_device.esxi4.id
port_name = "eth1"
vlan_vnid = metal_vlan.vmvlan.vxlan
}

# data "metal_precreated_ip_block" "private" {
# metro = var.PACKET_FACILITY
# project_id = local.project_id
Expand All @@ -157,14 +199,19 @@ resource "metal_port_vlan_attachment" "vmvlan_esxi2" {
# public = true
# }

data "vsphere_network" "vmnet" {
datacenter_id = vsphere_datacenter.dc.moid
name = "VM Network"
}

resource "vsphere_resource_pool" "pool" {
name = var.VSPHERE_RESOURCE_POOL
parent_resource_pool_id = vsphere_compute_cluster.compute_cluster.resource_pool_id
}

resource "vsphere_nas_datastore" "ds" {
name = var.VSPHERE_NFS_DS_NAME
host_system_ids = [vsphere_host.host1.id, vsphere_host.host2.id]
host_system_ids = [vsphere_host.host1.id, vsphere_host.host2.id, vsphere_host.host3.id, vsphere_host.host4.id]
type = "NFS"
remote_hosts = [metal_device.storage1.network.0.address]
remote_path = "/nfs"
Expand All @@ -188,6 +235,16 @@ resource "vsphere_distributed_virtual_switch" "dvs" {
devices = [var.VSPHERE_ESXI_TRUNK_NIC]
}

host {
host_system_id = vsphere_host.host3.id
devices = [var.VSPHERE_ESXI_TRUNK_NIC]
}

host {
host_system_id = vsphere_host.host4.id
devices = [var.VSPHERE_ESXI_TRUNK_NIC]
}

version = "7.0.0"
}

Expand All @@ -214,7 +271,17 @@ data "vsphere_host_thumbprint" "esxi1" {
data "vsphere_host_thumbprint" "esxi2" {
address = metal_device.esxi2.network.0.address
insecure = true
}
}

data "vsphere_host_thumbprint" "esxi3" {
address = metal_device.esxi3.network.0.address
insecure = true
}

data "vsphere_host_thumbprint" "esxi4" {
address = metal_device.esxi4.network.0.address
insecure = true
}

resource "vsphere_compute_cluster" "compute_cluster" {
name = var.VSPHERE_CLUSTER
Expand Down Expand Up @@ -246,6 +313,86 @@ resource "vsphere_host" "host2" {
thumbprint = data.vsphere_host_thumbprint.esxi2.id
}

# Manually enable vsan on this host in the vsphere UI
# Enable vsan in VMKernal Adapters on the management network
resource "vsphere_host" "host3" {
hostname = metal_device.esxi3.network.0.address
username = "root"
password = metal_device.esxi3.root_password
license = vsphere_license.license.license_key
force = true
datacenter = vsphere_datacenter.dc.moid
thumbprint = data.vsphere_host_thumbprint.esxi3.id
}

# Manually enable vsan on this host in the vsphere UI
appilon marked this conversation as resolved.
Show resolved Hide resolved
# Enable vsan in VMKernal Adapters on the management network
appilon marked this conversation as resolved.
Show resolved Hide resolved
resource "vsphere_host" "host4" {
hostname = metal_device.esxi4.network.0.address
username = "root"
password = metal_device.esxi4.root_password
license = vsphere_license.license.license_key
force = true
datacenter = vsphere_datacenter.dc.moid
thumbprint = data.vsphere_host_thumbprint.esxi4.id
}

resource "vsphere_virtual_machine" "template" {
name = var.VSPHERE_TEMPLATE
resource_pool_id = vsphere_compute_cluster.compute_cluster.resource_pool_id
datastore_id = vsphere_nas_datastore.ds.id
datacenter_id = vsphere_datacenter.dc.moid
host_system_id = vsphere_host.host2.id

wait_for_guest_net_timeout = -1

num_cpus = 2
memory = 2048
guest_id = "other3xLinuxGuest"

network_interface {
network_id = vsphere_distributed_port_group.pg.id
}

ovf_deploy {
remote_ovf_url = "https://storage.googleapis.com/vsphere-acctest/TinyVM/TinyVM.ovf"
ovf_network_map = {
"terraform-test-pg" = vsphere_distributed_port_group.pg.id
}
}
}

resource "vsphere_virtual_machine" "pxe" {
name = "pxe-server"
resource_pool_id = vsphere_compute_cluster.compute_cluster.resource_pool_id
datastore_id = vsphere_nas_datastore.ds.id

wait_for_guest_net_timeout = -1

num_cpus = 2
memory = 2048
guest_id = "other3xLinuxGuest"

network_interface {
network_id = data.vsphere_network.vmnet.id
}
network_interface {
network_id = vsphere_distributed_port_group.pg.id
}
clone {
template_uuid = vsphere_virtual_machine.template.id
}

disk {
label = "disk0"
size = 20
}

cdrom {
client_device = true
}
}

data "vsphere_vmfs_disks" "available" {
host_system_id = vsphere_host.host1.id
rescan = true
Expand All @@ -257,6 +404,8 @@ resource "local_file" "devrc" {
nas_host = metal_device.storage1.network.0.address
esxi_host_1 = metal_device.esxi1.network.0.address
esxi_host_2 = metal_device.esxi2.network.0.address
esxi_host_3 = metal_device.esxi3.network.0.address
esxi_host_4 = metal_device.esxi4.network.0.address
vsphere_host = cidrhost("${metal_device.esxi1.network.0.address}/${metal_device.esxi1.network.0.cidr}",3)
vmfs_disk_0 = data.vsphere_vmfs_disks.available.disks[0]
vmfs_disk_1 = data.vsphere_vmfs_disks.available.disks[1]
Expand Down
Loading