【问题标题】:ARM Template for Redis Cache failing to deployRedis 缓存的 ARM 模板无法部署
【发布时间】:2019-12-21 12:25:41
【问题描述】:

我正在尝试使用 ARM 模板部署 Redis 缓存,但它一直失败并出现以下错误:

{"code":"DeploymentFailed","message":"至少一个资源部署 手术失败。请列出部署操作以了解详细信息。 用法请见https://aka.ms/arm-debug 详细信息。","详细信息":[{"code":"BadRequest","message":"{\r\n \"error\": {\r\n \"code\": \"LinkedInvalidPropertyId\",\r\n \"message\": \"路径中的属性 id 'GET-PREREQ-existingDiagnosticsStorageAccountId' “properties.storageAccountId”无效。期待完全合格 以“/subscriptions/{subscriptionId}”开头的资源 ID 或 '/providers/{resourceProviderNamespace}/'.\"\r\n }\r\n}"}]}

在线搜索资源,但我无法弄清楚到底出了什么问题。 Redis 缓存资源确实已创建,但部署并未完全成功。以下似乎失败了: https://imgur.com/a/xsp0OqL https://imgur.com/a/mpBBIAm

azuredeployredis.json

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "redisCacheName": {
      "type": "string",
      "defaultValue": "defaultRedisCacheName",
      "metadata": {
        "description": "The name of the Azure Redis Cache to create."
      }
    },
    "redisCacheSKU": {
      "type": "string",
      "allowedValues": [
        "Basic",
        "Standard",
        "Premium"
      ],
      "defaultValue": "Standard",
      "metadata": {
        "description": "The pricing tier of the new Azure Redis Cache."
      }
    },
    "redisCacheFamily": {
      "type": "string",
      "defaultValue": "C",
      "metadata": {
        "description": "The family for the sku."
      },
      "allowedValues": [
        "C",
        "P"
      ]
    },
    "redisCacheCapacity": {
      "type": "int",
      "allowedValues": [
        0,
        1,
        2,
        3,
        4,
        5,
        6
      ],
      "defaultValue": 1,
      "metadata": {
        "description": "The size of the new Azure Redis Cache instance. "
      }
    },
    "enableNonSslPort": {
      "type": "bool",
      "defaultValue": false,
      "metadata": {
        "description": "A boolean value that indicates whether to allow access via non-SSL ports."
      }
    },
    "diagnosticsEnabled": {
      "type": "bool",
      "defaultValue": false,
      "metadata": {
        "description": "A value that indicates whether diagnostics should be saved to the specified storage account."
      }
    },
    "existingDiagnosticsStorageAccountId": {
      "type": "string",
      "metadata": {
        "description": "Existing storage account for diagnostics."
      }
    }
  },
  "resources": [
    {
      "apiVersion": "2015-08-01",
      "name": "[parameters('redisCacheName')]",
      "type": "Microsoft.Cache/Redis",
      "location": "[resourceGroup().location]",
      "properties": {
        "enableNonSslPort": "[parameters('enableNonSslPort')]",
        "sku": {
          "capacity": "[parameters('redisCacheCapacity')]",
          "family": "[parameters('redisCacheFamily')]",
          "name": "[parameters('redisCacheSKU')]"
        }
      },
      "resources": [
        {
          "apiVersion": "2017-05-01-preview",
          "type": "Microsoft.Cache/redis/providers/diagnosticsettings",
          "name": "[concat(parameters('redisCacheName'), '/Microsoft.Insights/', parameters('redisCacheName'))]",
          "location": "[resourceGroup().location]",
          "dependsOn": [
            "[concat('Microsoft.Cache/Redis/', parameters('redisCacheName'))]"
          ],
          "properties": {
            "storageAccountId": "[parameters('existingDiagnosticsStorageAccountId')]",
            "metrics": [
              {
                "timeGrain": "AllMetrics",
                "enabled": "[parameters('diagnosticsEnabled')]",
                "retentionPolicy": {
                  "days": 90,
                  "enabled": "[parameters('diagnosticsEnabled')]"
                }
              }
            ]
          }
        }
      ]
    }
  ]
}

azuredeployredis.parameters.json:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
    "contentVersion": "1.0.0.0",
  "parameters": {
    "redisCacheName": {
      "value": "xyz-redis-cache"
    },
    "existingDiagnosticsStorageAccountId": {
      "value": "GET-PREREQ-existingDiagnosticsStorageAccountId"
    }
  }
}

【问题讨论】:

  • 因为错误消息表明storageAccountId 需要是存储帐户的完整resource id,而不是您的参数文件所指示的GET-PREREQ-existingDiagnosticsStorageAccountId

标签: powershell azure-devops arm-template


【解决方案1】:

我的意思是,错误清楚地表明您需要将 resourceId,而不是资源名称传递给 properties.storageAccountId。它应该是这样的:

/subscriptions/guid/resourceGroups/rgname/providers/Microsoft.Storage/storageAccounts/storagename

您可以使用resourceId() 函数来计算:

resourceId('subscriptionId', 'resourceGroupname', 'Microsoft.Storage/storageAccounts', 'storageaccountname')

仅当存储帐户在不同的订阅和\或资源组中时才需要订阅 ID 和资源组名称

【讨论】:

  • 谢谢!似乎出于某种原因忽略了这一点。我遵循了一个 github 模板并没有看到这个。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-02-11
  • 1970-01-01
  • 1970-01-01
  • 2021-07-28
  • 2016-10-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多