MitocGroup / recink

REciNK - Rethink Continuous Integration for JavaScript Applications
https://www.npmjs.org/package/recink
Mozilla Public License 2.0
14 stars 5 forks source link

Provide support to multiple recink modules #160

Open eistrati opened 6 years ago

eistrati commented 6 years ago

Please improve below bash script to provide support for multiple recink modules (comma separated values):

#########################################################
# parse all env vars and create comma separated value   #
# which will be passed to recink as ${tf_vars} variable #
#########################################################
function parse_csv () {
  local count=0
  local csv_var=$1

  csv_var_name=$(echo ${csv_var} | cut -d '=' -f 1)
  csv_var_value=$(echo ${csv_var} | cut -d '=' -f 2 | sed "s|,| |g")

  count=0
  for element in ${csv_var_value}; do
    echo "${csv_var_name}.${count}:${element}"
    count=$(expr ${count} \+ 1)
  done | tr '\n' ' ' | sed "s|tfvar_||g;s| $||;s|=|:|g;s| |,|g"
}

tf_vars=$(env | grep tfvar_ | grep -v "," | tr '\n' ' ' | sed "s|tfvar_||g;s| $||;s|=|:|g;s| |,|g")
env | grep tfvar_
c_tf_vars2=$(env | grep tfvar_ | grep "," | wc -l)

if [ "${c_tf_vars2}" -gt "0" ]; then
  tf_vars2=$(env | grep tfvar_ | grep ",")
  for scv_var in ${tf_vars2} ; do
    tr_csv=$(parse_csv ${scv_var})
    tf_vars="${tf_vars},${tr_csv}"
  done
fi

########################################################################
# recink-terraform triggers automated terraform deployment workflow    #
# https://www.terraform.io/guides/running-terraform-in-automation.html #
########################################################################
npm install recink-terraform
ln -s ./node_modules/recink/bin/cli.js ./recink
git config --add core.longpaths true

#######################################################
# default workflow: terraform init && terraform plan  #
# terraform apply && terraform destroy are skipped    #
#######################################################
./recink run terraform \
  --include-modules="${recink_module}" \
  --custom-config="${recink_module}.terraform.plan:true" \
  --tf-vars="${tf_vars}"