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

{%- for key, value in users.items() %}
{%- if value.state == 'present' %}
nginx-auth-present-{{ key }}:
  webutil.user_exists:
    - name: {{ key }}
{%- if value.password is defined %}
    - password: {{ value.password }}
{%- endif %}
    - htpasswd_file: {{ nginx.config.dir }}/auth/htpasswd
    - require:
      - file: nginx-config-dir-auth
{%- else %}
nginx-auth-absent-{{ key }}:
  webutil.user_absent:
    - name: {{ key }}
    - htpasswd_file: {{ nginx.config.dir }}/auth/htpasswd
    - require:
      - file: nginx-config-dir-auth
{%- endif %}
{%- endfor %}