2

I'm trying to transition from Terraform with the azurerm provider to Bicep and having a tohgh time figuring out how to use Bicep to populate my required ADLS Gen 2 directory structure.

Many of my builds need a new ADLS with lots of containers, then inside each container I need nested directories, sometimes three or four levels deep. In Terraform this is pretty simple using the storage/path resource type: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/storage_data_lake_gen2_path

I cannot see any equivalent using Bicep. What am I missing? The only possibility that seems remotely feasible to accomplish this is to package a deployment Powershell or CLI script, but that looks like a lot of extra configuration and effort for something this trivial.

I would provide code samples for my bicep, but they would only show the storage and container resources and probably would not be very useful. The container resource works perfectly for creating the root directories - but I cannot see how to get Bicep to create directories/paths within them. Can anyone assist, please?

Update

Does not appear to be possible in Bicep. Happy to be proven wrong.

Indrid
  • 962
  • 4
  • 25
  • 39

1 Answers1

2

You will have to work with a deployment script to create directories in ADLS Gen2 file systems. You can include inline Azure CLI scripts in Bicep templates. You can create the directory using the Azure CLI command az storage fs directory create. If we include this command in a Bicep template deploying a ADLS Gen 2 storage account, it would look like this:

param location string = 'westeurope'
param containerName string = 'mycontainer'
param directoryName string = 'mydirectory'

resource storageAccount 'Microsoft.Storage/storageAccounts@2022-09-01' = {
  name: uniqueString(resourceGroup().id)
  kind: 'StorageV2'
  location: location
  sku: {
    name: 'Standard_LRS'
  }
  properties: {
    isHnsEnabled: true
  }

  resource container 'blobServices@2022-09-01' = {
    name: 'default'

    resource container 'containers@2022-09-01' = {
      name: containerName
    }
  }
}

resource createDirectory 'Microsoft.Resources/deploymentScripts@2020-10-01' = {
  name: 'createDirectory'
  kind: 'AzureCLI'
  location: location
  properties:{
    azCliVersion: '2.42.0'
    retentionInterval: 'P1D'
    arguments: '\'${storageAccount.name}\' \'${containerName}\' \'${directoryName}\''
    scriptContent: 'az storage fs directory create --account-name $1 -f $2 -n $3 --auth-mode key'
    environmentVariables: [
      {
        name: 'AZURE_STORAGE_KEY'
        secureValue: storageAccount.listKeys().keys[0].value
      }
    ]
  }
}

Tiamo Idzenga
  • 1,006
  • 11
  • 23
  • Thank you so much, yes, I had sort of come to same conclusion. In the end I wrote a standalone Powershell script to build out the multitude of paths using a single function. I did not use a deployment script though, I just run it as a downstream step/stage in AzDevops conditional on the main.bicep succeeding. Thank you very much! – Indrid Dec 29 '22 at 22:51
  • @Indrid Including it as a downstream stage in a pipeline seems to make more sense for me anyway. :) But the question was about doing it in a Bicep template. – Tiamo Idzenga Jan 09 '23 at 09:26