// Create a GKE node pool attached to an existing GKE cluster
// Assumes the GKE cluster already exists (referenced by name in var.cluster_name)
// Note: this file intentionally keeps the sizing, labels and taints similar to the original EKS example.

terraform {
  required_version = ">= 1.0.0"

  required_providers {
    google = {
      source  = "hashicorp/google"
      version = "~> 4.0"
    }
  }
}

provider "google" {
  // project is optional here; if omitted the provider will use the environment or default credentials project
  region = var.region
}

resource "google_container_node_pool" "metrics-integration" {
  name    = "metrics-integration"
  cluster = var.cluster_name
  location = var.region

  node_config {
    // Roughly map m5.xlarge -> n2-standard-4 (4 vCPU, 16GB)
    machine_type = "e2-standard-4"

    labels = {
      component = "metrics-integration"
    }

    taint {
      key    = "app"
      value  = "metrics-integration"
      effect = "NO_SCHEDULE"
    }
  }

  // Use autoscaling to mirror the AWS scaling_config (min 0, max 5)
  autoscaling {
    min_node_count = 0
    max_node_count = 3
  }

  // Keep initial count aligned with desired_size from the original (0). Note: some GKE/API versions
  // may require initial_node_count >= 1 when creating node pools; adjust if provider errors occur.
  initial_node_count = 0

  management {
    auto_repair  = true
    auto_upgrade = false
  }
}
