{% extends "common/base_resource.tf.j2" %}

{% block resources %}
{% for resource in resources %}
{{ resource_spacer() }}
resource "azurerm_storage_share" "{{ resource.name }}" {
  name                 = "{{ resource.properties.name }}"
  storage_account_name = "{{ resource.properties.storage_account_name }}"
  quota                = {{ resource.properties.quota }}
  
  {% if resource.properties.enabled_protocol is defined %}
  enabled_protocol = "{{ resource.properties.enabled_protocol }}"
  {% endif %}
  
  {% if resource.properties.access_tier is defined %}
  access_tier = "{{ resource.properties.access_tier }}"
  {% endif %}
  
  {% if resource.properties.metadata is defined %}
  metadata = {{ resource.properties.metadata | tojson }}
  {% endif %}
  
  {% if resource.properties.acl is defined %}
  {% for acl_item in resource.properties.acl %}
  acl {
    id = "{{ acl_item.id }}"
    
    {% if acl_item.access_policy is defined %}
    {% for policy in acl_item.access_policy %}
    access_policy {
      permissions = "{{ policy.permissions }}"
      
      {% if policy.start is defined %}
      start = "{{ policy.start }}"
      {% endif %}
      
      {% if policy.expiry is defined %}
      expiry = "{{ policy.expiry }}"
      {% endif %}
    }
    {% endfor %}
    {% endif %}
  }
  {% endfor %}
  {% endif %}
}

{% endfor %}
{% endblock %}
