-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
71 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,7 +168,7 @@ cython_debug/ | |
|
||
|
||
#terrafrom | ||
*.tfvars | ||
*.tfvars* | ||
.terraform* | ||
*.tfstate* | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#! /bin/bash -e | ||
|
||
|
||
TERRAFORM_DIR=terraform | ||
VAR_FILE="vars2.tfvars.json" | ||
|
||
function terraform_init() { | ||
|
||
terraform init | ||
KEY_ID=$(cat ~/.aws/credentials | awk 'BEGIN{FS=" "}/key_id/{print $3}') | ||
SECRET_KEY=$(cat ~/.aws/credentials | awk 'BEGIN{FS=" "}/secret_access/{print $3}') | ||
echo "{ \"access_key\": \"${KEY_ID}\", \"secret_key\": \"${SECRET_KEY}\", \"clients\": []}" > ${TERRAFORM_DIR}/${VAR_FILE} | ||
cd ${TERRAFORM_DIR} | ||
terraform apply --var-file=${VAR_FILE} | ||
cd .. | ||
} | ||
function terrafrom_apply(){ | ||
cd ${TERRAFORM_DIR} | ||
terraform apply ${VAR_FILE} | ||
cd .. | ||
} | ||
|
||
function add_new_clients(){ | ||
for client in "$@" | ||
do | ||
cat ${TERRAFORM_DIR}/${VAR_FILE}| jq '.clients[.clients| length ] += "'$client'" ' > ${TERRAFORM_DIR}/tmp_vars.tfvars.json | ||
mv ${TERRAFORM_DIR}/tmp_vars.tfvars.json ${TERRAFORM_DIR}/${VAR_FILE} | ||
done | ||
} | ||
|
||
function remove_clients(){ | ||
for client in "$@" | ||
do | ||
cat ${TERRAFORM_DIR}/${VAR_FILE}| jq '.clients[.clients| length ] += "'$client'" ' > ${TERRAFORM_DIR}/tmp_vars.tfvars.json | ||
mv ${TERRAFORM_DIR}/tmp_vars.tfvars.json ${TERRAFORM_DIR}/${VAR_FILE} | ||
done | ||
} | ||
|
||
|
||
|
||
function list_clients(){ | ||
aws iam list-users --output json | jq '.Users[] | select(.Path | contains("/certClient/"))| .UserName' | ||
} | ||
|
||
function usage(){ | ||
echo "admin [flag] [values]:" | ||
echo " -i : terraform init/apply" | ||
echo " -d : terraform destroy" | ||
echo " -n <client1, client2,...> : add new clients" | ||
echo " -r <client1, client2,...> : remove clients" | ||
echo " -l : list current clients" | ||
} | ||
|
||
while getopts ":inrl:" arg; do | ||
case "${arg}" in | ||
i) | ||
terraform_init | ||
;; | ||
n) | ||
shift 1 | ||
add_new_client "$@" | ||
;; | ||
*) | ||
echo "unknow option: ${arg}" | ||
echo "usage" | ||
usage | ||
;; | ||
esac | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters