Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: Update subnet configuration in main.tf to utilize the 'metal_subnet' variable. #75

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
25 changes: 11 additions & 14 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ locals {
vlan_id = var.create_vlan ? element(equinix_metal_vlan.nutanix[*].id, 0) : element(data.equinix_metal_vlan.nutanix[*].id, 0)
vxlan = var.create_vlan ? element(equinix_metal_vlan.nutanix[*].vxlan, 0) : element(data.equinix_metal_vlan.nutanix[*].vxlan, 0)

# Pick an arbitrary private subnet, we recommend a /22 like "192.168.100.0/22"
subnet = "192.168.100.0/22"

nutanix_reservation_ids = { for idx, val in var.nutanix_reservation_ids : idx => val }
}

Expand Down Expand Up @@ -64,12 +61,12 @@ resource "equinix_metal_device" "bastion" {

user_data = templatefile("${path.module}/templates/bastion-userdata.tmpl", {
metal_vlan_id = local.vxlan,
address = cidrhost(local.subnet, 2),
netmask = cidrnetmask(local.subnet),
host_dhcp_start = cidrhost(local.subnet, 3),
host_dhcp_end = cidrhost(local.subnet, 15),
vm_dhcp_start = cidrhost(local.subnet, 16),
vm_dhcp_end = cidrhost(local.subnet, -5),
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),
lease_time = "infinite",
nutanix_mac = "50:6b:8d:*:*:*",
set = "nutanix"
Expand Down Expand Up @@ -101,18 +98,18 @@ resource "equinix_metal_vrf" "nutanix" {
name = "nutanix-vrf-${random_string.vrf_name_suffix.result}"
metro = var.metal_metro
local_asn = "65000"
ip_ranges = [local.subnet]
ip_ranges = [var.cluster_subnet]
project_id = local.project_id
}

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

resource "equinix_metal_gateway" "gateway" {
Expand Down Expand Up @@ -231,7 +228,7 @@ resource "null_resource" "finalize_cluster" {

provisioner "file" {
content = templatefile("${path.module}/templates/create-cluster.sh.tmpl", {
bastion_address = cidrhost(local.subnet, 2),
bastion_address = cidrhost(var.cluster_subnet, 2),
})
destination = "/root/create-cluster.sh"
}
Expand Down
8 changes: 4 additions & 4 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ output "nutanix_sos_hostname" {

output "ssh_forward_command" {
description = "SSH port forward command to use to connect to the Prism GUI"
value = "ssh -L 9440:${data.local_file.cvm_ip_address.content}:9440 -L 19440:${cidrhost(local.subnet, -4)}:9440 -i ${module.ssh.ssh_private_key} root@${equinix_metal_device.bastion.access_public_ipv4}"
value = "ssh -L 9440:${data.local_file.cvm_ip_address.content}:9440 -L 19440:${cidrhost(var.cluster_subnet, -4)}:9440 -i ${module.ssh.ssh_private_key} root@${equinix_metal_device.bastion.access_public_ipv4}"
}

output "cvim_ip_address" {
Expand All @@ -26,16 +26,16 @@ output "cvim_ip_address" {

output "virtual_ip_address" {
description = "Reserved IP for cluster virtal IP"
value = cidrhost(local.subnet, -2)
value = cidrhost(var.cluster_subnet, -2)
}

output "iscsi_data_services_ip" {
description = "Reserved IP for cluster ISCSI Data Services IP"
value = cidrhost(local.subnet, -3)
value = cidrhost(var.cluster_subnet, -3)
}


output "prism_central_ip_address" {
description = "Reserved IP for Prism Central VM"
value = cidrhost(local.subnet, -4)
value = cidrhost(var.cluster_subnet, -4)
}
1 change: 1 addition & 0 deletions terraform.tfvars.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
# metal_vlan_id=null # ID of the VLAN you wish to use. e.g. 1234
# nutanix_node_count=3 # The number of Nutanix nodes to create.
# skip_cluster_creation=false # Skip the creation of the Nutanix cluster.
# cluster_subnet="192.168.140.0/22" # Pick an arbitrary private subnet, we recommend a /22 like "192.168.100.0/22"
# nutanix_reservation_ids=[] # Hardware reservation IDs to use for the Nutanix nodes
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ variable "metal_project_id" {
EOT
}

variable "cluster_subnet" {
type = string
default = "192.168.100.0/22"
description = "nutanix cluster subnet"
}

variable "metal_organization_id" {
type = string
default = null
Expand Down
Loading