This repository has been archived by the owner on Nov 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
/
deploy_request_reporter_function.sh
94 lines (83 loc) · 4.17 KB
/
deploy_request_reporter_function.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/bash
source ./InfrastructureDeployment/setup_env.sh
if "$DEPLOY_REQUEST_REPORTER_FUNCTION_APP" = "true"
then
echo "Creating the request reporter Azure Function App."
az functionapp create --name $REQUEST_REPORTER_FUNCTION_APP_NAME --storage-account $FUNCTION_STORAGE_NAME --resource-group $INFRASTRUCTURE_RESOURCE_GROUP_NAME --plan $FUNCTION_APP_NAME-plan --deployment-container-image-name $REQUEST_REPORTER_IMAGE --app-insights $APP_INSIGHTS_RESOURCE_NAME
if [ $? -ne 0 ]
then
echo "Could not create the $REQUEST_REPORTER_FUNCTION_APP_NAME request reporter Azure Function App."
echo "deploy_request_reporter_function.sh failed"
exit $?
fi
storageConnectionString=$(az storage account show-connection-string --resource-group $INFRASTRUCTURE_RESOURCE_GROUP_NAME --name $FUNCTION_STORAGE_NAME --query connectionString --output tsv)
if [ $? -ne 0 ]
then
echo "Could not get the $FUNCTION_STORAGE_NAME storage connection string."
echo "deploy_request_reporter_function.sh failed"
exit $?
fi
az functionapp config appsettings set --name $REQUEST_REPORTER_FUNCTION_APP_NAME --resource-group $INFRASTRUCTURE_RESOURCE_GROUP_NAME --settings AzureWebJobsStorage=${storageConnectionString}
if [ $? -ne 0 ]
then
echo "Could not set $REQUEST_REPORTER_FUNCTION_APP_NAME application settings."
echo "deploy_request_reporter_function.sh failed"
exit $?
fi
# Get Event Grid Topic URI
topic_uri=$(az eventgrid topic show -n $EVENT_GRID_TOPIC_NAME -g $INFRASTRUCTURE_RESOURCE_GROUP_NAME --query endpoint --output tsv)
if [ $? -ne 0 ]
then
echo "Could not get the $EVENT_GRID_TOPIC_NAME event grid topic URI."
echo "deploy_request_reporter_function.sh failed"
exit $?
fi
# Assign Event Grid Topic URI
az functionapp config appsettings set --name $REQUEST_REPORTER_FUNCTION_APP_NAME --resource-group $INFRASTRUCTURE_RESOURCE_GROUP_NAME --settings "EVENT_GRID_TOPIC_URI=${topic_uri}"
if [ $? -ne 0 ]
then
echo "Could not set $REQUEST_REPORTER_FUNCTION_APP_NAME event grid topic URI."
echo "deploy_request_reporter_function.sh failed"
exit $?
fi
# Get Event Grid Topic key
topic_key=$(az eventgrid topic key list -n $EVENT_GRID_TOPIC_NAME -g $INFRASTRUCTURE_RESOURCE_GROUP_NAME --query key1 --output tsv)
if [ $? -ne 0 ]
then
echo "Could not get the $EVENT_GRID_TOPIC_NAME Event Grid topic key."
echo "deploy_request_reporter_function.sh failed"
exit $?
fi
# Assign Event Grid Key
az functionapp config appsettings set --name $REQUEST_REPORTER_FUNCTION_APP_NAME --resource-group $INFRASTRUCTURE_RESOURCE_GROUP_NAME --settings "EVENT_GRID_KEY=${topic_key}"
if [ $? -ne 0 ]
then
echo "Could not get the $EVENT_GRID_TOPIC_NAME Event Grid key."
echo "deploy_request_reporter_function.sh failed"
exit $?
fi
# Get Redis URI detail.
redis_uri_detail=($(az redis show --name $AZURE_CACHE_NAME --resource-group $INFRASTRUCTURE_RESOURCE_GROUP_NAME --query [hostName,sslPort] --output tsv))
if [ $? -ne 0 ]
then
echo "Could not get the $AZURE_CACHE_NAME Redis URI connection string."
echo "deploy_request_reporter_function.sh failed"
exit $?
fi
# Get Redis access key.
redis_key=$(az redis list-keys --name $AZURE_CACHE_NAME --resource-group $INFRASTRUCTURE_RESOURCE_GROUP_NAME --query primaryKey --output tsv)
if [ $? -ne 0 ]
then
echo "Could not get the $AZURE_CACHE_NAME Redis access key."
echo "deploy_request_reporter_function.sh failed"
exit $?
fi
# Assign the Redis connection string to an App Setting in the Web App
az functionapp config appsettings set --name $REQUEST_REPORTER_FUNCTION_APP_NAME --resource-group $INFRASTRUCTURE_RESOURCE_GROUP_NAME --settings "REDIS_CONNECTION_STRING=${redis_uri_detail[0]}:${redis_uri_detail[1]},password=$redis_key,ssl=True,abortConnect=False"
if [ $? -ne 0 ]
then
echo "Could assign the $CACHE_MANAGER_FUNCTION_APP_NAME Redis connection string."
echo "deploy_request_reporter_function.sh failed"
exit $?
fi
fi