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

resource "azurerm_servicebus_queue" "this" {
  name         = "{{ config.get('name', project_id ~ '-queue') }}"
  namespace_id = azurerm_servicebus_namespace.this.id

  max_delivery_count            = {{ config.get('max_delivery_count', 10) }}
  lock_duration                 = "{{ config.get('lock_duration', 'PT1M') }}"
  max_size_in_megabytes         = {{ config.get('max_size_in_megabytes', 1024) }}
  default_message_ttl           = "{{ config.get('default_message_ttl', 'P14D') }}"
  dead_lettering_on_message_expiration = {{ config.get('dead_lettering_on_message_expiration', true) | lower }}

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

  {% if config.get('requires_duplicate_detection', false) %}
  duplicate_detection_history_time_window = "{{ config.get('duplicate_detection_history_time_window', 'PT10M') }}"
  {% endif %}

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