{{- if (include "external-dns.createSecret" .) }}
apiVersion: v1
kind: Secret
metadata:
  name: {{ template "external-dns.fullname" . }}
  labels: {{ include "external-dns.labels" . | nindent 4 }}
  {{- if .Values.secretAnnotations }}
  annotations: {{- include "common.tplvalues.render" (dict "value" .Values.secretAnnotations "context" $) | nindent 4 }}
  {{- end }}
type: Opaque
data:
  {{- if eq .Values.provider "alibabacloud" }}
  alibaba-cloud.json: {{ include "external-dns.alibabacloud-credentials" . | b64enc | quote }}
  {{- end }}
  {{- 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 or (eq .Values.provider "azure") (eq .Values.provider "azure-private-dns") }}
  azure.json: {{ include "external-dns.azure-credentials" . | b64enc | quote }}
  {{- end }}
  {{- if eq .Values.provider "google" }}
  credentials.json: {{ .Values.google.serviceAccountKey | b64enc | quote }}
  {{- end }}
  {{- if and (eq .Values.provider "hetzner") (not .Values.hetzner.secretName) }}
  hetzner_token: {{ .Values.hetzner.token | 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 "linode" }}
  linode_api_token: {{ .Values.linode.apiToken | 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 }}
  {{- if eq .Values.provider "ovh" }}
  ovh_consumer_key: {{ .Values.ovh.consumerKey | b64enc | quote }}
  ovh_application_key: {{ .Values.ovh.applicationKey | b64enc | quote }}
  ovh_application_secret: {{ .Values.ovh.applicationSecret | b64enc | quote }}
  {{- end }}
  {{- if eq .Values.provider "scaleway" }}
  scw_access_key: {{ .Values.scaleway.scwAccessKey | b64enc | quote }}
  scw_secret_key: {{ .Values.scaleway.scwSecretKey | b64enc | quote }}
  scw_default_organization_id: {{ .Values.scaleway.scwDefaultOrganizationId | b64enc | quote }}
  {{- end }}
  {{- if eq .Values.provider "vinyldns" }}
  vinyldns-access-key: {{ .Values.vinyldns.accessKey | b64enc | quote }}
  vinyldns-secret-key: {{ .Values.vinyldns.secretKey | b64enc | quote }}
  {{- end }}
{{- end }}
