---
{%- from "postfix/map.jinja" import postfix with context %}
postfix-main-cf:
  file.managed:
    - name: {{ postfix.base_dir }}/main.cf
    - source: salt://postfix/templates/main.cf.j2
    - user: root
    - group: root
    - mode: 644
    - template: jinja
    - watch_in:
      - service: postfix-service

postfix-master-cf:
  file.managed:
    - name: {{ postfix.base_dir }}/master.cf
    - source: salt://postfix/templates/master.cf.j2
    - user: root
    - group: root
    - mode: 644
    - template: jinja
    - watch_in:
      - service: postfix-service

{%- if postfix.db == 'pgsql' %}
postfix-pgsql-dir:
  file.directory:
    - name: {{ postfix.base_dir }}/pgsql
    - user: root
    - group: root

{%- for key, value in postfix.config.pgsql.files.items() %}
postfix-pgsql-{{ key }}:
  file.managed:
    - name: {{ postfix.base_dir }}/pgsql/{{ key }}.cf
    - source: salt://postfix/templates/pgsql.cf.j2
    - user: root
    - group: root
    - mode: 644
    - template: jinja
    - context:
        config: {{ postfix.config.pgsql.config }}
        query: {{ value.query }}
    - watch_in:
      - service: postfix-service
{% endfor %}
{%- endif %}