{% set config = merged_configs.get('aws_apigatewayv2_stage', {}) %}
{% set comments = compliance_comments.get('aws_apigatewayv2_stage', []) %}
# ------------------------------------------------------------------------------
# API Gateway v2 Stage
# ------------------------------------------------------------------------------
{% for comment in comments %}
# {{ comment }}
{% endfor %}

resource "aws_apigatewayv2_stage" "this" {
  api_id      = aws_apigatewayv2_api.this.id
  name        = "{{ config.get('name', '$default') }}"
  auto_deploy = {{ config.get('auto_deploy', true) | lower }}

  access_log_settings {
    destination_arn = {{ config.get('access_log_destination_arn', 'aws_cloudwatch_log_group.api_gw.arn') }}
  }

  default_route_settings {
    throttling_burst_limit = {{ config.get('throttling_burst_limit', 100) }}
    throttling_rate_limit  = {{ config.get('throttling_rate_limit', 50) }}
  }

  tags = {
    Name      = "{{ project_id }}-api-stage"
    ManagedBy = "complyform"
  }
}
