Catatan
Akses ke halaman ini memerlukan otorisasi. Anda dapat mencoba masuk atau mengubah direktori.
Akses ke halaman ini memerlukan otorisasi. Anda dapat mencoba mengubah direktori.
Pelajari cara menyebarkan template Azure Resource Manager (template ARM) dari komputer lokal Anda. Dibutuhkan sekitar 8 menit untuk menyelesaikannya.
Tutorial ini adalah seri pertama. Saat Anda maju melalui seri ini, Anda memodulasi templat dengan membuat templat tertaut, menyimpan templat tertaut di akun penyimpanan, mengamankan templat yang ditautkan dengan menggunakan token SAS, dan mempelajari cara membuat alur DevOps untuk menyebarkan templat. Seri ini berfokus pada penyebaran template. Jika Anda ingin mempelajari pengembangan templat, lihat tutorial pemula.
Dapatkan alat
Pastikan Anda memiliki alat yang Anda butuhkan untuk menyebarkan templat.
Penyebaran baris perintah
Untuk menyebarkan templat, Anda memerlukan Azure PowerShell atau Azure CLI. Untuk petunjuk penginstalan, lihat:
- Menginstal Azure PowerShell
- Menginstal Azure CLI di Windows
- Menginstal Azure CLI di Linux
- Menginstal Azure CLI di macOS
Setelah menginstal Azure PowerShell atau Azure CLI, masuk untuk pertama kalinya. Untuk bantuan, lihat Masuk - PowerShell atau Masuk - Azure CLI.
Editor (Opsional)
Templat adalah file JSON. Untuk meninjau atau mengedit templat, Anda dapat menggunakan Visual Studio Code.
Meninjau templat
template tersebut menyebarkan akun penyimpanan, paket layanan aplikasi, dan aplikasi web. Jika Anda tertarik untuk membuat templat, lihat Panduan Templat Memulai Cepat. Namun, Anda tidak perlu membuat templat untuk menyelesaikan tutorial ini.
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"projectName": {
"type": "string",
"minLength": 3,
"maxLength": 11,
"metadata": {
"description": "Specify a project name that is used to generate resource names."
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Specify a location for the resources."
}
},
"storageSKU": {
"type": "string",
"defaultValue": "Standard_LRS",
"allowedValues": [
"Standard_LRS",
"Standard_GRS",
"Standard_RAGRS",
"Standard_ZRS",
"Premium_LRS",
"Premium_ZRS",
"Standard_GZRS",
"Standard_RAGZRS"
],
"metadata": {
"description": "Specify the storage account type."
}
},
"linuxFxVersion": {
"type": "string",
"defaultValue": "php|7.0",
"metadata": {
"description": "Specify the Runtime stack of current web app"
}
}
},
"variables": {
"storageAccountName": "[format('{0}{1}', parameters('projectName'), uniqueString(resourceGroup().id))]",
"webAppName": "[format('{0}WebApp', parameters('projectName'))]",
"appServicePlanName": "[format('{0}Plan', parameters('projectName'))]"
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2025-06-01",
"name": "[variables('storageAccountName')]",
"location": "[parameters('location')]",
"sku": {
"name": "[parameters('storageSKU')]"
},
"kind": "StorageV2",
"properties": {
"supportsHttpsTrafficOnly": true
}
},
{
"type": "Microsoft.Web/serverfarms",
"apiVersion": "2025-03-01",
"name": "[variables('appServicePlanName')]",
"location": "[parameters('location')]",
"sku": {
"name": "B1",
"tier": "Basic",
"size": "B1",
"family": "B",
"capacity": 1
},
"kind": "linux",
"properties": {
"perSiteScaling": false,
"reserved": true,
"targetWorkerCount": 0,
"targetWorkerSizeId": 0
}
},
{
"type": "Microsoft.Web/sites",
"apiVersion": "2025-03-01",
"name": "[variables('webAppName')]",
"location": "[parameters('location')]",
"kind": "app",
"properties": {
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanName'))]",
"siteConfig": {
"linuxFxVersion": "[parameters('linuxFxVersion')]"
}
},
"dependsOn": [
"[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanName'))]"
]
}
],
"outputs": {
"storageEndpoint": {
"type": "object",
"value": "[reference(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName')), '2023-01-01').primaryEndpoints]"
}
}
}
Penting
Nama akun penyimpanan harus unik, antara 3 dan 24 karakter, dan hanya menggunakan angka dan huruf kecil . Variabel templat sampel storageAccountName menggabungkan maksimum 11 karakter dari parameter projectName dengan nilai uniqueString yang terdiri dari 13 karakter.
Simpan salinan templat ke komputer lokal Anda dengan ekstensi .json , misalnya, azuredeploy.json. Anda menyebarkan template ini nanti dalam tutorial.
Masuk ke Azure
Untuk mulai bekerja dengan Azure PowerShell atau Azure CLI untuk menyebarkan templat, masuk dengan kredensial Azure Anda.
Connect-AzAccount
Jika Anda memiliki beberapa langganan Azure, pilih langganan yang ingin Anda gunakan. Ganti [SubscriptionID/SubscriptionName] dan kurung siku [] dengan informasi langganan Anda:
Set-AzContext [SubscriptionID/SubscriptionName]
Buat grup sumber daya
Saat menyebarkan templat, Anda menentukan grup sumber daya untuk sumber daya. Sebelum menjalankan perintah penyebaran, buat grup sumber daya dengan Azure CLI atau Azure PowerShell. Untuk memilih antara Azure PowerShell dan Azure CLI, pilih tab di bagian kode berikut. Contoh CLI dalam artikel ini ditulis untuk shell Bash.
$projectName = Read-Host -Prompt "Enter a project name that is used to generate resource and resource group names"
$resourceGroupName = "${projectName}rg"
New-AzResourceGroup `
-Name $resourceGroupName `
-Location "Central US"
Menyebarkan templat
Gunakan satu atau kedua opsi penyebaran untuk menyebarkan template.
$projectName = Read-Host -Prompt "Enter the same project name"
$templateFile = Read-Host -Prompt "Enter the template file path and file name"
$resourceGroupName = "${projectName}rg"
New-AzResourceGroupDeployment `
-Name DeployLocalTemplate `
-ResourceGroupName $resourceGroupName `
-TemplateFile $templateFile `
-projectName $projectName `
-verbose
Untuk mempelajari selengkapnya tentang menyebarkan templat dengan menggunakan Azure PowerShell, lihat Menyebarkan sumber daya dengan templat ARM dan Azure PowerShell.
Membersihkan sumber daya
Untuk membersihkan sumber daya yang Anda sebarkan, hapus grup sumber daya.
- Dari portal Microsoft Azure, pilih Grup sumber daya dari menu sebelah kiri.
- Masukkan nama grup sumber daya di bidang Filter menurut nama .
- Pilih nama grup sumber daya.
- Pilih Hapus grup sumber daya dari menu atas.
Langkah berikutnya
Anda mempelajari cara menyebarkan template lokal. Dalam tutorial berikutnya, Anda memisahkan templat menjadi templat utama dan templat tertaut. Anda juga mempelajari cara menyimpan dan mengamankan templat yang ditautkan.