Skip to content

Instantly share code, notes, and snippets.

View javatarz's full-sized avatar

Karun Japhet javatarz

View GitHub Profile
#!/bin/bash
set -e
cd $MODULE_NAME
echo "init default.tfstate"
terraform init -backend-config="key=default.tfstate"
echo "select or create new workspace $WORKSPACE_NAME"
terraform workspace select $WORKSPACE_NAME || terraform workspace new $WORKSPACE_NAME
@javatarz
javatarz / plan.sh
Created August 26, 2019 13:50
script to load variables from local file
#!/bin/bash
set -e
cd $MODULE_NAME
echo "select or create new workspace $WORKSPACE_NAME"
terraform workspace select $WORKSPACE_NAME || terraform workspace new $WORKSPACE_NAME
echo "plan with var file ~/terraform_variables/$WORKSPACE_NAME/$MODULE_NAME.tfvars"
terraform plan -var-file=~/terraform_variables/$WORKSPACE_NAME/$MODULE_NAME.tfvars -out=$MODULE_NAME.tfplan -input=false
@javatarz
javatarz / apply.sh
Created August 26, 2019 13:50
script to load variables from local file
#!/bin/bash
set -e
cd $MODULE_NAME
echo "select or create new workspace $WORKSPACE_NAME"
terraform workspace select $WORKSPACE_NAME || terraform workspace new $WORKSPACE_NAME
echo "apply with var file ~/terraform_variables/$WORKSPACE_NAME/$MODULE_NAME.tfvars"
terraform apply -var-file=~/terraform_variables/$WORKSPACE_NAME/$MODULE_NAME.tfvars -auto-approve
@javatarz
javatarz / functions.sh
Last active December 13, 2019 08:40
Part of the functions.sh file
#!/bin/bash
function fetch_variables() {
workspace_name=$1
module_name=$2
echo $(cat ../config/$workspace_name/$module_name.tfvars | sed '/^$/D' | sed 's/.*/TF_VAR_& /' | tr -d '\n')
}
@javatarz
javatarz / test_variable_names.sh
Created August 26, 2019 13:48
Checks tfvars for hyphens
#!/bin/bash
function parse_and_test_properties_entries() {
prop=$1
if [[ "$prop" == "" || $prop = \#* ]]; then
continue
fi
key="$(cut -d'=' -f1 <<<"$prop")"
if [[ $key =~ "-" ]]; then
@javatarz
javatarz / functions.sh
Last active May 9, 2021 07:46
Part of the functions.sh file
function fetch_secrets() {
workspace_name=$1
module_name=$2
secret_key_for_workspace=$(eval "echo \$SECRET_KEY_$workspace_name")
echo $(openssl enc -aes-256-cbc -d -in ../config/$workspace_name/$module_name.tfsecrets.enc -pass pass:$secret_key_for_workspace | sed '/^$/D' | sed 's/.*/TF_VAR_& /' | tr -d '\n')
}
@javatarz
javatarz / encrypt.sh
Last active May 9, 2021 07:46
Encrypts files with openssl
#!/bin/bash
set -e
if [ -z "$SECRET_KEY" ]; then
echo "Set a SECRET_KEY for \"$WORKSPACE_NAME\" encryption"
exit 1
fi
function encrypt_file() {
input_file=$1
@javatarz
javatarz / decrypt.sh
Last active May 9, 2021 07:46
Decrypts files encrypted with openssl
#!/bin/bash
set -e
if [ -z "$SECRET_KEY" ]; then
echo "Set a SECRET_KEY for \"$WORKSPACE_NAME\" decryption"
exit 1
fi
function decrypt_file() {
input_file=$1
@javatarz
javatarz / test_encryption.sh
Last active May 9, 2021 07:45
Tests all files for openssl encryption
#!/bin/bash
base_dir="config"
for sub_dir in $(find $base_dir -mindepth 1 -maxdepth 1 -type d); do
workspace_name=${sub_dir#"$base_dir/"}
password_var_name="\$SECRET_KEY_$workspace_name"
secret_key_for_workspace=$(eval "echo $password_var_name")
if [ -z "$secret_key_for_workspace" ]; then
@javatarz
javatarz / plan.sh
Created August 26, 2019 13:43
apply.sh with config and secrets
#!/bin/bash
set -e
source $(dirname "$0")/functions.sh
cd $MODULE_NAME
echo "select or create new workspace $WORKSPACE_NAME"
terraform workspace select $WORKSPACE_NAME || terraform workspace new $WORKSPACE_NAME