{% set config = merged_configs.get('aws_cloudwatch_metric_alarm', {}) %}
{% set comments = compliance_comments.get('aws_cloudwatch_metric_alarm', []) %}
# ------------------------------------------------------------------------------
# CloudWatch Metric Alarm
# ------------------------------------------------------------------------------
{% for comment in comments %}
# {{ comment }}
{% endfor %}

resource "aws_cloudwatch_metric_alarm" "this" {
  alarm_name          = "{{ config.get('alarm_name', project_id ~ '-alarm') }}"
  alarm_description   = "{{ config.get('alarm_description', 'Managed by ComplyForm') }}"
  comparison_operator = "{{ config.get('comparison_operator', 'GreaterThanOrEqualToThreshold') }}"
  evaluation_periods  = {{ config.get('evaluation_periods', 1) }}
  metric_name         = "{{ config.get('metric_name', 'CPUUtilization') }}"
  namespace           = "{{ config.get('namespace', 'AWS/EC2') }}"
  period              = {{ config.get('period', 300) }}
  statistic           = "{{ config.get('statistic', 'Average') }}"
  threshold           = {{ config.get('threshold', 80) }}
  treat_missing_data  = "{{ config.get('treat_missing_data', 'missing') }}"

  alarm_actions = {{ config.get('alarm_actions', '[]') }}
  ok_actions    = {{ config.get('ok_actions', '[]') }}

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