{% set config = merged_configs.get('aws_athena_workgroup', {}) %}
{% set comments = compliance_comments.get('aws_athena_workgroup', []) %}
# ------------------------------------------------------------------------------
# Athena Workgroup
# ------------------------------------------------------------------------------
{% for comment in comments %}
# {{ comment }}
{% endfor %}

resource "aws_athena_workgroup" "this" {
  name        = "{{ config.get('name', project_id ~ '-workgroup') }}"
  description = "{{ config.get('description', 'Managed by ComplyForm') }}"
  state       = "{{ config.get('state', 'ENABLED') }}"

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

  configuration {
    enforce_workgroup_configuration    = {{ config.get('enforce_workgroup_configuration', true) | lower }}
    publish_cloudwatch_metrics_enabled = {{ config.get('publish_cloudwatch_metrics_enabled', true) | lower }}
    bytes_scanned_cutoff_per_query     = {{ config.get('bytes_scanned_cutoff_per_query', 'null') }}

    result_configuration {
      output_location = "{{ config.get('output_location', 's3://' ~ project_id ~ '-athena-results/') }}"

      encryption_configuration {
        encryption_option = "{{ config.get('result_encryption_option', 'SSE_KMS') }}"
        kms_key_arn       = {{ config.get('result_kms_key_arn', 'null') }}
      }
    }

    engine_version {
      selected_engine_version = "{{ config.get('engine_version', 'Athena engine version 3') }}"
    }
  }

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