# Validator Node Pool for Besu Network
# Deploy 1 validator per region (Standard_D2psv6 or Standard_D2s_v3 for regions without Arm support)

resource "azurerm_kubernetes_cluster_node_pool" "validators" {
  count = var.deploy_aks_clusters && var.validator_count > 0 ? 1 : 0

  name                  = "validators"
  kubernetes_cluster_id = azurerm_kubernetes_cluster.main[0].id
  node_count            = var.validator_count
  # Use region-specific override if available, otherwise use provided VM size
  vm_size               = local.validator_vm_size_override != null ? local.validator_vm_size_override : var.validator_vm_size
  vnet_subnet_id        = azurerm_subnet.nodes.id
  os_disk_size_gb       = 512
  enable_auto_scaling   = false
  # Zones not specified - let Azure use default zone availability per region
  # Some regions (e.g., canadacentral, mexicocentral) don't support zones
  # zones = [3]  # Only if region supports zones

  # Set max_surge to 1 to minimize surge node quota consumption
  # Using max_surge="1" instead of max_surge="0" to satisfy Azure requirement
  upgrade_settings {
    max_surge = "1"
  }

  node_labels = {
    pool = "validators"
    role = "validator"
  }

  node_taints = [
    "role=validator:NoSchedule"
  ]

  tags = merge(var.common_tags, {
    Pool   = "validators"
    Role   = "validator"
    Region = var.region_display
  })
}

# Output
output "validator_node_pool" {
  value = var.deploy_aks_clusters && var.validator_count > 0 ? {
    node_pool_name = azurerm_kubernetes_cluster_node_pool.validators[0].name
    node_count     = azurerm_kubernetes_cluster_node_pool.validators[0].node_count
    vm_size        = azurerm_kubernetes_cluster_node_pool.validators[0].vm_size
  } : null
}

