{% extends "aws/base_resource.tf.j2" %}
{% block resources %}
{% for ap in resources %}
{{ resource_spacer() }}
resource "aws_efs_access_point" "{{ ap.name_sanitized }}" {
  file_system_id = "{{ ap.FileSystemId }}"

  {% if ap.get('posix_user_formatted') %}
  posix_user {
    uid = {{ ap.posix_user_formatted.uid }}
    gid = {{ ap.posix_user_formatted.gid }}
    {% if ap.posix_user_formatted.get('secondary_gids') %}
    secondary_gids = [
      {% for gid in ap.posix_user_formatted.secondary_gids %}
      {{ gid }}{{ "," if not loop.last }}
      {% endfor %}
    ]
    {%  endif %}
  }
  {%  endif %}

  root_directory {
    path = "{{ ap.root_directory_formatted.path }}"

    {% if ap.root_directory_formatted.get('creation_info') %}
    creation_info {
      owner_uid   = {{ ap.root_directory_formatted.creation_info.owner_uid }}
      owner_gid   = {{ ap.root_directory_formatted.creation_info.owner_gid }}
      permissions = "{{ ap.root_directory_formatted.creation_info.permissions }}"
    }
    {%  endif %}
  }

  {{ render_common_tags(ap, indent=2) }}
}

{% endfor %}
{% endblock %}
