Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide support to multiple recink modules #160

Open
eistrati opened this issue Mar 16, 2018 · 0 comments
Open

Provide support to multiple recink modules #160

eistrati opened this issue Mar 16, 2018 · 0 comments
Assignees

Comments

@eistrati
Copy link
Contributor

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}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants