# helm_charts_secret.yaml
{{- if (include "external-dns.createSecret" .) }}
apiVersion: v1
kind: Secret
metadata:
  name: {{ template "external-dns.fullname" . }}
  labels: {{ include "external-dns.labels" . | nindent 4 }}
type: Opaque
data:
  {{- if eq .Values.provider "aws" }}
  credentials: {{ include "external-dns.aws-credentials" . | b64enc | quote }}
  {{- if .Values.aws.region }}
  config: {{ include "external-dns.aws-config" . | b64enc | quote }}
  {{- end }}
  {{- end }}
  {{- if eq .Values.provider "azure" }}
  azure.json: {{ include "external-dns.azure-credentials" . | b64enc | quote }}
  {{- end }}
  {{- if eq .Values.provider "google" }}
  credentials.json: {{ .Values.google.serviceAccountKey | b64enc | quote }}
  {{- end }}
  {{- if eq .Values.provider "cloudflare" }}
  {{- if .Values.cloudflare.apiToken }}
  cloudflare_api_token: {{ .Values.cloudflare.apiToken | b64enc | quote }}
  {{- else }}
  cloudflare_api_key: {{ required "cloudflare.apiKey is required if cloudflare.apiToken is not provided" .Values.cloudflare.apiKey | b64enc | quote }}
  {{- end }}
  {{- end }}
  {{- if eq .Values.provider "designate" }}
  {{- if .Values.designate.username }}
  designate_username: {{ .Values.designate.username | b64enc | quote }}
  {{- end }}
  {{- if .Values.designate.password }}
  designate_password: {{ .Values.designate.password | b64enc | quote }}
  {{- end }}
  {{- end }}
  {{- if eq .Values.provider "digitalocean" }}
  digitalocean_api_token: {{ .Values.digitalocean.apiToken | b64enc | quote }}
  {{- end }}
  {{- if eq .Values.provider "infoblox" }}
  infoblox_wapi_username: {{ .Values.infoblox.wapiUsername | b64enc | quote }}
  infoblox_wapi_password: {{ .Values.infoblox.wapiPassword | b64enc | quote }}
  {{- end }}
  {{- if eq .Values.provider "pdns" }}
  pdns_api_key: {{ .Values.pdns.apiKey | b64enc | quote }}
  {{- end }}
  {{- if eq .Values.provider "rfc2136" }}
  rfc2136_tsig_secret: {{ .Values.rfc2136.tsigSecret | b64enc | quote }}
  {{- end }}
  {{- if eq .Values.provider "transip" }}
  transip-api-key: {{ .Values.transip.apiKey | b64enc | quote }}
  {{- end }}
{{- end }}