クイックスタート: ARM テンプレートを使用して Azure Cache for Redis を作成する

Azure Cache for Redis をデプロイする Azure Resource Manager テンプレート (ARM テンプレート) を作成する方法について説明します。 キャッシュを既存のストレージ アカウントで使用することで、診断データを保持することができます。 さらに、デプロイ対象のリソースを定義する方法と、デプロイの実行時に指定されるパラメーターを定義する方法についても説明します。 このテンプレートは、独自のデプロイに使用することも、要件に合わせてカスタマイズすることもできます。 現時点では、診断設定は、サブスクリプションの同じリージョン内のすべてのキャッシュで共有されます。 領域内の 1 つのキャッシュを更新すると、領域内の他のすべてのキャッシュに反映されます。

Azure Resource Manager テンプレートは JavaScript Object Notation (JSON) ファイルであり、プロジェクトのインフラストラクチャと構成が定義されています。 このテンプレートでは、宣言型の構文が使用されています。 デプロイしようとしているものを、デプロイを作成する一連のプログラミング コマンドを記述しなくても記述できます。

環境が前提条件を満たしていて、ARM テンプレートの使用に慣れている場合は、 [Azure へのデプロイ] ボタンを選択します。 Azure portal でテンプレートが開きます。

Button to deploy the Resource Manager template to Azure.

前提条件

  • Azure サブスクリプション:Azure サブスクリプションをお持ちでない場合は、開始する前に 無料アカウント を作成してください。
  • ストレージ アカウント:これを作成するには、「Azure Storage アカウントの作成」を参照してください。 ストレージ アカウントは、診断データに使用されます。

テンプレートを確認する

このクイックスタートで使用されるテンプレートは Azure クイックスタート テンプレートからのものです。

{
  "$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'))]"
      ]
    }
  ]
}

このテンプレートでは、次のリソースが定義されています。

新しい Premium レベルの Resource Manager テンプレートも利用できます。

最新のテンプレートを確認する場合は、「Azure クイックスタート テンプレート」で Azure Cache for Redis を検索してください。

テンプレートのデプロイ

  1. Azure にサインインし、テンプレートを開くには次の画像を選択します。

    Button to deploy the Resource Manager template to Azure.

  2. 次の値を選択または入力します。

    • [サブスクリプション] : データ共有とその他のリソースの作成に使用する Azure サブスクリプションを選択します。
    • [リソース グループ] : [新規作成] を選択して新しいリソース グループを作成するか、既存のリソース グループを選択します。
    • 場所: リソース グループの場所を選択します。 ストレージ アカウントと Redis Cache は同じリージョンに存在する必要があります。 既定では、Redis Cache はリソース グループと同じ場所を使用します。 そのため、ストレージ アカウントと同じ場所を指定します。
    • Redis Cache 名: Redis Cache の名前を入力します。
    • 既存の診断ストレージ アカウント: ストレージ アカウントのリソース ID を入力します。 構文は /subscriptions/<SUBSCRIPTION ID>/resourceGroups/<RESOURCE GROUP NAME>/providers/Microsoft.Storage/storageAccounts/<STORAGE ACCOUNT NAME> です。

    残りの設定については既定値を使用します。

  3. [上記の使用条件に同意する] を選択し、 [購入] を選択します。

デプロイされているリソースを確認する

  1. Azure portal にサインインします。
  2. 作成した Redis Cache を開きます。

リソースをクリーンアップする

不要になったら、リソース グループを削除します。これにより、リソース グループ内のリソースが削除されます。

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

次のステップ

このチュートリアルでは、Azure Cache for Redis をデプロイする Azure Resource Manager テンプレートを作成する方法について説明しました。 Azure Web アプリと Azure Cache for Redis をデプロイする Azure Resource Manager のテンプレートを作成する方法については、「テンプレートを使用して Web アプリと Azure Cache for Redis を作成する」を参照してください。