Edit

Share via


Quickstart: Create a storage task with Bicep

This quickstart describes how to create a storage task by using Bicep.

Bicep is a ___domain-specific language (DSL) that uses declarative syntax to deploy Azure resources. It provides concise syntax, reliable type safety, and support for code reuse. Bicep offers the best authoring experience for your infrastructure-as-code solutions in Azure.

Prerequisites

If you don't have an Azure subscription, create a free account before you begin.

Review the Bicep file

The Bicep file used in this quickstart is from Azure Quickstart Templates.

@sys.description('The name of storage task.')
@minLength(3)
@maxLength(18)
param storageTaskName string

@sys.description('A description of the storage task.')
param description string

@sys.description('The region in which to create the storage task.')
param ___location string = resourceGroup().___location

@sys.description('Locks the file for one day.')
param lockedUntilDate string = dateTimeAdd(utcNow(), 'P1D')

resource storageTask 'Microsoft.StorageActions/storageTasks@2023-01-01' = {
  name: storageTaskName
  ___location: ___location
  identity: {
    type: 'SystemAssigned'
  }
  properties: {
    action: {
      if: {
        condition: '[[endsWith(Name, \'.docx\')]]'
        operations: [
         {
            name: 'SetBlobImmutabilityPolicy'
            onSuccess: 'continue'
            onFailure: 'break'
            parameters: {
              untilDate: lockedUntilDate
              mode: 'locked'
            }
         }
         {
            name: 'SetBlobTags'
            onSuccess: 'continue'
            onFailure: 'break'
            parameters: {
                tagsetImmutabilityUpdatedBy: 'StorageTaskQuickstart'
            }     
         }
        ]
      }

    }
    description: description
    enabled: true
  }
}

The Microsoft.StorageActions/storageTasks Azure resource is defined in the Bicep file.

Deploy the Bicep file

  1. Save the Bicep file as main.bicep to your local computer.

  2. Deploy the Bicep file using either Azure CLI or Azure PowerShell.

az group create --name exampleRG --___location <region>

az deployment group create --resource-group exampleRG --template-file main.bicep --parameters storageTaskName="<storage-task-name>" description="<description>" 

Review deployed resources

  1. In the Azure portal, search for Storage Tasks. Then, under Services, select Storage tasks - Azure Storage Actions.

  2. In the list of storage tasks, search for the name of the storage task that you deployed.

    Screenshot of the deployed storage task as it appears in the Azure portal.

Clean up resources

When no longer needed, delete the resource group. The resource group and all the resources in the resource group are deleted. Use the following command to delete the resource group and all its contained resources.

az group delete --name <resource-group-name>

Replace <resource-group-name> with the name of your resource group.

Next steps

Assign a storage task to a storage account.