|
| 1 | +#!/bin/bash |
| 2 | +printf "\n=== Managing Storage Accounts Resources in Azure ===\n" |
| 3 | +export BASEDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) |
| 4 | + |
| 5 | +azure group get -n $groupName |
| 6 | +if [ $? -ne 0 ]; then |
| 7 | + printf "\n Creating group %s in location %s \n" $groupName $location |
| 8 | + azure group create -n "$groupName" --location "$location" |
| 9 | +fi |
| 10 | + |
| 11 | +set -e |
| 12 | +accountName=`randomName $groupName` |
| 13 | +accountType="Standard_GRS" |
| 14 | + |
| 15 | +printf "\n1. Creating storage account %s in resrouce group %s with type %s in location %s \n" $accountName $groupName $accountType $location |
| 16 | +azure storage account new -g "$groupName" -n "$accountName" -t "$accountType" -l "$location" |
| 17 | + |
| 18 | +printf "\n2. Get account info of storage account %s in group %s\n" $accountName $groupName |
| 19 | +azure storage account get -g $groupName -n $accountName > $BASEDIR/$accountName.json |
| 20 | +[ $(cat $BASEDIR/$accountName.json | jq '.ResourceGroupName' --raw-output) == "$groupName" ] |
| 21 | +[ $(cat $BASEDIR/$accountName.json | jq '.StorageAccountName' --raw-output) == "$accountName" ] |
| 22 | +[ $(cat $BASEDIR/$accountName.json | jq '.AccountType' --raw-output) == "$accountType" ] |
| 23 | +[ $(cat $BASEDIR/$accountName.json | jq '.Location' --raw-output) == "$location" ] |
| 24 | +rm -f $BASEDIR/$accountName.json |
| 25 | + |
| 26 | +accountType1="Standard_RAGRS" |
| 27 | +printf "\n3. Set account type from %s to %s of storage account %s in group %s\n" $accountType $accountType1 $accountName $groupName |
| 28 | +azure storage account set -g $groupName -n $accountName -t "$accountType1" > $BASEDIR/$accountName.json |
| 29 | +[ $(cat $BASEDIR/$accountName.json | jq '.AccountType' --raw-output) == "$accountType1" ] |
| 30 | +rm -f $BASEDIR/$accountName.json |
| 31 | + |
| 32 | +printf "\n4. Get account key of storage account %s in group %s\n" $accountName $groupName |
| 33 | +azure storage account key get -g $groupName -n $accountName > $BASEDIR/$accountName.json |
| 34 | +key1=$(cat $BASEDIR/$accountName.json | jq '.key1' --raw-output) |
| 35 | +key2=$(cat $BASEDIR/$accountName.json | jq '.key2' --raw-output) |
| 36 | +[ $key1 != $key2 ] |
| 37 | +rm -f $BASEDIR/$accountName.json |
| 38 | + |
| 39 | +printf "\n5. Renew account key1 of storage account %s in group %s\n" $accountName $groupName |
| 40 | +azure storage account key new -g $groupName -n $accountName -k "key1" |
| 41 | +azure storage account key get -g $groupName -n $accountName > $BASEDIR/$accountName.json |
| 42 | +[ $(cat $BASEDIR/$accountName.json | jq '.key1' --raw-output) != $key1 ] |
| 43 | +rm -f $BASEDIR/$accountName.json |
| 44 | + |
| 45 | +printf "\n6. Renew account key2 of storage account %s in group %s\n" $accountName $groupName |
| 46 | +azure storage account key new -g $groupName -n $accountName -k "key2" |
| 47 | +azure storage account key get -g $groupName -n $accountName > $BASEDIR/$accountName.json |
| 48 | +[ $(cat $BASEDIR/$accountName.json | jq '.key2' --raw-output) != $key2 ] |
| 49 | +rm -f $BASEDIR/$accountName.json |
| 50 | + |
| 51 | +printf "\n7. Removing account %s in group %s\n" $accountName $groupName |
| 52 | +azure storage account remove -g $groupName -n $accountName |
0 commit comments