Ask the user to select the Azure cloud under which he runs the Azure CLI:
login_azure()
{
no_cloud=true
while $no_cloud; do
echo 'Select your cloud:'
az cloud list --output table
read -p 'Enter the name:' cloudName
az cloud set --name $cloudName && no_cloud=false
done
az account show || az login
echo 'To logout, please press `Ctrl + C` and type: `az logout`.'
}
Ask the user to select the subscription under which he runs the Azure CLI:
select_subscription()
{
no_cloud=true
subscriptionId=""
while $no_cloud; do
az account list
read -p 'Enter the subscription `id` (Example: aaaaaaa-bbbb-cccc-dddd-eeeeeeeeee):' subscriptionId
az account set --subscription $subscriptionId && no_cloud=false
done
}
Get the current tenant id:
tenantId=$(az account show --output tsv | awk '{print $8}')
Get the current tenant domain:
aadDomain=$(az ad signed-in-user show --query 'userPrincipalName' | cut -d '@' -f 2 | sed 's/\"//')
Create a resource if it not exist. For example, to create a resource group:
rsgName="MyNewResourcesGroup"
az group list --output tsv | grep $rsgName -q || az group create -l $regionName -n $rsgName && sleep 10
Create application insights and get the instrument key:
applicationInsightsName="MyNewAppInsights"
# Install the extension
az extension add -n application-insights
# Create
az monitor app-insights component show --output table | grep $applicationInsightsName -q || az monitor app-insights component create -a $applicationInsightsName -l $regionName --kind web -g $rsgName --application-type web
# Get key
aiInsKey=$(az monitor app-insights component show -a $applicationInsightsName -g $rsgName -o tsv | awk '{print $10}')
Get SQL Server database connection string:
connectionString=$(az sql db show-connection-string --client ado.net --name $sqlDatabaseName --output tsv)
Get Azure SignalR connection string:
signalRConnectionString=$(az signalr key list --name $signalRServiceName -g $rsgName --query primaryConnectionString -o tsv)
Get the Azure Storage Account connection string:
storageConnectionString=$(az storage account show-connection-string -n $storageAccountName -g $rsgName --output tsv)
Get the Azure App Service access URL:
appserviceDomain=$(az webapp show -n $webAppName -g $rsgName --output tsv | awk '{print $9}')
appserviceUrl=$(echo https://$appserviceDomain)
Set environment variable to function app:
az functionapp config appsettings set -g $rsgName -n $liveServiceFunctionName --settings InputQueueName="hmedia-live-input-queue"
Set environment variable to Azure app service:
az webapp config appsettings set -g $rsgName -n $webAppName --output none --settings something:something="$somevar"
Comments (0)
No comments yet. Be the first to leave one!