heat_template_version: rocky

description: >
  {{network.name}} network definition (automatically generated).

parameters:
  # the defaults here work for static IP assignment (IPAM) only
  {{network.name}}NetCidr:
{%- if network.ipv6 or ipv6_override %}
    default: "{{network.ipv6_subnet|default(network.ip_subnet|default(""))}}"
{%- else %}
    default: "{{network.ip_subnet|default("")}}"
{%- endif %}
    description: Cidr for the {{network.name_lower}} network.
    type: string
  {{network.name}}NetValueSpecs:
    default: {'provider:physical_network': '{{network.name_lower}}', 'provider:network_type': 'flat'}
    description: Value specs for the {{network.name_lower}} network.
    type: json
{%- if not ":" in network.ip_subnet and not network.ipv6 and not ipv6_override %}
  {{network.name}}NetEnableDHCP:
    default: false
    description: Whether to enable DHCP on the associated subnet (IPv4 only).
    type: boolean
{%- endif %}
  {{network.name}}NetAdminStateUp:
    default: false
    description: The admin state of the network.
    type: boolean
  {{network.name}}NetShared:
    default: false
    description: Whether this network is shared across all tenants.
    type: boolean
  {{network.name}}NetName:
    default: {{network.name_lower}}
    description: The name of the {{network.name_lower}} network.
    type: string
  {{network.name}}SubnetName:
    default: {{network.name_lower}}_subnet
    description: The name of the {{network.name_lower}} subnet in Neutron.
    type: string
  {{network.name}}AllocationPools:
{%- if ":" in network.ip_subnet or network.ipv6 or ipv6_override %}
    default: {{network.ipv6_allocation_pools|default(network.allocation_pools|default([]))}}
{%- else %}
    default: {{network.allocation_pools|default([])}}
{%- endif %}
    description: Ip allocation pool range for the {{network.name_lower}} network.
    type: json
{%- if ":" in network.ip_subnet or network.ipv6 or ipv6_override %}
  IPv6AddressMode:
    default: dhcpv6-stateful
    description: Neutron subnet IPv6 address mode
    type: string
  IPv6RAMode:
    default: dhcpv6-stateful
    description: Neutron subnet IPv6 router advertisement mode
    type: string
{%- endif %}
  {{network.name}}InterfaceDefaultRoute:
{%- if network.ipv6 or ipv6_override %}
    default: "{{network.gateway_ipv6|default(network.gateway_ip|default(''))}}"
{%- else %}
    default: "{{network.gateway_ip|default('')}}"
{%- endif %}
    description: default route for the {{network.name_lower}} network
    type: string
{%- if network.vlan %}
  {{network.name}}NetworkVlanID:
    default: {{network.vlan|default('')}}
    description: Vlan ID for the {{network.name_lower}} network traffic.
    type: number
{%- endif %}
  {{network.name}}Routes:
    default: {{network.routes|default([])}}
    description: >
      Routes for the {{network.name_lower}} network traffic.
      JSON route e.g. [{'destination':'10.0.0.0/16', 'nexthop':'10.0.0.1'}]
      Routes are added to the host_routes property on the subnet in neutron
      when the network and subnet is created.
    type: json

resources:
  {{network.name}}Network:
    type: OS::Neutron::Net
    properties:
      admin_state_up: {get_param: {{network.name}}NetAdminStateUp}
      name: {get_param: {{network.name}}NetName}
      shared: {get_param: {{network.name}}NetShared}
      value_specs: {get_param: {{network.name}}NetValueSpecs}

  {{network.name}}Subnet:
    type: OS::Neutron::Subnet
    properties:
{%- if ":" in network.ip_subnet or network.ipv6 or ipv6_override %}
      ip_version: 6
      ipv6_address_mode: {get_param: IPv6AddressMode}
      ipv6_ra_mode: {get_param: IPv6RAMode}
{%- else %}
      enable_dhcp: {get_param: {{network.name}}NetEnableDHCP}
{%- endif %}
      cidr: {get_param: {{network.name}}NetCidr}
      name: {get_param: {{network.name}}SubnetName}
      network: {get_resource: {{network.name}}Network}
      allocation_pools: {get_param: {{network.name}}AllocationPools}
      gateway_ip: {get_param: {{network.name}}InterfaceDefaultRoute}
      host_routes: {get_param: {{network.name}}Routes}

outputs:
  OS::stack_id:
    description: {{network.name_lower}} network
    value: {get_resource: {{network.name}}Network}
  subnet_cidr:
    value: {get_attr: [{{network.name}}Subnet, cidr]}
