{% set config = merged_configs.get('azurerm_log_analytics_workspace', {}) %}
{% set comments = compliance_comments.get('azurerm_log_analytics_workspace', []) %}
# ------------------------------------------------------------------------------
# Azure Log Analytics Workspace (Monitor)
# ------------------------------------------------------------------------------
{% for comment in comments %}
# {{ comment }}
{% endfor %}

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

  sku               = "{{ config.get('sku', 'PerGB2018') }}"
  retention_in_days = {{ config.get('retention_in_days', 90) }}
  daily_quota_gb    = {{ config.get('daily_quota_gb', -1) }}

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

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

{% if config.get('solutions') %}
{% for solution in config.solutions %}
resource "azurerm_log_analytics_solution" "{{ solution.name | lower | replace(' ', '_') }}" {
  solution_name         = "{{ solution.name }}"
  location              = var.region
  resource_group_name   = var.resource_group_name
  workspace_resource_id = azurerm_log_analytics_workspace.this.id
  workspace_name        = azurerm_log_analytics_workspace.this.name

  plan {
    publisher = "Microsoft"
    product   = "{{ solution.product }}"
  }
}
{% endfor %}
{% endif %}
