Created
July 30, 2019 16:19
-
-
Save asdkant/3175407f3478851954e11356a9e9a09d to your computer and use it in GitHub Desktop.
If you have a gazillion SPNs for azure CLI...
This file contains hidden or 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
#!/bin/bash | |
# az-spn | |
tenant='tenant id' # in my use case I have a single tenant | |
declare -A dic | |
dic['joes dev sub']='subscription name or id' | |
dic['joes dev id']='SPN ID' | |
dic['joes dev pass']='SPN password' | |
dic['joes prod sub']='subscription name or id' | |
dic['joes prod id']='SPN ID' | |
dic['joes prod pass']='SPN password' | |
dic['anotercorp dev sub']='subscription name or id' | |
dic['anotercorp dev id']='SPN ID' | |
dic['anotercorp dev pass']='SPN password' | |
dic['anotercorp prod sub']='subscription name or id' | |
dic['anotercorp prod id']='SPN ID' | |
dic['anotercorp prod pass']='SPN password' | |
action=$1 | |
customer=$2 | |
stage=$3 | |
case $action in | |
login ) | |
az login --service-principal -t $tenant -u "${dic[$customer\ $stage\ id]}" -p "${dic[$customer\ $stage\ pass]}" | |
;; | |
set ) | |
az account set -s "${dic[$customer\ $stage\ sub]}" | |
az account list | |
;; | |
logout ) | |
az account set -s "${dic[$customer\ $stage\ sub]}" | |
az logout | |
;; | |
help ) | |
echo 'usage:' $0 '{account name} {dev|prod} {login|set|logout}' | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment