Search code examples
azureazure-web-app-serviceazure-storageazure-resource-managerazure-bicep

Set Azure Storage Account mount path with Bicep


Previously, with Azure CLI script, I had the following Storage Account config:

az webapp config storage-account add \
  --resource-group $resourceGroup \
  --name $functionAppName \
  --storage-type AzureFiles \
  --share-name $shareName \
  --custom-id $shareId \
  --account-name $AZURE_STORAGE_ACCOUNT \
  --mount-path $mountPath \

Now, I'm trying to write this with Bicep, but I can't find any config for mount-path. Is there any possibility to set this in a Bicep file?


Solution

  • The Web Apps - Update Azure Storage Accounts accepts a dictionary of storage properties, so something like that should work:

    var webAppName = 'web app name'
    var storageAccountName = 'storage account name'
    var shareName = 'share name'
    var mountPath = 'mount path'
    
    resource storageAccount 'Microsoft.Storage/storageAccounts@2019-06-01' existing = {
      name: storageAccountName
    }
    
    resource webApp 'Microsoft.Web/sites@2021-01-15' existing = {
      name: webAppName
    }
    resource storageSetting 'Microsoft.Web/sites/config@2021-01-15' = {
      name: 'azurestorageaccounts'
      parent: webApp
      properties: {
        '${shareName}': {
          type: 'AzureFiles'
          shareName: shareName
          mountPath: mountPath
          accountName: storageAccount.name
          accessKey: storageAccount.listKeys().keys[0].value
        }
      }
    }