{% set config = merged_configs.get('aws_rds_cluster_instance', {}) %}
{% set comments = compliance_comments.get('aws_rds_cluster_instance', []) %}
# ------------------------------------------------------------------------------
# Aurora RDS Cluster Instance
# ------------------------------------------------------------------------------
{% for comment in comments %}
# {{ comment }}
{% endfor %}

resource "aws_rds_cluster_instance" "this" {
  count = {{ config.get('instance_count', 2) }}

  identifier         = "{{ config.get('cluster_identifier', project_id ~ '-aurora') }}-${count.index}"
  cluster_identifier = aws_rds_cluster.this.id
  instance_class     = "{{ config.get('instance_class', 'db.r6g.large') }}"
  engine             = aws_rds_cluster.this.engine
  engine_version     = aws_rds_cluster.this.engine_version

  auto_minor_version_upgrade = {{ config.get('auto_minor_version_upgrade', true) | lower }}

  performance_insights_enabled = {{ config.get('performance_insights_enabled', true) | lower }}
  monitoring_interval          = {{ config.get('monitoring_interval', 60) }}
  monitoring_role_arn          = {{ config.get('monitoring_role_arn', 'null') }}

  tags = {
    Name      = "{{ config.get('cluster_identifier', project_id ~ '-aurora') }}-${count.index}"
    ManagedBy = "complyform"
  }
}
