{% set config = merged_configs.get('aws_glue_catalog_database', {}) %}
{% set comments = compliance_comments.get('aws_glue_catalog_database', []) %}
# ------------------------------------------------------------------------------
# Glue Catalog Database
# ------------------------------------------------------------------------------
{% for comment in comments %}
# {{ comment }}
{% endfor %}

resource "aws_glue_catalog_database" "this" {
  name        = "{{ config.get('name', project_id | replace('-', '_') ~ '_db') }}"
  description = "{{ config.get('description', 'Managed by ComplyForm') }}"

  {% if config.get('location_uri') %}
  location_uri = "{{ config.location_uri }}"
  {% endif %}

  {% if config.get('create_table_default_permissions') %}
  create_table_default_permission {
    permissions = {{ config.get('default_permissions', '["ALL"]') }}

    principal {
      data_lake_principal_identifier = "{{ config.get('principal_identifier', 'IAM_ALLOWED_PRINCIPALS') }}"
    }
  }
  {% endif %}
}
