Back (Current repo: terraform-mariadb-replica-homelab)

A terraform homelab with mariadb and maxscale for my own understanding and learning.
To clone this repository:
git clone https://git.viktor1993.net/terraform-mariadb-replica-homelab.git
Log | Download | Files | Refs | README

service_discovery.awk (656B)


#!/bin/awk -f

BEGIN{
    FS="│";
    max_id = 0;
    if (port == ""){port = 3313;}
    if (number == ""){number = 2;}
}
{
    if($2 ~ /server[0-9]+/){
        for (i=1; i<=NF; i++) {
            gsub(/^[ \t]+|[ \t]+$/, "", $i);
        }
        match($2, /([0-9]+)$/, current_id);
        if (current_id[1] > max_id) {
             max_id = current_id[1];
        }
    }
}
END{
    boundary = max_id+1;
    print boundary;
    print "locals {";
    print "  servers = {";
    for(i = boundary; i < boundary+number; i++) {
        port++;
        print "    \"server"i"\" = { port = "port", server_id = "i" },";
    }
    print "  }"
    print "}";
}