Events
31 Mar, 11 pm - 2 Apr, 11 pm
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register todayThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
In this article, you use Bicep to deploy an Azure Web App that uses Azure Cache for Redis, as well as an App Service plan.
Bicep is a domain-specific language (DSL) that uses declarative syntax to deploy Azure resources. It provides concise syntax, reliable type safety, and support for code reuse. Bicep offers the best authoring experience for your infrastructure-as-code solutions in Azure.
You can use this Bicep file for your own deployments. The Bicep file provides unique names for the Azure Web App, the App Service plan, and the Azure Cache for Redis. If you'd like, you can customize the Bicep file after you save it to your local device to meet your requirements.
For more information about creating Bicep files, see Quickstart: Create Bicep files with Visual Studio Code. To learn about Bicep syntax, see Understand the structure and syntax of Bicep files.
The Bicep file used in this quickstart is from Azure Quickstart Templates.
@description('Describes plan\'s pricing tier and instance size. Check details at https://azure.microsoft.com/en-us/pricing/details/app-service/')
@allowed([
'F1'
'D1'
'B1'
'B2'
'B3'
'S1'
'S2'
'S3'
'P1'
'P2'
'P3'
'P4'
])
param skuName string = 'F1'
@description('Describes plan\'s instance count')
@minValue(1)
@maxValue(7)
param skuCapacity int = 1
@description('The pricing tier of the new Azure Redis Cache.')
@allowed([
'Basic'
'Standard'
])
param cacheSKUName string = 'Basic'
@description('The family for the sku.')
@allowed([
'C'
])
param cacheSKUFamily string = 'C'
@description('The size of the new Azure Redis Cache instance. ')
@minValue(0)
@maxValue(6)
param cacheSKUCapacity int = 0
@description('Location for all resources.')
param location string = resourceGroup().location
var hostingPlanName = 'hostingplan${uniqueString(resourceGroup().id)}'
var webSiteName = 'webSite${uniqueString(resourceGroup().id)}'
var cacheName = 'cache${uniqueString(resourceGroup().id)}'
resource hostingPlan 'Microsoft.Web/serverfarms@2021-03-01' = {
name: hostingPlanName
location: location
tags: {
displayName: 'HostingPlan'
}
sku: {
name: skuName
capacity: skuCapacity
}
properties: {
}
}
resource webSite 'Microsoft.Web/sites@2021-03-01' = {
name: webSiteName
location: location
tags: {
'hidden-related:${hostingPlan.id}': 'empty'
displayName: 'Website'
}
identity: {
type: 'SystemAssigned'
}
properties: {
serverFarmId: hostingPlan.id
httpsOnly: true
}
dependsOn: [
cache
]
}
resource appsettings 'Microsoft.Web/sites/config@2021-03-01' = {
parent: webSite
name: 'appsettings'
properties: {
CacheConnection: '${cacheName}.redis.cache.windows.net,abortConnect=false,ssl=true,password=${cache.listKeys().primaryKey}'
minTlsVersion: '1.2'
ftpsState: 'FtpsOnly'
}
}
resource cache 'Microsoft.Cache/Redis@2021-06-01' = {
name: cacheName
location: location
tags: {
displayName: 'cache'
}
properties: {
sku: {
name: cacheSKUName
family: cacheSKUFamily
capacity: cacheSKUCapacity
}
}
}
With this Bicep file, you deploy:
@description('Describes plan\'s pricing tier and instance size. Check details at https://azure.microsoft.com/en-us/pricing/details/app-service/')
@allowed([
'F1'
'D1'
'B1'
'B2'
'B3'
'S1'
'S2'
'S3'
'P1'
'P2'
'P3'
'P4'
])
param skuName string = 'F1'
@description('Describes plan\'s instance count')
@minValue(1)
@maxValue(7)
param skuCapacity int = 1
@description('Location for all resources.')
param location string = resourceGroup().location
var hostingPlanName = 'hostingplan${uniqueString(resourceGroup().id)}'
var webSiteName = 'webSite${uniqueString(resourceGroup().id)}'
var redisCacheName = 'cache${uniqueString(resourceGroup().id)}'
var redisAccessPolicyAssignment = 'redisWebAppAssignment'
resource hostingPlan 'Microsoft.Web/serverfarms@2021-03-01' = {
name: hostingPlanName
location: location
tags: {
displayName: 'HostingPlan'
}
sku: {
name: skuName
capacity: skuCapacity
}
properties: {
}
}
resource webSite 'Microsoft.Web/sites@2021-03-01' = {
name: webSiteName
location: location
tags: {
'hidden-related:${hostingPlan.id}': 'empty'
displayName: 'Website'
}
identity: {
type: 'SystemAssigned'
}
properties: {
serverFarmId: hostingPlan.id
httpsOnly: true
}
dependsOn: [
redisEnterprise
]
}
resource appsettings 'Microsoft.Web/sites/config@2021-03-01' = {
parent: webSite
name: 'appsettings'
properties: {
RedisHost: redisEnterprise.properties.hostName
minTlsVersion: '1.2'
ftpsState: 'FtpsOnly'
}
}
resource redisEnterprise 'Microsoft.Cache/redisEnterprise@2024-05-01-preview' = {
name: redisCacheName
location: location
sku: {
name: 'Balanced_B5'
}
identity: {
type: 'None'
}
properties: {
minimumTlsVersion: '1.2'
}
}
resource redisEnterpriseDatabase 'Microsoft.Cache/redisEnterprise/databases@2024-05-01-preview' = {
name: 'default'
parent: redisEnterprise
properties:{
clientProtocol: 'Encrypted'
port: 10000
clusteringPolicy: 'OSSCluster'
evictionPolicy: 'NoEviction'
persistence:{
aofEnabled: false
rdbEnabled: false
}
}
}
resource redisAccessPolicyAssignmentName 'Microsoft.Cache/redisEnterprise/accessPolicyAssignments@2024-03-01' = {
name: redisAccessPolicyAssignment
parent: redisEnterprise
properties: {
accessPolicyName: 'Data Owner'
objectId: webSite.identity.principalId
objectIdAlias: 'webapp'
}
}
With this Bicep file, you deploy:
Save the Bicep file as main.bicep to your local computer.
Deploy the Bicep file using either Azure CLI or Azure PowerShell.
az group create --name exampleRG --location eastus
az deployment group create --resource-group exampleRG --template-file main.bicep
When the deployment finishes, you should see a message indicating the deployment succeeded.
Use the Azure portal, Azure CLI, or Azure PowerShell to list the deployed resources in the resource group.
az resource list --resource-group exampleRG
When no longer needed, use the Azure portal, Azure CLI, or Azure PowerShell to delete the resource group and its resources.
az group delete --name exampleRG
To learn more about Bicep, continue to the following article:
Events
31 Mar, 11 pm - 2 Apr, 11 pm
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register todayTraining
Module
Build your first Bicep template - Training
Learn how to create Bicep templates and create reusable infrastructure as code.
Certification
Microsoft Certified: Azure Developer Associate - Certifications
Build end-to-end solutions in Microsoft Azure to create Azure Functions, implement and manage web apps, develop solutions utilizing Azure storage, and more.
Documentation
Provision Web App with Azure Cache for Redis - Azure Cache for Redis
Use Azure Resource Manager template to deploy web app with Azure Cache for Redis.
Microsoft.Cache/redis 2023-08-01 - Bicep, ARM template & Terraform AzAPI reference
Azure Microsoft.Cache/redis syntax and properties to use in Azure Resource Manager templates for deploying the resource. API version 2023-08-01
Deploy Azure Cache for Redis using Bicep - Azure Cache for Redis
Learn how to use Bicep to deploy an Azure Cache for Redis resource.
Microsoft.Cache/redis - Bicep, ARM template & Terraform AzAPI reference
Azure Microsoft.Cache/redis syntax and properties to use in Azure Resource Manager templates for deploying the resource. API version latest