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

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

  capacity = {{ config.get('capacity', 1) }}
  family   = "{{ config.get('family', 'P') }}"
  sku_name = "{{ config.get('sku_name', 'Premium') }}"

  # TLS
  minimum_tls_version = "{{ config.get('minimum_tls_version', '1.2') }}"

  # Disable non-SSL port
  enable_non_ssl_port = {{ config.get('enable_non_ssl_port', false) | lower }}

  # Network
  public_network_access_enabled = {{ config.get('public_network_access_enabled', false) | lower }}
  {% if config.get('subnet_id') %}
  subnet_id = "{{ config.subnet_id }}"
  {% endif %}

  redis_configuration {
    {% if config.get('maxmemory_policy') %}
    maxmemory_policy = "{{ config.maxmemory_policy }}"
    {% endif %}
    aof_backup_enabled = {{ config.get('aof_backup_enabled', false) | lower }}
  }

  {% if config.get('patch_schedule_day') %}
  patch_schedule {
    day_of_week    = "{{ config.patch_schedule_day }}"
    start_hour_utc = {{ config.get('patch_schedule_hour', 2) }}
  }
  {% endif %}

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