Update resources in a deployment stack

Completed

As an application evolves, so does its resources. How do we update a deployment stack and its managed resources when new services and features are added? What situations require us to update a deployment stack?

The deposits application is undergoing significant change. Azure resource properties need to be modified, new resources need to be added, and existing resources need to be removed. You need to learn more about when to update a deployment stack and how to update existing managed resources.

In this unit, you learn about what situations call for an update to a deployment stack. You also learn how to modify resources managed by a deployment stack.

Note

The commands in this unit are shown to illustrate concepts. Don't run the commands yet. You'll practice what you learn here soon.

Updating a deployment stack

Over time, the resources that make up an application change. Properties of existing resources need to be modified, resources need to be added or deleted, or an application needs to integrate resources that were deployed through other approaches. A deployment stack can be updated to implement the changes in our applications. What situations require us to update a deployment stack?

  • Modifying the property of a managed resource
  • Adding an existing resource as a managed resource
  • Adding a new managed resource
  • Detaching a managed resource
  • Deleting a managed resource

How are these changes implemented? As we discussed in the last module, deployment stacks manage resources that are defined in a Bicep file, ARM JSON template, or template spec. When you create a deployment stack, you reference one of these files to deploy your resources. The same is true for updating a deployment stack. To update resources managed by a deployment stack, update the underlying template file.

Updating an existing managed resource

It's common practice to modify your resources deployed in Azure. You may need to change a property value of a resource to incorporate a new feature or enhance its functionality. If you currently use infrastructure as code to define your resources in Azure, you're familiar with how to modify the properties of a resource. With deployment stacks, the process is identical. Make the change to the resource in your Bicep file and run an update operation on the stack.

Let's consider our Bicep file from the last module. Our file defines an app service plan, a web app, and an Azure SQL server and database. We want to modify the SKU of the app service plan from the F1 SKU to the S1 SKU.

// 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: 'S1'
    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'
  }
}

With the Bicep file modified, we want to update the deployment stack so that the changes made to the resources in the Bicep file are implemented.

To update a deployment stack using Azure CLI, use the az stack group create command.

az stack group create \
    --name stack-deposits \
    --resource-group rg-depositsApplication \
    --template-file ./main.bicep \
    --action-on-unmanage detachAll \
    --deny-settings-mode none

After the stack update is complete, we want to verify that the app service plan is now running on the S1 SKU.

To view the configuration of the app service plan using Azure CLI, use the az appservice plan show command

az appservice plan show \
    --name plan-deposits
    --resource-group rg-depositsApplication

The output shows us that the update was successful and the app service plan is now running on the S1 SKU.

"sku": {
    "capacity": 1,
    "family": "S",
    "name": "S1",
    "size": "S1",
    "tier": "Standard"
},

With the Bicep file modified, we want to update the deployment stack so that the changes made to the resources in the Bicep file are implemented.

To update a deployment stack using Azure PowerShell, use the Set-AzResourceGroupDeploymentStack command.

Set-AzResourceGroupDeploymentStack `
    -Name stack-deposits `
    -ResourceGroupName rg-depositsApplication `
    -TemplateFile ./main.bicep `
    -ActionOnUnmanage DetachAll `
    -DenySettingsMode None

After the stack update is complete, we want to verify that the app service plan is now running on the S1 SKU.

To view the configuration of the app service plan using Azure PowerShell, use the Get-AzAppServicePlan command

$plan = Get-AzAppServicePlan `
    -ResourceGroupName rg-depositsApplication `
    -Name plan-deposits
$sku = $plan.Sku
$sku

The output shows us that the update was successful and the app service plan is now running on the S1 SKU.

Name         : S1
Tier         : Standard
Size         : S1
Family       : S
Capacity     : 1