scaleway-cli icon indicating copy to clipboard operation
scaleway-cli copied to clipboard

Add documentation about adding instances automatically from a tag in a load balancer backend

Open remyleone opened this issue 5 years ago • 2 comments
trafficstars

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

How I imagine scw could expose this functionality

References

remyleone avatar Nov 16 '20 10:11 remyleone

Here is a small script to replace backend ip by any instance by tag

#!/bin/bash

set -e

LB_NAME=$1
TAG=$2

cmd_f_help () {
  cat << _HELP_
Add Instance private IP to LB of your choice

  Usage :
    First parameter: Name of the load balancer
    Second parameter: Tag of your VM
_HELP_
}

if [ $# -lt 2 ]
then
    cmd_f_help
    exit 1
fi

LB_ID=$(scw lb lb list name="${LB_NAME}" -o template="{{ .ID }}")
LB_BACKEND=$(scw lb backend list lb-id="${LB_ID}" -o template="{{ .ID }}")
INSTANCE_IP=$(scw instance server list tags.0="${TAG}"  -o template="{{ .PrivateIP }}")

i=0
IPS=""
for variable in $INSTANCE_IP
do
    IPS="${IPS} server-ip.$i=$variable"
    ((i=i+1))
done

for BACKEND in $LB_BACKEND
do
    scw lb backend set-servers $BACKEND $IPS
done

willoucom avatar Nov 16 '20 10:11 willoucom

This could also be a feature of a backend spécific command

remyleone avatar Nov 16 '20 10:11 remyleone