Quickstart: Create an Azure Cache for Redis using an ARM template

Learn how to create an Azure Resource Manager template (ARM template) that deploys an Azure Cache for Redis. The cache can be used with an existing storage account to keep diagnostic data. You also learn how to define which resources are deployed and how to define parameters that are specified when the deployment is executed. You can use this template for your own deployments, or customize it to meet your requirements. Currently, diagnostic settings are shared for all caches in the same region for a subscription. Updating one cache in the region affects all other caches in the region.

An Azure Resource Manager template is a JavaScript Object Notation (JSON) file that defines the infrastructure and configuration for your project. The template uses declarative syntax. You describe your intended deployment without writing the sequence of programming commands to create the deployment.

If your environment meets the prerequisites and you're familiar with using ARM templates, select the Deploy to Azure button. The template will open in the Azure portal.

Button to deploy the Resource Manager template to Azure.

Prerequisites

  • Azure subscription: If you don't have an Azure subscription, create a free account before you begin.
  • A storage account: To create one, see Create an Azure Storage account. The storage account is used for diagnostic data.

Review the template

The template used in this quickstart is from Azure Quickstart Templates.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "metadata": {
    "_generator": {
      "name": "bicep",
      "version": "0.22.6.54827",
      "templateHash": "17110451938184928271"
    }
  },
  "parameters": {
    "redisCacheName": {
      "type": "string",
      "defaultValue": "[format('redisCache-{0}', uniqueString(resourceGroup().id))]",
      "metadata": {
        "description": "Specify the name of the Azure Redis Cache to create."
      }
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
        "description": "Location of all resources"
      }
    },
    "redisCacheSKU": {
      "type": "string",
      "defaultValue": "Standard",
      "allowedValues": [
        "Basic",
        "Standard",
        "Premium"
      ],
      "metadata": {
        "description": "Specify the pricing tier of the new Azure Redis Cache."
      }
    },
    "redisCacheFamily": {
      "type": "string",
      "defaultValue": "C",
      "allowedValues": [
        "C",
        "P"
      ],
      "metadata": {
        "description": "Specify the family for the sku. C = Basic/Standard, P = Premium."
      }
    },
    "redisCacheCapacity": {
      "type": "int",
      "defaultValue": 1,
      "allowedValues": [
        0,
        1,
        2,
        3,
        4,
        5,
        6
      ],
      "metadata": {
        "description": "Specify the size of the new Azure Redis Cache instance. Valid values: for C (Basic/Standard) family (0, 1, 2, 3, 4, 5, 6), for P (Premium) family (1, 2, 3, 4, 5)"
      }
    },
    "builtInAccessPolicyName": {
      "type": "string",
      "defaultValue": "Data Reader",
      "allowedValues": [
        "Data Owner",
        "Data Contributor",
        "Data Reader"
      ],
      "metadata": {
        "description": "Specify name of Built-In access policy to use as assignment."
      }
    },
    "builtInAccessPolicyAssignmentName": {
      "type": "string",
      "defaultValue": "[format('builtInAccessPolicyAssignment-{0}', uniqueString(resourceGroup().id))]",
      "metadata": {
        "description": "Specify name of custom access policy to create."
      }
    },
    "builtInAccessPolicyAssignmentObjectId": {
      "type": "string",
      "defaultValue": "[newGuid()]",
      "metadata": {
        "description": "Specify the valid objectId(usually it is a GUID) of the Microsoft Entra Service Principal or Managed Identity or User Principal to which the built-in access policy would be assigned."
      }
    },
    "builtInAccessPolicyAssignmentObjectAlias": {
      "type": "string",
      "defaultValue": "[format('builtInAccessPolicyApplication-{0}', uniqueString(resourceGroup().id))]",
      "metadata": {
        "description": "Specify human readable name of principal Id of the Microsoft Entra Application name or Managed Identity name used for built-in policy assignment."
      }
    },
    "customAccessPolicyName": {
      "type": "string",
      "defaultValue": "[format('customAccessPolicy-{0}', uniqueString(resourceGroup().id))]",
      "metadata": {
        "description": "Specify name of custom access policy to create."
      }
    },
    "customAccessPolicyPermissions": {
      "type": "string",
      "defaultValue": "+@connection +get +hget allkeys",
      "metadata": {
        "description": "Specify the valid permissions for the customer access policy to create. For details refer to https://aka.ms/redis/ConfigureAccessPolicyPermissions"
      }
    },
    "customAccessPolicyAssignmentName": {
      "type": "string",
      "defaultValue": "[format('customAccessPolicyAssignment-{0}', uniqueString(resourceGroup().id))]",
      "metadata": {
        "description": "Specify name of custom access policy to create."
      }
    },
    "customAccessPolicyAssignmentObjectId": {
      "type": "string",
      "defaultValue": "[newGuid()]",
      "metadata": {
        "description": "Specify the valid objectId(usually it is a GUID) of the Microsoft Entra Service Principal or Managed Identity or User Principal to which the custom access policy would be assigned."
      }
    },
    "customAccessPolicyAssignmentObjectAlias": {
      "type": "string",
      "defaultValue": "[format('customAccessPolicyApplication-{0}', uniqueString(resourceGroup().id))]",
      "metadata": {
        "description": "Specify human readable name of principal Id of the Microsoft Entra Application name or Managed Identity name used for custom policy assignment."
      }
    }
  },
  "resources": [
    {
      "type": "Microsoft.Cache/redis",
      "apiVersion": "2023-08-01",
      "name": "[parameters('redisCacheName')]",
      "location": "[parameters('location')]",
      "properties": {
        "enableNonSslPort": false,
        "minimumTlsVersion": "1.2",
        "sku": {
          "capacity": "[parameters('redisCacheCapacity')]",
          "family": "[parameters('redisCacheFamily')]",
          "name": "[parameters('redisCacheSKU')]"
        },
        "redisConfiguration": {
          "aad-enabled": "true"
        }
      }
    },
    {
      "type": "Microsoft.Cache/redis/accessPolicyAssignments",
      "apiVersion": "2023-08-01",
      "name": "[format('{0}/{1}', parameters('redisCacheName'), parameters('builtInAccessPolicyAssignmentName'))]",
      "properties": {
        "accessPolicyName": "[parameters('builtInAccessPolicyName')]",
        "objectId": "[parameters('builtInAccessPolicyAssignmentObjectId')]",
        "objectIdAlias": "[parameters('builtInAccessPolicyAssignmentObjectAlias')]"
      },
      "dependsOn": [
        "[resourceId('Microsoft.Cache/redis', parameters('redisCacheName'))]"
      ]
    },
    {
      "type": "Microsoft.Cache/redis/accessPolicies",
      "apiVersion": "2023-08-01",
      "name": "[format('{0}/{1}', parameters('redisCacheName'), parameters('customAccessPolicyName'))]",
      "properties": {
        "permissions": "[parameters('customAccessPolicyPermissions')]"
      },
      "dependsOn": [
        "[resourceId('Microsoft.Cache/redis', parameters('redisCacheName'))]",
        "[resourceId('Microsoft.Cache/redis/accessPolicyAssignments', parameters('redisCacheName'), parameters('builtInAccessPolicyAssignmentName'))]"
      ]
    },
    {
      "type": "Microsoft.Cache/redis/accessPolicyAssignments",
      "apiVersion": "2023-08-01",
      "name": "[format('{0}/{1}', parameters('redisCacheName'), parameters('customAccessPolicyAssignmentName'))]",
      "properties": {
        "accessPolicyName": "[parameters('customAccessPolicyName')]",
        "objectId": "[parameters('customAccessPolicyAssignmentObjectId')]",
        "objectIdAlias": "[parameters('customAccessPolicyAssignmentObjectAlias')]"
      },
      "dependsOn": [
        "[resourceId('Microsoft.Cache/redis', parameters('redisCacheName'))]",
        "[resourceId('Microsoft.Cache/redis/accessPolicies', parameters('redisCacheName'), parameters('customAccessPolicyName'))]"
      ]
    }
  ]
}

