From a1e6394ef63cbdb67f6bfce3b9af6a57e9cf862d Mon Sep 17 00:00:00 2001 From: codinja1188 <3358152+vasubabu@users.noreply.github.com> Date: Mon, 3 Jun 2024 21:25:27 +0530 Subject: [PATCH] feat: Update subnet configuration in main.tf to utilize the 'metal_subnet' variable. --- main.tf | 25 +++++++++++-------------- outputs.tf | 8 ++++---- terraform.tfvars.example | 1 + variables.tf | 6 ++++++ 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/main.tf b/main.tf index e7e8286..b9941e8 100644 --- a/main.tf +++ b/main.tf @@ -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 } } @@ -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" @@ -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" { @@ -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" } diff --git a/outputs.tf b/outputs.tf index d893aac..ba777b9 100644 --- a/outputs.tf +++ b/outputs.tf @@ -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" { @@ -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) } diff --git a/terraform.tfvars.example b/terraform.tfvars.example index 2f04f52..8c4ab2a 100644 --- a/terraform.tfvars.example +++ b/terraform.tfvars.example @@ -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 diff --git a/variables.tf b/variables.tf index f4d9045..0ff872b 100644 --- a/variables.tf +++ b/variables.tf @@ -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