---
{%- from "haproxy/map.jinja" import haproxy with context %}

haproxy-errors-dir:
  file.directory:
    - name: {{ haproxy.config.dir }}/errors/
    - user: {{ haproxy.config.user }}
    - group: {{ haproxy.config.group }}
    - mode: "0700"

{% for errorfile in haproxy.errorfiles %}
haproxy-errors-{{ errorfile }}:
  file.managed:
    - name: {{ haproxy.config.dir }}/errors/{{ errorfile }}
    - source: salt://haproxy/errors/{{ errorfile }}
    - user: {{ haproxy.config.user }}
    - group: {{ haproxy.config.group }}
    - mode: "0600"
    - watch_in:
      - service: haproxy-service
{% endfor %}

{% for map in haproxy.config.maps %}
haproxy-maps-{{ map }}:
  file.managed:
    - name: {{ haproxy.config.dir }}/maps/{{ map }}
    - source: salt://haproxy/templates/maps/{{ map }}.j2
    - user: {{ haproxy.config.user }}
    - group: {{ haproxy.config.group }}
    - mode: "0600"
    - template: jinja
    - watch_in:
      - service: haproxy-service
{% endfor %}

{% for static in haproxy.config.static %}
haproxy-static-{{ static }}:
  file.managed:
    - name: {{ haproxy.config.dir }}/static/{{ static }}
    - source: salt://haproxy/templates/static/{{ static }}.j2
    - user: {{ haproxy.config.user }}
    - group: {{ haproxy.config.group }}
    - mode: "0600"
    - template: jinja
    - watch_in:
      - service: haproxy-service
{% endfor %}


haproxy-config-main:
  file.managed:
    - name: {{ haproxy.config.dir }}/{{ haproxy.config.configfile }}
    - source: salt://haproxy/templates/haproxy.cfg.j2
    - user: {{ haproxy.config.user }}
    - group: {{ haproxy.config.group }}
    - mode: "0600"
    - template: jinja
    - watch_in:
      - service: haproxy-service

haproxy-config-spoe:
  file.managed:
    - name: {{ haproxy.config.dir }}/spoe.cfg
    - source: salt://haproxy/templates/spoe.cfg.j2
    - user: {{ haproxy.config.user }}
    - group: {{ haproxy.config.group }}
    - mode: "0600"
    - template: jinja
    - watch_in:
      - service: haproxy-service