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

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

  public_network_enabled          = {{ config.get('public_network_enabled', false) | lower }}
  managed_virtual_network_enabled = {{ config.get('managed_virtual_network_enabled', true) | lower }}

  {% if config.get('customer_managed_key_id') %}
  customer_managed_key_id          = "{{ config.customer_managed_key_id }}"
  customer_managed_key_identity_id = "{{ config.get('customer_managed_key_identity_id', '') }}"
  {% endif %}

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

  {% if config.get('github_configuration') %}
  github_configuration {
    account_name    = "{{ config.github_configuration.account_name }}"
    repository_name = "{{ config.github_configuration.repository_name }}"
    branch_name     = "{{ config.github_configuration.get('branch_name', 'main') }}"
    root_folder     = "{{ config.github_configuration.get('root_folder', '/') }}"
    git_url         = "{{ config.github_configuration.get('git_url', 'https://github.com') }}"
  }
  {% endif %}

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