def wait_for_state(instances, exp_state)

      time = 0
      all_good = false

      loop do
        all_good = instances.all? do |i|
          state = i.elb_health[:state] 
          puts "#{i.id}: #{state}"

          exp_state == state
        end

        break if all_good || time > timeout

        sleep 1
        time += 1
      end

      # If timeout before all inservice, deregister and raise error
      unless all_good
        raise "Instances are out of service"
      end
    end
def wait_for_state(instances, exp_state)

      time = 0
      all_good = false

      loop do
        all_good = instances.all? do |i|
          state = i.elb_health[:state] 
          puts "#{i.id}: #{state}"

          exp_state == state
        end

        break if all_good || time > timeout

        sleep 1
        time += 1
      end

      # If timeout before all inservice, deregister and raise error
      unless all_good
        raise "Instances are out of service"
      end
    end
Wait for all the instances to become InService