Skip to content

Storage account, blobs, files, lifecycle

Level: Intermediate

Overview and purpose

Create private-only StorageV2 with optional private containers, SMB file shares, and a cool-tier lifecycle policy.

Azure services and dependencies

Read main.bicep for the exact resource types, supported API versions, decorators, and outputs. No secret values are required or emitted by this module.

Prerequisites

Install Azure CLI and Bicep, authenticate to the intended subscription, and confirm az account show before executing cloud commands. Choose a globally unique lowercase alphanumeric name. For data access, provision private endpoints, private DNS, and appropriate identity roles.

Use the repository root as the working directory. Commands below use Bash (Azure Cloud Shell works); PowerShell variable syntax differs. Set RG to a dedicated existing sandbox group (except for the subscription-scoped resource-group example), and LOCATION to an approved Azure region. Set shell variables NAME to your own approved values. For array/object inputs, put valid JSON in the corresponding quoted variable. Never use example IDs as real principal/resource IDs.

Important parameters

Parameter Type Requirement
name string Required
location string Optional; see source default
containers array Optional; see source default
fileShares array Optional; see source default
coolAfterDays int Optional; see source default

Descriptions and defaults live beside each declaration in the canonical source. Names must meet the individual Azure service's naming rules.

Bicep source and usage

View the complete source. Reference this module from another Bicep file with a relative module path and a params object. The resources/modules lesson shows composition and dependencies.

Compile and validate locally

az bicep build --file 1_storage-databases/storage-account/main.bicep --stdout

Compilation and linting need no Azure login and create no resources. A successful compile is not evidence that a deployment or application has been tested.

Deployment instructions

These are opt-in cloud operations, never routine CI steps. Review policy, permissions, region, quotas, dependencies, and price before proceeding.

az deployment group validate --resource-group "$RG" --template-file 1_storage-databases/storage-account/main.bicep --parameters name="$NAME"
az deployment group what-if --resource-group "$RG" --template-file 1_storage-databases/storage-account/main.bicep --parameters name="$NAME"
az deployment group create --resource-group "$RG" --template-file 1_storage-databases/storage-account/main.bicep --parameters name="$NAME"

For a reusable deployment, put your own values into an untracked *.local.bicepparam file with a using declaration instead of embedding environment identifiers into the module.

Expected results and validation

The deployment returns the outputs declared at the end of main.bicep. Inspect the deployment's provisioning state and resource IDs in Azure Portal or Azure CLI. For a resource-group deployment:

az resource list --resource-group "$RG" --output table

For subscription resource-group creation, verify az group show --name "$NAME". Then perform the service-specific checks below. No live Azure deployment is claimed by this repository's offline CI.

Service-specific checks and limitations

SMB shares are provisioned but SMB identity integration is not configured. Configure an approved Azure Files identity source and ACLs before mounting. Blob and file endpoints require separate private endpoints.

Cleanup

Only if this is a dedicated disposable group, inspect its contents and delete it:

az resource list --resource-group "$RG" --output table
az group delete --name "$RG"

For the resource-group module use the created NAME as RG. Do not delete shared prerequisites or groups containing unrelated work. Deletion can be delayed by locks, soft-delete, protection settings, or backup retention. Verify completion in Azure; stopping compute is not full cleanup.

Cost and security considerations

Capacity, transactions, cool-tier minimum retention, data retrieval, and private endpoints may be charged. Public blob access and shared keys are disabled.

Use least privilege and approved regions. Consult the current Azure pricing calculator and Microsoft Bicep resource reference.

Complete Bicep source

1_storage-databases/storage-account/main.bicep
@description('Globally unique lowercase alphanumeric storage name.')
@minLength(3)
@maxLength(24)
param name string
@description('Azure region.')
param location string = resourceGroup().location
@description('Private blob containers to create.')
param containers array = []
@description('SMB file shares to create. Shared key access remains disabled.')
param fileShares array = []
@description('Days before base blobs move to cool tier; zero disables the lifecycle policy.')
@minValue(0)
param coolAfterDays int = 0

resource account 'Microsoft.Storage/storageAccounts@2023-05-01' = {
  name: name
  location: location
  kind: 'StorageV2'
  sku: { name: 'Standard_LRS' }
  properties: {
    minimumTlsVersion: 'TLS1_2'
    supportsHttpsTrafficOnly: true
    allowBlobPublicAccess: false
    allowSharedKeyAccess: false
    publicNetworkAccess: 'Disabled'
    defaultToOAuthAuthentication: true
  }
}
resource blobs 'Microsoft.Storage/storageAccounts/blobServices@2023-05-01' = {
  parent: account
  name: 'default'
  properties: {
    deleteRetentionPolicy: { enabled: true, days: 7 }
  }
}
resource blobContainers 'Microsoft.Storage/storageAccounts/blobServices/containers@2023-05-01' = [for container in containers: {
  parent: blobs
  name: container
  properties: { publicAccess: 'None' }
}]
resource files 'Microsoft.Storage/storageAccounts/fileServices@2023-05-01' = {
  parent: account
  name: 'default'
  properties: {}
}
resource shares 'Microsoft.Storage/storageAccounts/fileServices/shares@2023-05-01' = [for share in fileShares: {
  parent: files
  name: share
  properties: { shareQuota: 100, enabledProtocols: 'SMB' }
}]
resource lifecycle 'Microsoft.Storage/storageAccounts/managementPolicies@2023-05-01' = if (coolAfterDays > 0) {
  parent: account
  name: 'default'
  properties: {
    policy: {
      rules: [
        {
          name: 'CoolBaseBlobs'
          enabled: true
          type: 'Lifecycle'
          definition: {
            filters: { blobTypes: ['blockBlob'] }
            actions: {
              baseBlob: { tierToCool: { daysAfterModificationGreaterThan: coolAfterDays } }
            }
          }
        }
      ]
    }
  }
}

output id string = account.id
output name string = account.name