#!/usr/bin/env bash
set -euo pipefail
# When changing this script, remember to modify the corresponding github action
region=${1}
env=${2}
clusterName=${3}
roleArn=${4}
logicalRegionName=${5}

ROOT=$(cd $(dirname ${BASH_SOURCE[0]}) && pwd)
deploy_dir="${ROOT}/envs/${env}-${logicalRegionName}"
variant_dir="${ROOT}/variants"

if [ -e ${deploy_dir} ]; then
  echo "New region deploy directory already exist"
  exit 1
fi

mkdir -p "${deploy_dir}"
echo "Prepare manifest files"
cp "${variant_dir}/values.yaml" "${deploy_dir}/"

sed -i "s|<REGION>|${region}|g" "${deploy_dir}/values.yaml"
sed -i "s|<CLUSTER-NAME>|${clusterName}|g" "${deploy_dir}/values.yaml"
sed -i "s|<ROLE-ARN>|${roleArn}|g" "${deploy_dir}/values.yaml"