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

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

  sku      = "{{ config.get('sku', 'Standard') }}"
  capacity = {{ config.get('capacity', 1) }}

  minimum_tls_version = "{{ config.get('minimum_tls_version', '1.2') }}"

  public_network_access_enabled = {{ config.get('public_network_access_enabled', false) | lower }}

  local_authentication_enabled = {{ config.get('local_authentication_enabled', false) | lower }}

  auto_inflate_enabled     = {{ config.get('auto_inflate_enabled', true) | lower }}
  maximum_throughput_units = {{ config.get('maximum_throughput_units', 20) }}

  identity {
    type = "{{ config.get('identity_type', 'SystemAssigned') }}"
  }

  {% if config.get('network_rulesets') %}
  network_rulesets {
    default_action                 = "{{ config.network_rulesets.get('default_action', 'Deny') }}"
    trusted_service_access_enabled = {{ config.network_rulesets.get('trusted_service_access_enabled', true) | lower }}
    public_network_access_enabled  = false
  }
  {% endif %}

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