variable "region" {
  type        = string
  description = "AWS region to deploy the EKS cluster into."
  default     = "us-west-2"
}

variable "aws_profile" {
  type        = string
  description = "Local AWS CLI profile the IaC engine should use. Must already be configured via `aws configure` or `aws sso login`."
  default     = "xylabs-datalake"
}

variable "environment" {
  type        = string
  description = "Environment name (staging, prod, etc.). Goes into resource tags + names."
  default     = "staging"
}

variable "project" {
  type        = string
  description = "Project name; goes into resource tags."
  default     = "aries-datalake"
}

variable "cluster_name" {
  type        = string
  description = "EKS cluster name. Defaults to `${var.project}-${var.environment}`."
  default     = ""
}

variable "k8s_version" {
  type        = string
  description = "Kubernetes version for the EKS control plane."
  default     = "1.31"
}

variable "vpc_cidr" {
  type        = string
  description = "CIDR block for the dedicated VPC. Must not overlap any existing VPC you intend to peer with — and must not overlap the compute-aws VPC if both stacks live in the same account."
  default     = "10.43.0.0/16"
}

variable "availability_zone_count" {
  type        = number
  description = "Number of AZs to span (>= 2 required by EKS)."
  default     = 2
}

variable "node_instance_types" {
  type        = list(string)
  description = "EC2 instance types for the managed node group. The first type is preferred; subsequent types are fallbacks when capacity is scarce."
  default     = ["t3.medium"]
}

variable "node_desired_size" {
  type        = number
  description = "Desired number of worker nodes."
  default     = 2
}

variable "node_min_size" {
  type        = number
  description = "Minimum number of worker nodes."
  default     = 1
}

variable "node_max_size" {
  type        = number
  description = "Maximum number of worker nodes."
  default     = 4
}

variable "node_disk_size_gb" {
  type        = number
  description = "Root EBS volume size per node."
  default     = 50
}

variable "node_capacity_type" {
  type        = string
  description = "`ON_DEMAND` or `SPOT`. Spot is dramatically cheaper but EKS will replace nodes on reclamation."
  default     = "ON_DEMAND"
}

variable "endpoint_public_access" {
  type        = bool
  description = "Whether the EKS API server is reachable from the public internet. Required for `aws eks update-kubeconfig` from a developer laptop. Phase 4 (PrivateLink) flips this to false."
  default     = true
}

variable "endpoint_public_access_cidrs" {
  type        = list(string)
  description = "CIDRs allowed to reach the public EKS API endpoint. Defaults to anywhere; tighten to your office IP for prod."
  default     = ["0.0.0.0/0"]
}

variable "tfstate_passphrase" {
  type        = string
  description = "Passphrase for OpenTofu state encryption. See encryption.tofu.example."
  default     = ""
  sensitive   = true
}

variable "scope_tags" {
  type        = map(string)
  description = "Tags applied to every resource via the AWS provider's default_tags. Populated by the `aries compute add --infra ...` flow with the infra-uid + managed-by tag set; left empty when the legacy `aries cluster aws ...` commands invoke the module."
  default     = {}
}

locals {
  cluster_name = length(var.cluster_name) > 0 ? var.cluster_name : "${var.project}-${var.environment}"
  name_prefix  = "${var.project}-${var.environment}-cluster"

  common_tags = merge({
    Project     = var.project
    Environment = var.environment
    Component   = "cluster"
    ManagedBy   = "opentofu"
  }, var.scope_tags)
}
