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

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

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

  threat_intelligence_mode = "{{ config.get('threat_intelligence_mode', 'Alert') }}"

  {% if config.get('dns_proxy_enabled', false) %}
  dns {
    proxy_enabled = true
    servers       = {{ config.get('dns_servers', '[]') }}
  }
  {% endif %}

  {% if config.get('intrusion_detection_mode') %}
  intrusion_detection {
    mode = "{{ config.intrusion_detection_mode }}"
  }
  {% endif %}

  {% if config.get('tls_certificate') %}
  tls_certificate {
    key_vault_secret_id = "{{ config.tls_certificate.key_vault_secret_id }}"
    name                = "{{ config.tls_certificate.get('name', project_id ~ '-tls-cert') }}"
  }
  {% endif %}

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