The following resources are defined in the template:

Resource Manager templates for the new Premium tier are also available.

To check for the latest templates, see Azure Quickstart Templates and search for Azure Cache for Redis.

Deploy the template

  1. Select the following image to sign in to Azure and open the template.

    Button to deploy the Resource Manager template to Azure.

  2. Select or enter the following values:

    • Subscription: select an Azure subscription used to create the data share and the other resources.
    • Resource group: select Create new to create a new resource group or select an existing resource group.
    • Location: select a location for the resource group. The storage account and the Redis cache must be in the same region. By default the Redis cache uses the same location as the resource group. So, specify the same location as the storage account.
    • Redis Cache Name: enter a name for the Redis cache.
    • Existing Diagnostics Storage Account: enter the resource ID of a storage account. The syntax is /subscriptions/<SUBSCRIPTION ID>/resourceGroups/<RESOURCE GROUP NAME>/providers/Microsoft.Storage/storageAccounts/<STORAGE ACCOUNT NAME>.

    Use the default value for the rest of the settings.

  3. select I agree to the terms and conditions stated above, and the select Purchase.

Review deployed resources

  1. Sign in to the Azure portal.
  2. Open the Redis cache that you created.

Clean up resources

When no longer needed, delete the resource group, which deletes the resources in the resource group.

$resourceGroupName = Read-Host -Prompt "Enter the resource group name"
Remove-AzResourceGroup -Name $resourceGroupName
Write-Host "Press [ENTER] to continue..."

Next steps

In this tutorial, you learnt how to create an Azure Resource Manager template that deploys an Azure Cache for Redis. To learn how to create an Azure Resource Manager template that deploys an Azure Web App with Azure Cache for Redis, see Create a Web App plus Azure Cache for Redis using a template.