{% extends "common/base_resource.tf.j2" %}
{% from "common/base_resource.tf.j2" import render_common_tags %}
{% block resources %}
{% for vnet in resources %}
# Import existing Virtual Network: {{ vnet.name }}
import {
  to = azurerm_virtual_network.{{ vnet.name_sanitized }}
  id = "{{ vnet.id }}"
}

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
  }
}

{% endfor %}
{% endblock %}
