{% set config = merged_configs.get('aws_guardduty_detector', {}) %}
{% set comments = compliance_comments.get('aws_guardduty_detector', []) %}
# ------------------------------------------------------------------------------
# GuardDuty Detector
# ------------------------------------------------------------------------------
{% for comment in comments %}
# {{ comment }}
{% endfor %}

resource "aws_guardduty_detector" "this" {
  enable = {{ config.get('enable', true) | lower }}

  finding_publishing_frequency = "{{ config.get('finding_publishing_frequency', 'FIFTEEN_MINUTES') }}"

  datasources {
    s3_logs {
      enable = {{ config.get('s3_logs_enabled', true) | lower }}
    }

    kubernetes {
      audit_logs {
        enable = {{ config.get('kubernetes_audit_logs_enabled', true) | lower }}
      }
    }

    malware_protection {
      scan_ec2_instance_with_findings {
        ebs_volumes {
          enable = {{ config.get('malware_protection_enabled', true) | lower }}
        }
      }
    }
  }

  tags = {
    Name      = "{{ project_id }}-guardduty"
    ManagedBy = "complyform"
  }
}
