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

resource "azurerm_subnet" "this" {
  name                 = "{{ config.get('name', project_id ~ '-subnet') }}"
  resource_group_name  = var.resource_group_name
  virtual_network_name = azurerm_virtual_network.this.name
  address_prefixes     = {{ config.get('address_prefixes', '["10.0.1.0/24"]') }}

  {% if config.get('service_endpoints') %}
  service_endpoints = {{ config.service_endpoints }}
  {% endif %}

  {% if config.get('delegation') %}
  delegation {
    name = "{{ config.delegation.get('name', 'delegation') }}"

    service_delegation {
      name    = "{{ config.delegation.service_delegation_name }}"
      actions = {{ config.delegation.get('actions', '["Microsoft.Network/virtualNetworks/subnets/action"]') }}
    }
  }
  {% endif %}

  private_endpoint_network_policies = "{{ config.get('private_endpoint_network_policies', 'Enabled') }}"
}
