#!/usr/bin/env bash

PREFIX="/ghostv2"
REGION="ca-central-1"
WRITE="$1"

while getopts "w" opt; do
  case $opt in
    w) WRITE=true ;;
    *) echo "Usage $0 [-w]" && exit 1 ;;
  esac
done

while IFS='=' read -r key value; do
  [[ -z "$key" || "$key" =~ ^# ]] && continue

  echo "Creating parameter: $PREFIX/$key"

  if [[ "$WRITE" == "true" ]]; then
    aws ssm put-parameter \
      --name "$PREFIX/$key" \
      --value "$value" \
      --type SecureString \
      --overwrite \
      --region "$REGION" > /dev/null
  fi
done < api/.env
