Bu hızlı başlangıçta, Bicep dosyasıyla şablon belirtimlerinin nasıl oluşturulacağı ve dağıtılacağı açıklanmaktadır. Kuruluşunuzdaki kişilerin Microsoft Azure'da kaynak dağıtabilmesi için bir kaynak grubuna bir şablon belirtimi dağıtılır. Şablon belirtimleri, kullanıcılara Bicep dosyasını değiştirme erişimi vermek zorunda kalmadan dağıtım şablonlarını paylaşmanızı sağlar. Bu şablon belirtimi örneği, depolama hesabı dağıtmak için bir Bicep dosyası kullanır.
Şablon belirtimi oluşturduğunuzda, Bicep dosyası JavaScript Nesne Gösterimi'ne (JSON) dönüştürülür. Şablon belirtimi, Azure kaynaklarını dağıtmak için JSON kullanır. Şu anda Bir Bicep dosyasını içeri aktarmak ve şablon belirtimi kaynağı oluşturmak için Microsoft Azure portalını kullanamazsınız.
Önkoşullar
Bicep dosyası oluşturma
Yerel bicep dosyasından bir şablon belirtimi oluşturursunuz. Aşağıdaki örneği kopyalayın ve main.bicep olarak bilgisayarınıza kaydedin. Örneklerde C:\templates\main.bicep yolu kullanılır. Farklı bir yol kullanabilirsiniz, ancak komutları değiştirmeniz gerekir.
Aşağıdaki Bicep dosyası PowerShell ve CLI sekmelerinde kullanılır.
Bicep dosya sekmesi, şablon belirtimi oluşturmak ve dağıtmak için Bicep ve JSON'u birleştiren farklı bir şablon kullanır.
@allowed([
'Premium_LRS'
'Premium_ZRS'
'Standard_GRS'
'Standard_GZRS'
'Standard_LRS'
'Standard_RAGRS'
'Standard_RAGZRS'
'Standard_ZRS'
])
@description('Storage account type.')
param storageAccountType string = 'Standard_LRS'
@description('Location for all resources.')
param location string = resourceGroup().location
var storageAccountName = 'storage${uniqueString(resourceGroup().id)}'
resource storageAccount 'Microsoft.Storage/storageAccounts@2025-06-01' = {
name: storageAccountName
location: location
sku: {
name: storageAccountType
}
kind: 'StorageV2'
properties: {}
}
output storageAccountNameOutput string = storageAccount.name
Şablon belirtimi oluşturma
Şablon belirtimi Microsoft.Resources/templateSpecs adlı bir kaynak türüdür. Şablon belirtimi oluşturmak için Azure CLI, Azure PowerShell veya bicep dosyası kullanın.
Bu örnekte kaynak grubu adı templateSpecRGkullanılır. Farklı bir ad kullanabilirsiniz, ancak komutları değiştirmeniz gerekir.
Şablon belirtimini içerecek yeni bir kaynak grubu oluşturun.
New-AzResourceGroup `
-Name templateSpecRG `
-Location westus2
Bu kaynak grubunda şablon belirtimini oluşturun. Yeni şablona storageSpec adını verin.
New-AzTemplateSpec `
-Name storageSpec `
-Version "1.0" `
-ResourceGroupName templateSpecRG `
-Location westus2 `
-TemplateFile "C:\templates\main.bicep"
Şablon belirtimini içerecek yeni bir kaynak grubu oluşturun.
az group create \
--name templateSpecRG \
--location westus2
Bu kaynak grubunda şablon belirtimini oluşturun. Yeni şablona storageSpec adını verin.
az ts create \
--name storageSpec \
--version "1.0" \
--resource-group templateSpecRG \
--location westus2 \
--template-file "C:\templates\main.bicep"
Bicep dosyasıyla bir şablon belirtimi oluşturabilirsiniz, ancak mainTemplate JSON içinde olması gerekir. JSON şablonu standart JSON söz dizimini kullanmaz. Örneğin, satır sonu virgülleri yoktur, çift tırnaklar tek tırnaklarla değiştirilir ve ifadeler içindeki tek tırnaklardan kaçmak için ters eğik çizgi (\) kullanılır.
Aşağıdaki şablonu kopyalayın ve main.bicep olarak bilgisayarınıza kaydedin.
param templateSpecName string = 'storageSpec'
param templateSpecVersionName string = '1.0'
@description('Location for all resources.')
param location string = resourceGroup().location
resource createTemplateSpec 'Microsoft.Resources/templateSpecs@2022-02-01' = {
name: templateSpecName
location: location
}
resource createTemplateSpecVersion 'Microsoft.Resources/templateSpecs/versions@2022-02-01' = {
parent: createTemplateSpec
name: templateSpecVersionName
location: location
properties: {
mainTemplate: {
'$schema': 'https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#'
'contentVersion': '1.0.0.0'
'metadata': {}
'parameters': {
'storageAccountType': {
'type': 'string'
'defaultValue': 'Standard_LRS'
'metadata': {
'description': 'Storage account type.'
}
'allowedValues': [
'Premium_LRS'
'Premium_ZRS'
'Standard_GRS'
'Standard_GZRS'
'Standard_LRS'
'Standard_RAGRS'
'Standard_RAGZRS'
'Standard_ZRS'
]
}
'location': {
'type': 'string'
'defaultValue': '[resourceGroup().location]'
'metadata': {
'description': 'Location for all resources.'
}
}
}
'variables': {
'storageAccountName': '[format(\'{0}{1}\', \'storage\', uniqueString(resourceGroup().id))]'
}
'resources': [
{
'type': 'Microsoft.Storage/storageAccounts'
'apiVersion': '2025-06-01'
'name': '[variables(\'storageAccountName\')]'
'location': '[parameters(\'location\')]'
'sku': {
'name': '[parameters(\'storageAccountType\')]'
}
'kind': 'StorageV2'
'properties': {}
}
]
'outputs': {
'storageAccountNameOutput': {
'type': 'string'
'value': '[variables(\'storageAccountName\')]'
}
}
}
}
}
Yeni bir kaynak grubu oluşturmak için Azure PowerShell veya Azure CLI kullanın.
New-AzResourceGroup `
-Name templateSpecRG `
-Location westus2
az group create \
--name templateSpecRG \
--location westus2
Bu kaynak grubunda şablon belirtimini oluşturun. Şablon belirtimi adı storageSpec ve sürüm numarası 1.0 , Bicep dosyasındaki parametrelerdir.
New-AzResourceGroupDeployment `
-ResourceGroupName templateSpecRG `
-TemplateFile "C:\templates\main.bicep"
az deployment group create \
--resource-group templateSpecRG \
--template-file "C:\templates\main.bicep"
Şablon belirtimlerini dağıtma
Depolama hesabı dağıtmak için şablon belirtimini kullanın. Bu örnekte kaynak grubu adı storageRGkullanılır. Farklı bir ad kullanabilirsiniz, ancak komutları değiştirmeniz gerekir.
Yeni depolama hesabını içerecek bir kaynak grubu oluşturun.
New-AzResourceGroup `
-Name storageRG `
-Location westus2
Şablon belirtiminin kaynak kimliğini alın.
$id = (Get-AzTemplateSpec -ResourceGroupName templateSpecRG -Name storageSpec -Version "1.0").Versions.Id
Şablon belirtimini dağıtın.
New-AzResourceGroupDeployment `
-TemplateSpecId $id `
-ResourceGroupName storageRG
Parametreleri tam olarak bicep dosya dağıtımında yaptığınız gibi sağlarsınız. Şablon belirtimini depolama hesabı türü için bir parametreyle yeniden dağıtın.
New-AzResourceGroupDeployment `
-TemplateSpecId $id `
-ResourceGroupName storageRG `
-storageAccountType Standard_GRS
Yeni depolama hesabını içerecek bir kaynak grubu oluşturun.
az group create \
--name storageRG \
--location westus2
Şablon belirtiminin kaynak kimliğini alın.
id=$(az ts show --name storageSpec --resource-group templateSpecRG --version "1.0" --query "id")
Not
Şablon belirtim kimliğini alma ve Windows PowerShell'de bir değişkene atama ile ilgili bilinen bir sorun vardır.
Şablon belirtimini dağıtın.
az deployment group create \
--resource-group storageRG \
--template-spec $id
Parametreleri tam olarak bicep dosya dağıtımında yaptığınız gibi sağlarsınız. Şablon belirtimini depolama hesabı türü için bir parametreyle yeniden dağıtın.
az deployment group create \
--resource-group storageRG \
--template-spec $id \
--parameters storageAccountType="Standard_GRS"
Bicep dosyası kullanarak bir şablon belirtimi dağıtmak için bir modül kullanın. Modül, mevcut bir şablon belirtimine bağlanır. Daha fazla bilgi için bkz . şablon belirtimindeki dosya.
Aşağıdaki Bicep modülünü kopyalayın ve bilgisayarınıza storage.bicep olarak kaydedin.
module deployTemplateSpec 'ts:<subscriptionId>/templateSpecRG/storageSpec:1.0' = {
name: 'deployVersion1'
}
modülde değerini değiştirin <subscriptionId> . Abonelik kimliğinizi almak için Azure PowerShell veya Azure CLI kullanın.
(Get-AzContext).Subscription.Id
az account show --query "id" --output tsv
Depolama hesabı için yeni bir kaynak grubu oluşturmak için Azure PowerShell veya Azure CLI kullanın.
New-AzResourceGroup `
-Name storageRG `
-Location westus2
az group create \
--name storageRG \
--location westus2
Şablon belirtimini Azure PowerShell veya Azure CLI ile dağıtın.
New-AzResourceGroupDeployment `
-ResourceGroupName storageRG `
-TemplateFile "C:\templates\storage.bicep"
az deployment group create \
--resource-group storageRG \
--template-file "C:\templates\storage.bicep"
Parametre ekleyebilir ve şablon belirtimini farklı bir depolama hesabı türüyle yeniden dağıtabilirsiniz. Örneği kopyalayın ve storage.bicep dosyanızı değiştirin. Ardından şablon belirtimi dağıtımını yeniden dağıtın.
module deployTemplateSpec 'ts:<subscriptionId>/templateSpecRG/storageSpec:1.0' = {
name: 'deployVersion1'
params: {
storageAccountType: 'Standard_GRS'
}
}
Erişim izni ver
Kuruluşunuzdaki diğer kullanıcıların şablon belirtiminizi dağıtmasına izin vermek istiyorsanız, onlara okuma erişimi vermeniz gerekir. Okuyucu rolünü, paylaşmak istediğiniz şablon belirtimlerini içeren kaynak grubu için bir Microsoft Entra grubuna atayabilirsiniz. Daha fazla bilgi için bkz . Öğretici: Azure PowerShell kullanarak Azure kaynaklarına grup erişimi verme.
Bicep dosyasını güncelleştirme
Şablon belirtimi oluşturulduktan sonra Bicep dosyasını güncelleştirmeye karar verdiniz. PowerShell veya CLI sekmelerindeki örneklerle devam etmek için örneği kopyalayın ve main.bicep dosyanızı değiştirin.
parametresi storageNamePrefix , depolama hesabı adı için bir ön ek değeri belirtir. değişkeni, storageAccountName ön eki benzersiz bir dizeyle birleştirir.
@allowed([
'Premium_LRS'
'Premium_ZRS'
'Standard_GRS'
'Standard_GZRS'
'Standard_LRS'
'Standard_RAGRS'
'Standard_RAGZRS'
'Standard_ZRS'
])
@description('Storage account type.')
param storageAccountType string = 'Standard_LRS'
@description('Location for all resources.')
param location string = resourceGroup().location
@maxLength(11)
@description('The storage account name prefix.')
param storageNamePrefix string = 'storage'
var storageAccountName = '${toLower(storageNamePrefix)}${uniqueString(resourceGroup().id)}'
resource storageAccount 'Microsoft.Storage/storageAccounts@2025-06-01' = {
name: storageAccountName
location: location
sku: {
name: storageAccountType
}
kind: 'StorageV2'
properties: {}
}
output storageAccountNameOutput string = storageAccount.name
Şablon belirtim sürümünü güncelleştirme
Düzeltilen şablon için yeni bir şablon belirtimi oluşturmak yerine, var olan şablon belirtimine adlı 2.0 yeni bir sürüm ekleyin. Kullanıcılar iki sürümü de dağıtmayı seçebilir.
Şablon belirtiminin yeni bir sürümünü oluşturun.
New-AzTemplateSpec `
-Name storageSpec `
-Version "2.0" `
-ResourceGroupName templateSpecRG `
-Location westus2 `
-TemplateFile "C:\templates\main.bicep"
Yeni sürümü dağıtmak için 2.0 sürümün kaynak kimliğini alın.
$id = (Get-AzTemplateSpec -ResourceGroupName templateSpecRG -Name storageSpec -Version "2.0").Versions.Id
Yeni sürümü dağıtın ve depolama hesabı adı için bir ön ek belirtmek için öğesini kullanın storageNamePrefix .
New-AzResourceGroupDeployment `
-TemplateSpecId $id `
-ResourceGroupName storageRG `
-storageNamePrefix "demo"
Şablon belirtiminin yeni bir sürümünü oluşturun.
az ts create \
--name storageSpec \
--version "2.0" \
--resource-group templateSpecRG \
--location westus2 \
--template-file "C:\templates\main.bicep"
Yeni sürümü dağıtmak için 2.0 sürümün kaynak kimliğini alın.
id=$(az ts show --name storageSpec --resource-group templateSpecRG --version "2.0" --query "id")
Yeni sürümü dağıtın ve depolama hesabı adı için bir ön ek belirtmek için öğesini kullanın storageNamePrefix .
az deployment group create \
--resource-group storageRG \
--template-spec $id \
--parameters storageNamePrefix="demo"
Şablon belirtiminin yeni bir sürümünü oluşturun. Örneği kopyalayın ve main.bicep dosyanızı değiştirin.
parametresi storageNamePrefix , depolama hesabı adı için bir ön ek değeri belirtir. değişkeni, storageAccountName ön eki benzersiz bir dizeyle birleştirir.
param templateSpecName string = 'storageSpec'
param templateSpecVersionName string = '2.0'
@description('Location for all resources.')
param location string = resourceGroup().location
resource createTemplateSpec 'Microsoft.Resources/templateSpecs@2022-02-01' = {
name: templateSpecName
location: location
}
resource createTemplateSpecVersion 'Microsoft.Resources/templateSpecs/versions@2022-02-01' = {
parent: createTemplateSpec
name: templateSpecVersionName
location: location
properties: {
mainTemplate: {
'$schema': 'https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#'
'contentVersion': '1.0.0.0'
'metadata': {}
'parameters': {
'storageAccountType': {
'type': 'string'
'defaultValue': 'Standard_LRS'
'metadata': {
'description': 'Storage account type.'
}
'allowedValues': [
'Premium_LRS'
'Premium_ZRS'
'Standard_GRS'
'Standard_GZRS'
'Standard_LRS'
'Standard_RAGRS'
'Standard_RAGZRS'
'Standard_ZRS'
]
}
'location': {
'type': 'string'
'defaultValue': '[resourceGroup().location]'
'metadata': {
'description': 'Location for all resources.'
}
}
'storageNamePrefix': {
'type': 'string'
'defaultValue': 'storage'
'metadata': {
'description': 'The storage account name prefix.'
}
'maxLength': 11
}
}
'variables': {
'storageAccountName': '[format(\'{0}{1}\', toLower(parameters(\'storageNamePrefix\')), uniqueString(resourceGroup().id))]'
}
'resources': [
{
'type': 'Microsoft.Storage/storageAccounts'
'apiVersion': '2025-06-01'
'name': '[variables(\'storageAccountName\')]'
'location': '[parameters(\'location\')]'
'sku': {
'name': '[parameters(\'storageAccountType\')]'
}
'kind': 'StorageV2'
'properties': {}
}
]
'outputs': {
'storageAccountNameOutput': {
'type': 'string'
'value': '[variables(\'storageAccountName\')]'
}
}
}
}
}
Şablon belirtiminize yeni sürümü eklemek için şablonunuzu Azure PowerShell veya Azure CLI ile dağıtın.
New-AzResourceGroupDeployment `
-ResourceGroupName templateSpecRG `
-TemplateFile "C:\templates\main.bicep"
az deployment group create \
--resource-group templateSpecRG \
--template-file "C:\templates\main.bicep"
Aşağıdaki Bicep modülünü kopyalayın ve bilgisayarınıza storage.bicep olarak kaydedin.
module deployTemplateSpec 'ts:<subscriptionId>/templateSpecRG/storageSpec:2.0' = {
name: 'deployVersion2'
params: {
storageNamePrefix: 'demo'
}
}
modülde değerini değiştirin <subscriptionId> . Abonelik kimliğinizi almak için Azure PowerShell veya Azure CLI kullanın.
(Get-AzContext).Subscription.Id
az account show --query "id" --output tsv
Şablon belirtimini Azure PowerShell veya Azure CLI ile dağıtın.
New-AzResourceGroupDeployment `
-ResourceGroupName storageRG `
-TemplateFile "C:\templates\storage.bicep"
az deployment group create \
--resource-group storageRG \
--template-file "C:\templates\storage.bicep"
Kaynakları temizleme
Bu hızlı başlangıçta dağıtmış olduğunuz kaynakları temizlemek için her iki kaynak grubunu da silin. Kaynak grubu, şablon belirtimleri ve depolama hesapları silinir.
Kaynak gruplarını silmek için Azure PowerShell veya Azure CLI kullanın.
Remove-AzResourceGroup -Name "templateSpecRG"
Remove-AzResourceGroup -Name "storageRG"
az group delete --name templateSpecRG
az group delete --name storageRG
Sonraki adımlar