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

resource "azurerm_container_registry" "this" {
  name                = "{{ config.get('name', project_id | replace('-', '') ~ 'acr') }}"
  resource_group_name = var.resource_group_name
  location            = var.region
  sku                 = "{{ config.get('sku', 'Premium') }}"

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

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

  quarantine_policy_enabled = {{ config.get('quarantine_policy_enabled', true) | lower }}

  retention_policy_in_days = {{ config.get('retention_policy_in_days', 30) }}
  trust_policy_enabled     = {{ config.get('trust_policy_enabled', true) | lower }}

  {% if config.get('georeplications') %}
  {% for geo in config.georeplications %}
  georeplications {
    location                = "{{ geo.location }}"
    zone_redundancy_enabled = {{ geo.get('zone_redundancy_enabled', true) | lower }}
  }
  {% endfor %}
  {% endif %}

  {% if config.get('encryption_key_vault_key_id') %}
  encryption {
    key_vault_key_id   = "{{ config.encryption_key_vault_key_id }}"
    identity_client_id = "{{ config.get('encryption_identity_client_id', '') }}"
  }
  {% endif %}

  identity {
    type = "{{ config.get('identity_type', 'SystemAssigned') }}"
  }

  {% if config.get('network_rule_set') %}
  network_rule_set {
    default_action = "{{ config.network_rule_set.get('default_action', 'Deny') }}"
  }
  {% endif %}

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