배포 스택 업데이트 및 삭제
배포 스택을 사용하면 표준 프로세스 및 템플릿을 사용하여 Azure 리소스를 관리할 수 있습니다. 애플리케이션이 변경되면 애플리케이션을 구성하는 리소스도 변경됩니다. 관리되는 리소스를 추가하고 제거하는 것은 수명 주기 관리의 중요한 부분입니다.
배포 스택을 사용하여 스프린트 1 및 예금 애플리케이션의 초기 배포를 완료했습니다. 이제 애플리케이션에 새로운 서비스를 도입하는 스프린트 2를 준비해야 합니다. 배포 스택과 관리되는 리소스를 업데이트하고 삭제하는 방법에 대해 자세히 알아보고 싶습니다.
이 단원에서는 Bicep 파일에 리소스를 추가하여 배포 스택을 업데이트하는 방법을 알아봅니다. 또한 배포 스택과 해당 관리되는 리소스를 삭제하는 방법도 알아봅니다.
참고 항목
이 단원의 명령은 개념을 설명하기 위해 표시된 것입니다. 명령을 아직 실행하지 마세요. 여기에서 학습하는 내용을 곧 연습할 예정입니다.
배포 스택 업데이트
애플리케이션이 발전함에 따라 해당 리소스도 발전합니다. 새로운 서비스와 기능이 추가되면 배포 스택과 해당 관리되는 리소스를 어떻게 업데이트하나요? 어떤 상황에서 배포 스택을 업데이트해야 하나요? 새 리소스를 추가하거나 기존 관리되는 리소스의 속성을 변경하려면 배포 스택을 업데이트해야 합니다.
스택 업데이트는 ARM JSON 템플릿, Bicep 파일 또는 템플릿 사양에 정의된 리소스를 업데이트하는 것을 의미합니다. 템플릿 파일이 변경되면 적절한 명령을 사용하여 배포 스택을 업데이트합니다.
예금 애플리케이션이 새 Azure SQL Database를 추가해야 하고 배포 스택에서 데이터베이스를 관리해야 한다고 가정해 보겠습니다. 새 데이터베이스를 추가하기 위해 Bicep 파일을 업데이트하여 새 Azure SQL 서버 및 데이터베이스를 정의합니다.
// Parameters
@description('The location for all resources.')
param location string = 'eastus'
@description('The name of the SQL database.')
param sqlDatabaseName string = 'sqldb-${uniqueString(resourceGroup().id)}'
@description('The password of the admin user.')
param sqlServerAdminUserName string
@description('The name of the admin user.')
@secure()
param sqlServerAdminPassword string
@description('The name of the SQL server.')
param sqlServerName string = 'sql-${uniqueString(resourceGroup().id)}'
@description('The name of the web application.')
param webApplicationName string = 'webapp-${uniqueString(resourceGroup().id)}'
// Variables
@description('The name of the app service plan.')
var appServicePlanName = 'plan-deposits'
// Resource - App Service Plan
resource appServicePlan 'Microsoft.Web/serverfarms@2023-12-01' = {
name: appServicePlanName
location: location
sku: {
name: 'F1'
capacity: 1
}
}
// Resource - Web App
resource webApplication 'Microsoft.Web/sites@2023-12-01' = {
name: webApplicationName
location: location
properties: {
serverFarmId: appServicePlan.id
}
}
// Resource - SQL Server
resource sqlServer 'Microsoft.Sql/servers@2021-11-01' ={
name: sqlServerName
location: location
properties: {
administratorLogin: sqlServerAdminUserName
administratorLoginPassword: sqlServerAdminPassword
}
}
// Resource - SQL Database
resource sqlServerDatabase 'Microsoft.Sql/servers/databases@2021-11-01' = {
parent: sqlServer
name: sqlDatabaseName
location: location
sku: {
name: 'Standard'
tier: 'Standard'
}
}
강조 표시된 코드는 예금 애플리케이션을 위한 새로운 Azure SQL Database를 정의합니다. 새 리소스가 정의되면 배포 스택을 업데이트해야 합니다.
Azure CLI를 사용하여 배포 스택을 업데이트하려면 az stack group create
명령을 사용합니다.
az stack group create \
--name stack-deposits \
--resource-group rg-depositsApplication \
--template-file ./main.bicep \
--action-on-unmanage detachAll \
--deny-settings-mode none
참고 항목
Azure CLI에는 배포 스택을 업데이트하는 전용 명령이 없습니다. 스택을 업데이트하려면 create 명령을 사용합니다.
스택에서 업데이트를 수행하면 현재 구독에 스택이 이미 존재한다는 메시지가 표시됩니다. 관리되지 않는 작업 매개 변수의 값이 변경되면 경고가 새 값을 알려 줍니다.
스택이 새 리소스를 관리하고 있는지 확인하려면 az stack group show
명령을 사용합니다.
az stack group show \
--resource-group rg-depositsApplication
--name stack-deposits
{
"actionOnUnmanage": {
"managementGroups": "detach",
"resourceGroups": "detach",
"resources": "detach"
},
"bypassStackOutOfSyncError": null,
"correlationId": ".",
"debugSetting": null,
"deletedResources": [],
"denySettings": {
"applyToChildScopes": false,
"excludedActions": null,
"excludedPrincipals": null,
"mode": "none"
},
"deploymentId": "/subscriptions/././rg-depositsApplication/./Microsoft.Resources/deployments/stack-deposits",
"deploymentScope": null,
"description": null,
"detachedResources": [],
"duration": "PT2M53.2734284S",
"error": null,
"failedResources": [],
"id": "/subscriptions/././rg-depositsApplication/./Microsoft.Resources/deploymentStacks/stack-deposits",
"location": null,
"name": "stack-deposits",
"outputs": null,
"parameters": {
"sqlServerAdminPassword": {
"reference": null,
"type": "securestring",
"value": ""
},
"sqlServerAdminUserName": {
"reference": null,
"type": "string",
"value": "sqladmin"
}
},
"parametersLink": null,
"provisioningState": "succeeded",
"resourceGroup": "rg-depositsApplication",
"resources": [
{
"denyStatus": "none",
"id": "/subscriptions/././rg-depositsApplication/././servers/sql-eque2jlrboltq",
"resourceGroup": "rg-depositsApplication",
"status": "managed"
},
{
"denyStatus": "none",
"id": "/subscriptions/././rg-depositsApplication/././servers/sql-eque2jlrboltq/databases/sqldb-eque2jlrboltq",
"resourceGroup": "rg-depositsApplication",
"status": "managed"
},
{
"denyStatus": "none",
"id": "/subscriptions/././rg-depositsApplication/././serverfarms/plan-deposits",
"resourceGroup": "rg-depositsApplication",
"status": "managed"
},
{
"denyStatus": "none",
"id": "/subscriptions/./resourceGroups/rg-depositsApplication/././sites/webapp-eque2jlrboltq",
"resourceGroup": "rg-depositsApplication",
"status": "managed"
}
],
"systemData": {
"createdAt": "2024-01-01T00:00:01.000000+00:00",
"createdBy": "depositsapplication@contoso.com",
"createdByType": "User",
"lastModifiedAt": "2024-01-01T00:00:01.000000+00:00",
"lastModifiedBy": "depositsapplication@contoso.com",
"lastModifiedByType": "User"
},
"tags": {},
"template": null,
"templateLink": null,
"type": "Microsoft.Resources/deploymentStacks"
}
강조 표시된 코드는 배포 스택에서 관리되는 새로운 Azure SQL 서버 및 Azure SQL Database를 보여 줍니다.
Azure PowerShell을 사용하여 배포 스택을 업데이트하려면 Set-AzResourceGroupDeploymentStack
명령을 사용합니다.
Set-AzResourceGroupDeploymentStack `
-Name stack-deposits `
-ResourceGroupName rg-depositsApplication `
-TemplateFile ./main.bicep `
-ActionOnUnmanage DetachAll `
-DenySettingsMode None
스택이 새 리소스를 관리하고 있는지 확인하려면 Get-AzResourceGroupDeploymentStack
명령을 사용합니다.
Get-AzResourceGroupDeploymentStack `
-ResourceGroupName rg-depositsApplication `
-Name stack-deposits
Id : /subscriptions/././rg-depositsApplication/././deploymentStacks/stack-deposits
Name : stack-deposits
ProvisioningState : succeeded
resourcesCleanupAction : detach
resourceGroupsCleanupAction : detach
managementGroupsCleanupAction : detach
CorrelationId : .
DenySettingsMode : none
CreationTime(UTC) : 1/01/2024 0:00:01 AM
DeploymentId : /subscriptions/././rg-depositsApplication/././deployments/stack-deposits
Resources : /subscriptions/././rg-depositsApplication/././serverfarms/plan-deposits
/subscriptions/././rg-depositsApplication/././sites/webapp-eque2jlrboltq
/subscriptions/././rg-depositsApplication/././servers/sql-eque2jlrboltq
/subscriptions/././rg-depositsApplication/././servers/sql-eque2jlrboltq/databases/sqldb-eque2jlrboltq
Parameters :
Name Type Value
======================== ========================= ==========
sqlServerAdminUserName string "sqladmin"
sqlServerAdminPassword securestring ""
강조 표시된 코드는 배포 스택에서 관리되는 새로운 Azure SQL 서버 및 Azure SQL Database를 보여 줍니다.
다음 모듈에서는 관리되는 리소스 추가, 업데이트, 분리, 삭제 등 리소스 수명 주기 관리 작업을 진행합니다.
배포 스택 삭제
신뢰할 수 있는 리소스 정리는 배포 스택의 핵심 기능입니다. 배포 스택을 삭제하면 관리되는 리소스, 리소스 그룹 및 관리 그룹도 삭제할 수 있습니다. 단일 API 호출을 사용하면 종속성을 이해할 필요가 없습니다. 배포 스택 만들기 및 업데이트와 마찬가지로 관리되지 않는 작업 매개 변수는 Azure가 분리된 리소스를 처리하는 방법을 결정합니다.
참고 항목
이 모듈에서는 리소스 그룹 범위 배포 스택을 사용하여 작업합니다. 이 상황에서는 리소스 그룹이 스택에서 관리되지 않습니다. 관리되지 않는 작업 매개 변수의 값이 '모두 삭제'이더라도 스택이 존재하는 리소스 그룹이 삭제되지 않습니다. 스택과 해당 리소스가 삭제된 후에는 리소스 그룹을 삭제해야 합니다.
Azure CLI를 사용하여 배포 스택을 삭제하려면 az stack group delete
명령을 사용합니다. --action-on-unmanaged
인수는 Azure가 분리된 리소스, 리소스 그룹 및 관리 그룹을 처리하는 방법을 결정합니다.
az stack group delete \
--name stack-deposits \
--resource-group rg-depositsApplication \
--action-on-unmanage deleteAll
Azure PowerShell을 사용하여 배포 스택을 삭제하려면 Remove-AzResourceGroupDeploymentStack
명령을 사용합니다. -ActionOnUnmanage
인수는 Azure가 분리된 리소스, 리소스 그룹 및 관리 그룹을 처리하는 방법을 결정합니다.
Remove-AzResourceGroupDeploymentStack `
-Name stack-deposits `
-ResourceGroupName rg-depositsApplication `
-ActionOnUnmanage -DeleteAll