자습서: 로컬 ARM 템플릿 배포

로컬 머신에서 ARM 템플릿(Azure Resource Manager 템플릿)을 배포하는 방법을 알아봅니다. 완료하는 데 8분 정도 걸립니다.

이 자습서는 시리즈의 첫 번째 자습서입니다. 시리즈를 진행하면서 연결된 템플릿을 만들어서 템플릿을 모듈화하고, 연결된 계정을 스토리지 계정에 저장하고, SAS 토큰을 사용하여 연결된 템플릿을 보호하고, 템플릿을 배포하는 DevOps 파이프라인을 만드는 방법을 알아볼 수 있습니다. 이 시리즈에서는 템플릿 배포에 중점을 둡니다. 템플릿 개발을 알아보려면 초보자를 위한 자습서를 참조하세요.

도구 가져오기

먼저 템플릿을 배포하는 데 필요한 도구가 있는지 확인합니다.

명령줄 배포

템플릿을 배포하려면 Azure PowerShell 또는 Azure CLI가 필요합니다. 설치 지침은 다음을 참조하세요.

Azure PowerShell 또는 Azure CLI가 설치되면 처음으로 로그인해야 합니다. 도움을 받으려면 로그인 - PowerShell 또는 로그인 - Azure CLI를 참조하세요.

편집기(선택 사항)

템플릿은 JSON 파일입니다. 템플릿을 검토/편집하려면 적합한 JSON 편집기가 필요합니다. Resource Manager 도구 확장이 있는 Visual Studio Code를 사용하는 것이 좋습니다. 이러한 도구를 설치해야 하는 경우 빠른 시작: Visual Studio Code를 사용하여 ARM 템플릿 만들기를 참조하세요.

템플릿 검토

템플릿은 스토리지 계정, App Service 계획 및 웹앱을 배포합니다. 템플릿을 만드는 데 관심이 있으면 빠른 시작 템플릿에 대한 자습서를 진행하면 됩니다. 단, 이 자습서를 완료하는 데는 필요하지 않습니다.

{
  "$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": "2023-01-01",
      "name": "[variables('storageAccountName')]",
      "location": "[parameters('location')]",
      "sku": {
        "name": "[parameters('storageSKU')]"
      },
      "kind": "StorageV2",
      "properties": {
        "supportsHttpsTrafficOnly": true
      }
    },
    {
      "type": "Microsoft.Web/serverfarms",
      "apiVersion": "2022-09-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": "2022-09-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]"
    }
  }
}

Important

스토리지 계정 이름은 3자에서 24자 사이의 고유한 이름이어야 하고 숫자소문자만 사용해야 합니다. 샘플 템플릿의 storageAccountName 변수는 projectName 매개 변수의 최대 11자를 uniqueString 값 13자로 결합합니다.

확장명이 .json인 템플릿(예: azuredeploy.json)의 복사본을 로컬 컴퓨터에 저장합니다. 이 템플릿은 자습서의 뒷부분에서 배포합니다.

Azure에 로그인

Azure PowerShell/Azure CLI를 사용하여 템플릿을 배포하기 시작하려면 Azure 자격 증명으로 로그인합니다.

Connect-AzAccount

Azure 구독이 여러 개 있는 경우 사용할 구독을 선택합니다. [SubscriptionID/SubscriptionName] 및 대괄호 []을(를) 구독 정보로 바꿉니다.

Set-AzContext [SubscriptionID/SubscriptionName]

리소스 그룹 만들기

템플릿을 배포하는 경우 리소스를 포함할 리소스 그룹을 지정합니다. 배포 명령을 실행하기 전에 먼저 Azure CLI 또는 Azure PowerShell을 사용하여 리소스 그룹을 만듭니다. Azure PowerShell과 Azure CLI 중에서 선택하려면 다음 코드 섹션에서 해당 탭을 선택합니다. 이 문서의 CLI 예제는 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"

템플릿 배포

하나 또는 두 가지 배포 옵션을 사용하여 템플릿을 배포합니다.

$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

Azure PowerShell을 사용하여 템플릿을 배포하는 방법에 대해 자세히 알아보려면 ARM 템플릿과 Azure PowerShell을 사용하여 리소스 배포를 참조하세요.

리소스 정리

리소스 그룹을 삭제하여 배포된 리소스를 정리합니다.

  1. Azure Portal의 왼쪽 메뉴에서 리소스 그룹을 선택합니다.
  2. 이름으로 필터링 필드에서 리소스 그룹 이름을 입력합니다.
  3. 해당 리소스 그룹 이름을 선택합니다.
  4. 위쪽 메뉴에서 리소스 그룹 삭제를 선택합니다.

다음 단계

로컬 템플릿을 배포하는 방법을 알아보았습니다. 다음 자습서에서는 템플릿을 기본 템플릿과 연결된 템플릿으로 분리하고 연결된 템플릿을 저장하고 보호하는 방법을 알아봅니다.