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

  build_config {
    runtime     = "{{ config.get('runtime', 'python312') }}"
    entry_point = "{{ config.get('entry_point', 'main') }}"

    source {
      storage_source {
        bucket = "{{ config.get('source_bucket', '${var.project_id}-functions') }}"
        object = "{{ config.get('source_object', 'function-source.zip') }}"
      }
    }
  }

  service_config {
    max_instance_count    = {{ config.get('max_instance_count', 10) }}
    min_instance_count    = {{ config.get('min_instance_count', 0) }}
    available_memory      = "{{ config.get('available_memory', '256M') }}"
    timeout_seconds       = {{ config.get('timeout_seconds', 60) }}
    ingress_settings      = "{{ config.get('ingress_settings', 'ALLOW_INTERNAL_ONLY') }}"
    service_account_email = "{{ config.get('service_account_email', '') }}"
  }
}
