resource "helm_release" "longhorn" {
  depends_on = [var.wait_on]
  name             = "longhorn"
  repository       = "https://charts.longhorn.io"
  chart            = "longhorn"
  namespace        = var.namespace
  create_namespace = true
  version          = "1.7.1"

  set = [{
      name  = "defaultSettings.defaultDataPath"
      value = "/var/lib/longhorn/"
    },
    {
      name  = "defaultSettings.defaultDataLocality"
      value = "best-effort"
    },
    {
      name  = "defaultSettings.storageOverProvisioningPercentage"
      value = "90"
    },
    {
      name  = "csi.kubeletRootDir"
      value = "/var/lib/kubelet"  # Adjust if your Rancher setup uses a different path
    },
    {
      name  = "enablePSP"
      value = "false"
    },
    {
      name  = "serviceMonitor.enabled"
      value = "true"
    },
    {
      name  = "persistence.defaultClassReplicaCount"
      value = "1"
    },
    {
      name  = "persistence.defaultDataLocality"
      value = "best-effort"
    }]
}

output "installed" {
  value = true
  depends_on = [helm_release.longhorn]
}
