Bicep 简介
在 Bicep 文件中,定义要部署到 Azure 的基础结构。 然后在整个开发生命周期中使用该文件部署基础结构。
创建资源组
创建存储帐户前,需要创建资源组或使用现有资源组。
在 storageaccountexamplerg
区域中创建名为 eastus
的 Azure 资源组:
az group create --name storageaccountexamplerg --___location eastus
创建存储帐户
使用以下代码创建 Bicep 文件来预配 Azure 存储帐户:
@description('Specifies the name for resources.')
param storageAccountName string = 'storage${uniqueString(resourceGroup().id)}'
@description('Specifies the ___location for resources.')
param ___location string = resourceGroup().___location
resource myStorageAccount 'Microsoft.Storage/storageAccounts@2022-09-01' = {
name: storageAccountName
___location: ___location
kind: 'StorageV2'
sku: {
name: 'Standard_RAGRS'
}
}
如果要自定义存储帐户名称,请记住,它的长度必须为 3 到 24 个字符,并且只能包含数字和小写字母。 存储帐户名称在 Azure 中必须是唯一的。
要部署 Bicep 文件,请使用 Azure CLI 或 Azure PowerShell,如下例所示。 运行命令后,部署开始,并且资源在指定的资源组中创建。
az deployment group create --resource-group storageaccountexamplerg --template-file <bicep-file>
验证存储帐户
要验证 Azure 存储帐户是否存在,请使用 Azure CLI 或 Azure PowerShell,如下例所示:
az storage account list --resource-group storageaccountexamplerg
清理资源
删除资源组时会一并删除该资源组和它包含的所有资源。 如果 storageaccountexamplerg
资源组中存在本单元中创建的存储帐户范围之外的资源,这些资源也会被删除。
az group delete --name storageaccountexamplerg