

resource "linode_lke_cluster" "stg-video-cluster" {
  label       = "stg-video-cluster"
  k8s_version = "1.33"
  region      = "us-central"
  tags        = ["staging"]

  pool {
    type  = "g6-standard-2"
    count = 3
    labels = {
        "workload" = "media"
    }
    taint {
      key    = "dedicated"
      value  = "media"
      effect = "NoSchedule"
    }
    autoscaler {
      min = 3
      max = 10
    }
  }

  pool {
    type  = "g6-standard-2"
    count = 2
    labels = {
        "workload" = "infra"
    }
    autoscaler {
      min = 2
      max = 5
    }
  }

}

resource "local_file" "kubeconfig" {
  filename = "stg-kubeconfig.yaml"
  content  = base64decode(linode_lke_cluster.stg-video-cluster.kubeconfig)
}

provider "kubernetes" {
  config_path = local_file.kubeconfig.filename
  alias       = "staging"
}

resource "linode_lke_cluster" "prd-video-cluster" {
  label       = "prd-video-cluster"
  k8s_version = "1.33"
  region      = "us-central"
  tags        = ["production"]

  pool {
    type  = "g6-standard-2"
    count = 3
    labels = {
        workload = "infra"
    }
  }

  # WebRTC-BE pool
  pool {
    type  = "g6-standard-2"
    count = 3
    labels = {
      workload = "app"
    }
  }
  # Coturn pool
  pool {
    type  = "g6-standard-4"
    count = 3
    labels = {
        workload = "media"
    }
  }

}

resource "local_file" "kubeconfig_prd" {
  filename = "prd-kubeconfig.yaml"
  content  = base64decode(linode_lke_cluster.prd-video-cluster.kubeconfig)
}

provider "kubernetes" {
  config_path = local_file.kubeconfig_prd.filename
  alias       = "production"
}
