{% set config = merged_configs.get('google_compute_subnetwork', {}) %}
# Compliance: {{ compliance_comments.get('google_compute_subnetwork', []) | join(', ') }}
resource "google_compute_subnetwork" "main" {
  name                     = "{{ config.get('name', '${var.project_id}-subnet') }}"
  project                  = var.project_id
  region                   = var.region
  network                  = google_compute_network.main.id
  ip_cidr_range            = "{{ config.get('ip_cidr_range', '10.0.0.0/20') }}"
  private_ip_google_access = {{ config.get('private_ip_google_access', true) | lower }}

  log_config {
    aggregation_interval = "{{ config.get('log_aggregation_interval', 'INTERVAL_5_SEC') }}"
    flow_sampling        = {{ config.get('flow_sampling', 0.5) }}
    metadata             = "{{ config.get('log_metadata', 'INCLUDE_ALL_METADATA') }}"
  }
{% if config.get('secondary_ip_ranges') %}

  {% for range in config.get('secondary_ip_ranges', []) %}
  secondary_ip_range {
    range_name    = "{{ range.name }}"
    ip_cidr_range = "{{ range.cidr }}"
  }
  {% endfor %}
{% endif %}
}
