{{ define "agent.config.prometheus" }}
// Grafana Cloud Prometheus
local.file "prometheus_host" {
  filename  = "/etc/grafana-agent-credentials/prometheus_host"
}

local.file "prometheus_username" {
  filename  = "/etc/grafana-agent-credentials/prometheus_username"
}

local.file "prometheus_password" {
  filename  = "/etc/grafana-agent-credentials/prometheus_password"
  is_secret = true
}

prometheus.remote_write "grafana_cloud_prometheus" {
  endpoint {
    url = nonsensitive(local.file.prometheus_host.content) + "{{ .Values.externalServices.prometheus.writeEndpoint }}"
    
    basic_auth {
      username = local.file.prometheus_username.content
      password = local.file.prometheus_password.content
    }
  }
}
{{ end }}
