# Load the helper function and call it with arguments tailored for the testing
# grid.  It will make the morph configuration for us.  We share this function
# with the production grid and have one fewer possible point of divergence.
import ../../lib/make-grid.nix {
  name = "Testing";
  config = ./config.json;
  nodes = cfg:
  let
    sshUsers = import ./secrets/users.nix;

    # Get absolute vpn key directory path, as a string:
    monitoringvpnKeyDir = toString ./. + "/${cfg.monitoringvpnKeyDir}";

    # TBD: derive these automatically:
    hostsMap = {
      "172.23.23.1"  = [ "monitoring" "monitoring.monitoringvpn" ];
      "172.23.23.11" = [ "payments"   "payments.monitoringvpn"   ];
      "172.23.23.12" = [ "storage001" "storage001.monitoringvpn" ];
    };
    vpnClientIPs = [ "172.23.23.11" "172.23.23.12" ];
    nodeExporterTargets = [ "monitoring" "payments" "storage001" ];

  in {
    "payments" = import ../../lib/make-issuer.nix (cfg // {
      publicIPv4 = "18.194.183.13";
      monitoringvpnIPv4 = "172.23.23.11";
      inherit monitoringvpnKeyDir;
      inherit sshUsers;
      hardware = ../../lib/issuer-aws.nix;
      stateVersion = "19.03";
    });

    "storage001" = import ../../lib/make-testing.nix (cfg // {
      publicIPv4 = "3.120.26.190";
      monitoringvpnIPv4 = "172.23.23.12";
      inherit monitoringvpnKeyDir;
      inherit sshUsers;
      hardware = ./testing001-hardware.nix;
      stateVersion = "19.03";
    });

    "monitoring" = import ../../lib/make-monitoring.nix (cfg // {
      publicIPv4 = "18.156.171.217";
      monitoringvpnIPv4 = "172.23.23.1";
      inherit monitoringvpnKeyDir;
      inherit vpnClientIPs;
      inherit hostsMap;
      inherit nodeExporterTargets;
      hardware = ../../lib/issuer-aws.nix;
      stateVersion = "19.09";
      inherit sshUsers;
    });
  };
}