{% set config = merged_configs.get('google_cloud_run_v2_service', {}) %}
# Compliance: {{ compliance_comments.get('google_cloud_run_v2_service', []) | join(', ') }}
resource "google_cloud_run_v2_service" "main" {
  name     = "{{ config.get('name', '${var.project_id}-service') }}"
  project  = var.project_id
  location = var.region
  ingress  = "{{ config.get('ingress', 'INGRESS_TRAFFIC_INTERNAL_LOAD_BALANCER') }}"

  template {
    scaling {
      min_instance_count = {{ config.get('min_instance_count', 0) }}
      max_instance_count = {{ config.get('max_instance_count', 10) }}
    }

    containers {
      image = "{{ config.get('image', 'us-docker.pkg.dev/${var.project_id}/repo/app:latest') }}"

      resources {
        limits = {
          cpu    = "{{ config.get('cpu_limit', '1') }}"
          memory = "{{ config.get('memory_limit', '512Mi') }}"
        }
        cpu_idle          = {{ config.get('cpu_idle', true) | lower }}
        startup_cpu_boost = {{ config.get('startup_cpu_boost', false) | lower }}
      }
    }

    service_account = "{{ config.get('service_account', '') }}"
  }
}
