bicep creating storage account using module

To create a storage account we can make our bicep code more re-usable by placing in into modules

So we have this as our directory structure

root (main.bicep) -> module -> storage -> (we call this main.bicep too) 



root main.bicep contains the following code


// main.bicep

module storageModule './modules/storage/main.bicep' = {

  name: 'storageDeploy-${uniqueString(resourceGroup().id)}' 

  params: {

    storageSku: 'Standard_LRS'

  }

}

// Accessing an output from the module

output storageId string = storageModule.outputs.saName  


And our storage module (modules/storage/main.bicep) 



// main.bicep

@description('Storage Account Name (must be globally unique)')

param storageName string = 'store${uniqueString(resourceGroup().id)}'


@description('The location for the resource')

param location string = resourceGroup().location


@description('Storage SKU')

@allowed([

  'Standard_LRS'

  'Standard_GRS'

])


param storageSku string = 'Standard_LRS'


resource storageAccount 'Microsoft.Storage/storageAccounts@2023-01-01' = {

  name: '${toLower(storageName)}'

  location: location

  sku: {

    name: storageSku

  }

  kind: 'StorageV2'

  properties: {

    accessTier: 'Hot'

    supportsHttpsTrafficOnly: true

  }

}


// 2. Call the nested child module (Same folder reference)

module container './blob-service.bicep' = {

  name: 'container-deploy'

  params: {

    storageAccountName: storageAccount.name

    containerName: 'app-data'

  }

}

output saName string = storageAccount.name


And to create the bicep, we can use the following command 

 az stack group validate  --name "storage-enterprise--demo"
--resource-group "MyDevRG"   --template-file ./main.bicep
--deny-settings-mode "none"
--action-on-unmanage "detachAll"


The sample repo can be found here

https://github.com/kepungnzai/bicep-group-hello

Comments

Popular posts from this blog

vllm : Failed to infer device type

NodeJS: Error: spawn EINVAL in window for node version 20.20 and 18.20

android studio kotlin source is null error