openstackheatopenstack-nova

Assigning a Floating IP to a Load Balancer in a heat template


Does anyone know how to associate a floating IP address with a load balancer in a heat template? I can create a load balancer on an instance (or a bunch of instances, but starting small) in heat; and can associate a floating IP address to the load balancer in Horizon, but I can't figure out how to do it through heat.


Solution

  • I just had to find the answer to this question myself.

    It turns out that the vip attribute of an OS::Neutron::Pool resource contains a few more keys than are documented here. In particular, the vip attribute contains a port_id, which is the address of the Neutron port associated with this pool.

    Since we have a Neutron port id, we can use that to associate a floating ip address like this:

    type: "OS::Neutron::Pool"
      properties:
        protocol: HTTP
        monitors:
          - {get_resource: monitor}
        subnet_id: {get_resource: fixed_subnet}
        lb_method: ROUND_ROBIN
        vip:
          protocol_port: 80
    
    lb_floating:
      type: "OS::Neutron::FloatingIP"
      properties:
        floating_network_id:
          get_param: external_network_id
        port_id:
          get_attr: [pool, vip, port_id]
    

    That get_attr call is getting the port_id attribute of the vip attribute of the pool resource.