apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ template "common.names.fullname" . }}
  labels: {{- include "common.labels.standard" . | nindent 4 }}
  {{- if .Values.commonLabels }}
  {{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
  {{- end }}
  {{- if .Values.commonAnnotations }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  {{- end }}
data:
  {{- $port := .Values.service.port | toString }}
  DISCOURSE_HOST: "{{ include "discourse.host" . }}"
  DISCOURSE_SKIP_INSTALL: {{ ternary "yes" "no" .Values.discourse.skipInstall | quote }}
  DISCOURSE_SITE_NAME: {{ .Values.discourse.siteName | quote }}
  DISCOURSE_USERNAME: {{ .Values.discourse.username | quote }}
  DISCOURSE_EMAIL: {{ .Values.discourse.email | quote }}
  DISCOURSE_REDIS_HOST: {{ template "discourse.redisHost" . }}
  DISCOURSE_REDIS_PORT_NUMBER: {{ template "discourse.redisPort" . }}
  DISCOURSE_DATABASE_HOST: {{ template "discourse.databaseHost" . }}
  DISCOURSE_DATABASE_PORT_NUMBER: {{ template "discourse.databasePort" . }}
  DISCOURSE_DATABASE_NAME: {{ template "discourse.databaseName" . }}
  DISCOURSE_DATABASE_USER: {{ template "discourse.databaseUser" . }}
  {{- if .Values.discourse.smtp.enabled }}
  DISCOURSE_SMTP_HOST: {{ .Values.discourse.smtp.host | quote }}
  DISCOURSE_SMTP_PORT: {{ .Values.discourse.smtp.port | quote }}
  {{- if .Values.discourse.smtp.user }}
  DISCOURSE_SMTP_USER: {{ .Values.discourse.smtp.user | quote }}
  {{- end }}
  {{- if .Values.discourse.smtp.protocol }}
  DISCOURSE_SMTP_PROTOCOL: {{ .Values.discourse.smtp.protocol | quote }}
  {{- end }}
  {{- if .Values.discourse.smtp.auth }}
  DISCOURSE_SMTP_AUTH: {{ .Values.discourse.smtp.auth | quote }}
  {{- end }}
  {{- end }}
  {{- if or .Values.postgresql.enabled .Values.externalDatabase.create }}
  POSTGRESQL_CLIENT_DATABASE_HOST: {{ template "discourse.databaseHost" . }}
  POSTGRESQL_CLIENT_DATABASE_PORT_NUMBER: {{ template "discourse.databasePort" . }}
  {{- if or .Values.postgresql.enabled (not .Values.externalDatabase.postgresqlPostgresUser) }}
  POSTGRESQL_CLIENT_POSTGRES_USER: "postgres"
  {{- else }}
  POSTGRESQL_CLIENT_POSTGRES_USER: {{ .Values.externalDatabase.postgresqlPostgresUser | quote }}
  POSTGRESQL_CLIENT_CREATE_DATABASE_USERNAME: {{ .Values.externalDatabase.user | quote }}
  POSTGRESQL_CLIENT_CREATE_DATABASE_PASSWORD: {{ .Values.externalDatabase.password | quote }}
  {{- end }}
  POSTGRESQL_CLIENT_CREATE_DATABASE_NAME: {{ template "discourse.databaseName" . }}
  POSTGRESQL_CLIENT_CREATE_DATABASE_EXTENSIONS: "hstore,pg_trgm"
  {{- end }}
