{{- range $index, $middlewareData := .Values.middlewares.geoBlock }}
---
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
  name: {{ ternary (printf "%v-%v" $.Release.Name $middlewareData.name) $middlewareData.name $.Values.ingressClass.enabled }}
  namespace: tc-system
spec:
  plugin:
    GeoBlock:
      allowLocalRequests: {{ $middlewareData.allowLocalRequests }}
      logLocalRequests: {{ $middlewareData.logLocalRequests }}
      logAllowedRequests: {{ $middlewareData.logAllowedRequests }}
      logApiRequests: {{ $middlewareData.logApiRequests }}
      api: {{ $middlewareData.api }}
      apiTimeoutMs: {{ $middlewareData.apiTimeoutMs }}
      cacheSize: {{ $middlewareData.cacheSize }}
      forceMonthlyUpdate: {{ $middlewareData.forceMonthlyUpdate }}
      allowUnknownCountries: {{ $middlewareData.allowUnknownCountries }}
      unknownCountryApiResponse: {{ $middlewareData.unknownCountryApiResponse }}
      blackListMode: {{ $middlewareData.blackListMode }}
      {{- if not $middlewareData.countries -}}
        {{- fail "You have to define at least one country..." -}}
      {{- end }}
      countries:
        {{- range $middlewareData.countries }}
        - {{ . }}
        {{- end }}
{{- end -}}
