# This file was generated by chef-alfresco

# General Configurations: global, timeouts
<% node['haproxy']['general_config'].each do |line| -%>
<%= line %>
<% end -%>
# Log format
<%= node['haproxy']['logformat'] %>

# Frontends

<% if node['haproxy']['frontends'] -%>
  <% node['haproxy']['frontends'].each do |frontendName,frontend| -%>
# START frontend <%= frontendName %>
frontend <%= frontendName %>
    <% if frontend['entries'] -%>
      <% frontend['entries'].each do |entry| -%>
<%= entry %>
      <% end -%>
    <% end -%>
    <% if frontend['headers'] -%>
      <% frontend['headers'].each do |header| -%>
<%= header %>
      <% end -%>
    <% end -%>
# Backend ACLs
    <% if frontend['acls'] -%>
      <% frontend['acls'].each do |backendName,acls| -%>
        <% if acls -%>
          <% acls.each do |acl| -%>
acl is_<%= backendName %> <%= acl %>
          <% end -%>
        <% end -%>
      <% end -%>
    <% end -%>
# Free formed ACLs
    <% if frontend['acl_lines'] -%>
      <% frontend['acl_lines'].each do |acl| -%>
acl <%= acl %>
      <% end -%>
    <% end -%>
# Other Configurations
    <% if frontend['other_config'] -%>
      <% frontend['other_config'].each do |other_config| -%>
<%= other_config %>
      <% end -%>
    <% end -%>
# Redirects
    <% if frontend['redirects'] -%>
      <% frontend['redirects'].each do |redirect| -%>
<%= redirect %>
      <% end -%>
    <% end -%>
# Use backends
    <% if frontend['acls'] -%>
      <% frontend['acls'].each do |backendName,acls| -%>
use_backend <%= backendName %> if is_<%= backendName %>
      <% end -%>
    <% end -%>
# Default Backend
default_backend <%= node['haproxy']['default_backend'] %>
# END frontend <%= frontendName %>

  <% end -%>
<% end -%>

# Backends

<% if @haproxy_backends -%>
  <% @haproxy_backends.each do |roleName,role| -%>
# START <%= roleName %> backend
backend <%= roleName %>
    <% if role['entries'] -%>
      <% role['entries'].each do |entry| -%>
<%= entry %>
      <% end -%>
    <% end -%>
    <% if role['balanced'] -%>
balance leastconn
cookie JSESSIONID prefix
    <% end -%>
    <% if role['secure_entries'] -%>
      <% role['secure_entries'].each do |secure_entry| -%>
<%= secure_entry %>
      <% end -%>
    <% end -%>

    <% if role['ordered_az'] -%>
      <% role['ordered_az'].each do |az| -%>
        <% az['id'].each do |instanceName,instance| -%>
# Instance <%= instanceName %>, az <%= instance['az'] %>
server <%= instanceName %> <%= instance['ip'] %>:<%= role['port'] %> <%= instance['options'] %>
        <% end -%>
      <% end -%>
    <% end -%>
# END <%= roleName %> backend

  <% end -%>
<% end -%>
