Skip to content

Instantly share code, notes, and snippets.

@zepptron
Last active February 4, 2019 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zepptron/5c84853c0d3ca53874774ae71b2dbe18 to your computer and use it in GitHub Desktop.
Save zepptron/5c84853c0d3ca53874774ae71b2dbe18 to your computer and use it in GitHub Desktop.
azure get ip function => .zshrc / .bashrc
azure-ips () {
local rgp=$(az group list | jq '.[].name' | sed 's/"//g' | fzf )
local check_vm=($(az vm list -g ${rgp} | jq '.[].name' | sed 's/"//g'))
local check_vmss=($(az vmss list -g ${rgp} | jq '.[].name' | sed 's/"//g'))
local array=()
if [[ $check_vm ]]; then array+=$check_vm fi
if [[ $check_vmss ]]; then array+=($check_vmss) fi
local count=$(echo "${#array[@]}")
if [[ $count > "1" ]]; then
local get=($(echo $array | tr ' ' '\n' | fzf))
elif [[ $count == "1" ]]; then
local get=($(echo $array | tr ' ' '\n'))
else
echo "no VMs or VMSS found."
return 0
fi
if [[ " ${check_vm[@]} " =~ " ${get} " ]]; then
az vm show -g ${rgp} --name ${get} -d | jq '.privateIps'
elif [[ " ${check_vmss[@]} " =~ " ${get} " ]]; then
az vmss nic list -g ${rgp} --vmss-name ${get} | jq '.[].ipConfigurations | .[].privateIpAddress'
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment