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

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

  policy_settings {
    enabled                     = true
    mode                        = "{{ config.get('policy_mode', 'Prevention') }}"
    request_body_check          = {{ config.get('request_body_check', true) | lower }}
    max_request_body_size_in_kb = {{ config.get('max_request_body_size_in_kb', 128) }}
    file_upload_limit_in_mb     = {{ config.get('file_upload_limit_in_mb', 100) }}
  }

  managed_rules {
    managed_rule_set {
      type    = "OWASP"
      version = "{{ config.get('owasp_version', '3.2') }}"
    }

    {% if config.get('bot_protection_enabled', true) %}
    managed_rule_set {
      type    = "Microsoft_BotManagerRuleSet"
      version = "{{ config.get('bot_rule_set_version', '1.0') }}"
    }
    {% endif %}
  }

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