如何通过ARM模板输出返回Redis主键? [英] How to return Redis primaryKey via ARM template output?

查看:19
本文介绍了如何通过ARM模板输出返回Redis主键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试借助下面列出的 ARM 模板部署 Redis - 然后返回其主键(Azure 门户中的访问密钥"下的 Redis 秘密字符串 ->主"):

但是,我从我的管道AzureResourceManagerTemplateDeployment@3"收到错误消息;任务:

<块引用>

[错误]无法评估模板输出:RedisCachePassword".请查看错误详情和部署操作.请参阅

如果您知道自己在做什么,那么您应该可以这样设置:

<代码>{"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#","contentVersion": "1.0.0.0",参数": {redisCacheName":{"defaultValue": "myredisinstance",类型":字符串"}},变量":{"resourceId": "[resourceId('Microsoft.Cache/Redis', parameters('redisCacheName'))]","apiVersion": "[providers('Microsoft.Cache', 'redis').apiVersions[0]]"},输出":{RedisCachePassword":{类型":字符串","value": "[listKeys(variables('resourceId'), variables('apiVersion')).primaryKey]"}},资源": []}

I am trying to deploy Redis with the help of the ARM template listed below - and then return its primary key (the secret string available in Azure portal for Redis under "Access keys" -> "Primary"):

However I get the error message from my pipeline "AzureResourceManagerTemplateDeployment@3" task:

[error]Unable to evaluate template outputs: 'RedisCachePassword'. Please see error details and deployment operations. Please see https://aka.ms/arm-debug for usage details.

[error]Details:

[error]DeploymentOutputEvaluationFailed: The template output 'RedisCachePassword' is not valid: The language expression property 'primaryKey' can't be evaluated..

What is please wrong with my ARM template below? And how to be able to find the correct names in such cases?

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "redisCacheName": {
            "defaultValue": "my-redis",
            "type": "String"
        }
    },
    "variables": {
        "resourceName": "[concat(resourceGroup().name, '-', parameters('redisCacheName'))]"
    },
    "outputs": {
      "RedisCacheEndpoint": {
        "type": "string",
        "value": "[concat(reference(variables('resourceName')).hostName, ':', reference(variables('resourceName')).sslPort)]"
      },
      "RedisCachePassword": {
        "type": "string",
        "value": "[reference(variables('resourceName')).accessKeys.primaryKey]"
      }
    },
    "resources": [
        {
            "type": "Microsoft.Cache/Redis",
            "apiVersion": "2019-07-01",
            "name": "[variables('resourceName')]",
            "location": "[resourceGroup().location]",
            "properties": {
                "sku": {
                    "name": "Basic",
                    "family": "C",
                    "capacity": 1
                },
                "enableNonSslPort": false
            }
        }
    ]
}

Why does not [reference(variables('resourceName')).accessKeys.primaryKey] work?

解决方案

Be aware that those outputs are in some ways quite visible. You might be better off invoking the listKeys command outside of your outputs. You can use it in other templates or execute the command separately via AzureCLI or Powershell.

If you know what you are doing, this is how you should be able to set it up:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "redisCacheName": {
            "defaultValue": "myredisinstance",
            "type": "String"
        }
    },
    "variables": {
        "resourceId": "[resourceId('Microsoft.Cache/Redis', parameters('redisCacheName'))]",
        "apiVersion": "[providers('Microsoft.Cache', 'redis').apiVersions[0]]"
    },
    "outputs": {
      "RedisCachePassword": {
        "type": "string",
        "value": "[listKeys(variables('resourceId'), variables('apiVersion')).primaryKey]"
      }
    },
    "resources": []
}

Here is some more information about how this works in general.

To "debug" such things, I like to use https://resources.azure.com, and look at the output and the "actions" tab:

这篇关于如何通过ARM模板输出返回Redis主键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