{% for vnet in resources %}
resource "azurerm_virtual_network" "{{ vnet.name_sanitized }}" {
  name                = "{{ vnet.name }}"
  location            = "{{ vnet.location }}"
  resource_group_name = "{{ vnet.resource_group_name }}"
  address_space       = {{ vnet.address_space | tojson }}
  {%- if vnet.dns_servers %}
  dns_servers         = {{ vnet.dns_servers | tojson }}
  {%- endif %}
  {%- if vnet.bgp_community %}
  bgp_community       = "{{ vnet.bgp_community }}"
  {%- endif %}
  {%- if vnet.flow_timeout_in_minutes %}
  flow_timeout_in_minutes = {{ vnet.flow_timeout_in_minutes }}
  {%- endif %}

  {%- if vnet.ddos_protection_plan %}
  ddos_protection_plan {
    id     = "{{ vnet.ddos_protection_plan.id }}"
    enable = {{ vnet.ddos_protection_plan.enable | lower }}
  }
  {%- endif %}

  {%- if vnet.tags %}
  tags = {
    {%- for key, value in vnet.tags.items() %}
    {{ key }} = "{{ value }}"{{ "," if not loop.last }}
    {%- endfor %}
  }
  {%- endif %}

  lifecycle {
    prevent_destroy = true
  }
}

{%- if vnet.subnet_details %}

# Note: Subnets detected in this VNet (scan separately with 'terraback subnet scan' when implemented):
{% for subnet in vnet.subnet_details %}
# - {{ subnet.name }} ({{ subnet.address_prefix }})
{%- endfor %}
{%- endif %}
{% endfor %}