{% set config = merged_configs.get('azurerm_private_endpoint', {}) %}
{% set comments = compliance_comments.get('azurerm_private_endpoint', []) %}
# ------------------------------------------------------------------------------
# Azure Private Endpoint
# ------------------------------------------------------------------------------
{% for comment in comments %}
# {{ comment }}
{% endfor %}

resource "azurerm_private_endpoint" "this" {
  name                = "{{ config.get('name', project_id ~ '-pe') }}"
  resource_group_name = var.resource_group_name
  location            = var.region
  subnet_id           = "{{ config.get('subnet_id', '') }}"

  private_service_connection {
    name                           = "{{ config.get('connection_name', project_id ~ '-psc') }}"
    private_connection_resource_id = "{{ config.get('private_connection_resource_id', '') }}"
    subresource_names              = {{ config.get('subresource_names', '[]') }}
    is_manual_connection           = {{ config.get('is_manual_connection', false) | lower }}
  }

  {% if config.get('private_dns_zone_group') %}
  private_dns_zone_group {
    name                 = "{{ config.private_dns_zone_group.get('name', 'default') }}"
    private_dns_zone_ids = {{ config.private_dns_zone_group.private_dns_zone_ids }}
  }
  {% endif %}

  tags = {
    Name      = "{{ config.get('name', project_id ~ '-pe') }}"
    ManagedBy = "complyform"
  }
}
