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

resource "azurerm_eventhub" "this" {
  name         = "{{ config.get('name', project_id ~ '-eh') }}"
  namespace_id = azurerm_eventhub_namespace.this.id

  partition_count   = {{ config.get('partition_count', 2) }}
  message_retention = {{ config.get('message_retention', 7) }}

  {% if config.get('capture_description') %}
  capture_description {
    enabled             = true
    encoding            = "{{ config.capture_description.get('encoding', 'Avro') }}"
    interval_in_seconds = {{ config.capture_description.get('interval_in_seconds', 300) }}
    size_limit_in_bytes = {{ config.capture_description.get('size_limit_in_bytes', 314572800) }}

    destination {
      name                = "EventHubArchive.AzureBlockBlob"
      archive_name_format = "{{ config.capture_description.get('archive_name_format', '{Namespace}/{EventHub}/{PartitionId}/{Year}/{Month}/{Day}/{Hour}/{Minute}/{Second}') }}"
      blob_container_name = "{{ config.capture_description.blob_container_name }}"
      storage_account_id  = "{{ config.capture_description.storage_account_id }}"
    }
  }
  {% endif %}
}
