Skip to content

Commit

Permalink
Fix: De-centralize the network support multiple clusters @build @publish
Browse files Browse the repository at this point in the history
  • Loading branch information
codinja1188 committed Jun 25, 2024
1 parent 81c68cb commit 43bdf70
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
26 changes: 11 additions & 15 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,13 @@ resource "equinix_metal_device" "bastion" {

user_data = templatefile("${path.module}/templates/bastion-userdata.tmpl", {
metal_vlan_id = local.vxlan,
address = cidrhost(var.cluster_subnet, 2),
netmask = cidrnetmask(var.cluster_subnet),
host_dhcp_start = cidrhost(var.cluster_subnet, 3),
host_dhcp_end = cidrhost(var.cluster_subnet, 15),
vm_dhcp_start = cidrhost(var.cluster_subnet, 16),
vm_dhcp_end = cidrhost(var.cluster_subnet, -5),
address = cidrhost(cidrsubnet(var.cluster_subnet, 1, 1), 2),
netmask = cidrnetmask(cidrsubnet(var.cluster_subnet, 1, 1)),
gateway_address = cidrhost(cidrsubnet(var.cluster_subnet, 1, 1), 1),
host_dhcp_start = cidrhost(cidrsubnet(var.cluster_subnet, 1, 1), 3),
host_dhcp_end = cidrhost(cidrsubnet(var.cluster_subnet, 1, 1), 15),
vm_dhcp_start = cidrhost(cidrsubnet(var.cluster_subnet, 1, 1), 16),
vm_dhcp_end = cidrhost(cidrsubnet(var.cluster_subnet, 1, 1), -5),
lease_time = "infinite",
nutanix_mac = "50:6b:8d:*:*:*",
set = "nutanix"
Expand All @@ -83,9 +84,6 @@ resource "equinix_metal_port" "bastion_bond0" {
vlan_ids = [local.vlan_id]
}

# This generates a random suffix to avoid VRF name
# collisions when multiple clusters are deployed to
# an existing Metal project
resource "random_string" "vrf_name_suffix" {
length = 5
special = false
Expand All @@ -107,13 +105,13 @@ data "equinix_metal_vrf" "nutanix" {
}

resource "equinix_metal_reserved_ip_block" "nutanix" {
description = "Reserved IP block (${var.cluster_subnet}) taken from on of the ranges in the VRF's pool of address space."
description = "Reserved IP block (${var.cluster_subnet}) taken from one of the ranges in the VRF's pool of address space."
project_id = local.project_id
metro = var.metal_metro
type = "vrf"
vrf_id = local.vrf_id
cidr = split("/", var.cluster_subnet)[1]
network = cidrhost(var.cluster_subnet, 0)
cidr = split("/", cidrsubnet(var.cluster_subnet, 1, 1))[1]
network = cidrhost(cidrsubnet(var.cluster_subnet, 1, 1), 0)
}

resource "equinix_metal_gateway" "gateway" {
Expand All @@ -136,7 +134,6 @@ resource "equinix_metal_device" "nutanix" {
ip_address {
type = "private_ipv4"
}

}

resource "null_resource" "wait_for_firstboot" {
Expand Down Expand Up @@ -166,7 +163,6 @@ resource "equinix_metal_port" "nutanix" {
layer2 = true
bonded = true
vlan_ids = [local.vlan_id]

}

resource "null_resource" "reboot_nutanix" {
Expand Down Expand Up @@ -230,7 +226,7 @@ resource "null_resource" "finalize_cluster" {

provisioner "file" {
content = templatefile("${path.module}/templates/create-cluster.sh.tmpl", {
bastion_address = cidrhost(var.cluster_subnet, 2),
bastion_address = cidrhost(cidrsubnet(var.cluster_subnet, 1, 1), 2),
})
destination = "/root/create-cluster.sh"
}
Expand Down
1 change: 1 addition & 0 deletions templates/bastion-userdata.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ write_files:
pre-up sleep 5
address ${address}
netmask ${netmask}
gateway ${gateway_address}
vlan-raw-device bond0
- path: /etc/dnsmasq.d/nutanix.config
append: true
Expand Down

0 comments on commit 43bdf70

Please sign in to comment.