Created
April 26, 2024 18:01
-
-
Save krnese/4e0e35c0fd0ff91ccda98a8de8678148 to your computer and use it in GitHub Desktop.
Azure Function
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
{ | |
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", | |
"contentVersion": "1.0.0.0", | |
"parameters": { | |
"functionAppName": { | |
"type": "string", | |
"defaultValue": "[format('func-{0}', uniqueString(resourceGroup().id))]", | |
"metadata": { | |
"description": "The name of the Azure Function app." | |
} | |
}, | |
"storageAccountType": { | |
"type": "string", | |
"defaultValue": "Standard_LRS", | |
"allowedValues": [ | |
"Standard_LRS", | |
"Standard_GRS", | |
"Standard_RAGRS" | |
], | |
"metadata": { | |
"description": "Storage Account type" | |
} | |
}, | |
"location": { | |
"type": "string", | |
"defaultValue": "[resourceGroup().location]", | |
"metadata": { | |
"description": "Location for all resources." | |
} | |
}, | |
"functionWorkerRuntime": { | |
"type": "string", | |
"defaultValue": "python", | |
"metadata": { | |
"description": "The language worker runtime to load in the function app." | |
} | |
}, | |
"linuxFxVersion": { | |
"type": "string", | |
"defaultValue": "PYTHON|3.11", | |
"metadata": { | |
"description": "Required for Linux app to represent runtime stack in the format of 'runtime|runtimeVersion'. For example: 'python|3.11'" | |
} | |
}, | |
"packageUri": { | |
"type": "string", | |
"defaultValue": "https://github.com/Azure/ai-hub/raw/main/infrastructure/terraform/modules/functions/rag.zip", | |
"metadata": { | |
"description": "The zip content url." | |
} | |
} | |
}, | |
"variables": { | |
"hostingPlanName": "[parameters('functionAppName')]", | |
"applicationInsightsName": "[parameters('functionAppName')]", | |
"uaiName": "[parameters('functionAppName')]", | |
"storageAccountName": "[format('{0}azfunctions', uniqueString(resourceGroup().id))]" | |
}, | |
"resources": [ | |
{ | |
"type": "Microsoft.ManagedIdentity/userAssignedIdentities", | |
"apiVersion": "2023-01-31", | |
"location": "[parameters('location')]", | |
"name": "[variables('uaiName')]" | |
}, | |
// Assign Storage Blob Contributor to the User Assigned Managed Identity on the resource group | |
{ | |
"type": "Microsoft.Authorization/roleAssignments", | |
"apiVersion": "2022-04-01", | |
"name": "[guid(resourceGroup().id, variables('uaiName'))]", | |
"dependsOn": [ | |
"[resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', variables('uaiName'))]", | |
"[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]" | |
], | |
"properties": { | |
"roleDefinitionId": "[concat(subscription().id, '/providers/Microsoft.Authorization/roleDefinitions/', 'ba92f5b4-2d11-453d-a403-e96b0029c9fe')]", | |
"principalId": "[reference(resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', variables('uaiName')), '2023-01-31').principalId]", | |
"scope": "[resourceGroup().id]" | |
} | |
}, | |
{ | |
"type": "Microsoft.Storage/storageAccounts", | |
"apiVersion": "2022-05-01", | |
"name": "[variables('storageAccountName')]", | |
"location": "[parameters('location')]", | |
"sku": { | |
"name": "[parameters('storageAccountType')]" | |
}, | |
"kind": "Storage" | |
}, | |
{ | |
"type": "Microsoft.Web/serverfarms", | |
"apiVersion": "2018-02-01", | |
"name": "[variables('hostingPlanName')]", | |
"location": "[resourceGroup().location]", | |
"sku": { | |
"name": "EP1", | |
"tier": "ElasticPremium", | |
"size": "EP1", | |
"family": "EP", | |
"capacity": 1 | |
}, | |
"kind": "linux", | |
"properties": { | |
"reserved": true | |
} | |
}, | |
{ | |
"type": "Microsoft.Insights/components", | |
"apiVersion": "2020-02-02", | |
"name": "[variables('applicationInsightsName')]", | |
"location": "[resourceGroup().location]", | |
"properties": { | |
"Application_Type": "web" | |
}, | |
"kind": "web" | |
}, | |
{ | |
"type": "Microsoft.Web/sites", | |
"apiVersion": "2022-03-01", | |
"name": "[parameters('functionAppName')]", | |
"location": "[parameters('location')]", | |
"identity": { | |
"type": "UserAssigned", | |
"userAssignedIdentities": { | |
"[resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', variables('uaiName'))]": {} | |
} | |
}, | |
"dependsOn": [ | |
"[resourceId('Microsoft.Insights/components', variables('applicationInsightsName'))]", | |
"[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]", | |
"[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]" | |
], | |
"kind": "functionapp,linux", | |
"properties": { | |
"reserved": true, | |
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]", | |
"siteConfig": { | |
"linuxFxVersion": "[parameters('linuxFxVersion')]", | |
"appSettings": [ | |
{ | |
"name": "APPINSIGHTS_INSTRUMENTATIONKEY", | |
"value": "[reference(resourceId('Microsoft.Insights/components', parameters('functionAppName')), '2020-02-02-preview').InstrumentationKey]" | |
}, | |
{ | |
"name": "AzureWebJobsStorage__accountname", | |
"value": "[variables('storageAccountName')]" | |
}, | |
{ | |
"name": "SCM_DO_BUILD_DURING_DEPLOYMENT", | |
"value": "true" | |
}, | |
{ | |
"name": "FUNCTIONS_EXTENSION_VERSION", | |
"value": "~4" | |
}, | |
{ | |
"name": "FUNCTIONS_WORKER_RUNTIME", | |
"value": "[parameters('functionWorkerRuntime')]" | |
}, | |
{ | |
"name": "WEBSITE_RUN_FROM_PACKAGE", | |
"value": "0" | |
}, | |
{ | |
"name": "TaskHubName", | |
"value": "task1" | |
}, | |
{ | |
"name": "WEBSITE_RUN_FROM_PACKAGE_BLOB_MI_RESOURCE_ID", | |
"value": "[resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', variables('uaiName'))]" | |
}, | |
{ | |
"name": "AZURE_CLIENT_ID", | |
"value": "[reference(resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', variables('uaiName')), '2023-01-31').clientId]" | |
} | |
] | |
} | |
} | |
}, | |
{ | |
"type": "Microsoft.Web/sites/extensions", | |
"apiVersion": "2022-03-01", | |
"name": "[concat(parameters('functionAppName'), '/ZipDeploy')]", | |
"dependsOn": [ | |
"[resourceId('Microsoft.Web/sites', parameters('functionAppName'))]" | |
], | |
"properties": { | |
"packageUri": "[parameters('packageUri')]", | |
"appOffline": false | |
} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment