【问题标题】:Arm Template - Bad JSON content found in the requestArm 模板 - 在请求中发现错误的 JSON 内容
【发布时间】:2021-01-07 15:18:43
【问题描述】:

我正在尝试使用 Arm 模板将访问策略添加到 KeyVault 但我收到错误消息“在请求中发现错误的 JSON 内容” 细节: 内部错误: 代码:错误请求 信息: 错误: 代码:错误请求 消息:在请求中发现错误的 JSON 内容..

我不明白我使用的模板有什么问题。

这是我正在使用的模板:

{  
        "contentVersion": "1.0.0.0",
        "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json",
        "parameters": {
            "keyVault": {
                "type": "string"
            },
            "resourceGroup": {
                "type": "string"
            },
            "subscriptionId": {
                "type": "string"
            },
            "tenantId": {
                "type": "string"
            },
            "objectId": {
                "type": "string"
            }
        },
        "resources": [
            {
                "name": "[concat(take(deployment().name, 50))]",
                "apiVersion": "2017-05-10",
                "resourceGroup": "[parameters('resourceGroup')]",
                "subscriptionId": "[parameters('subscriptionId')]",
                "type": "Microsoft.Resources/deployments",
                "properties": {
                    "mode": "Incremental",
                    "template": {
                        "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
                        "contentVersion": "1.0.0.0",
                        "resources": [
                            {
                                "type": "Microsoft.KeyVault/vaults/accessPolicies",
                                "name": "[concat(parameters('keyVault'), '/add')]",
                                "apiVersion": "2018-02-14",
                                "properties": {
                                    "accessPolicies": [
                                        {
                                            "tenantId": "[parameters('tenantId')]",
                                            "objectId": "[parameters('objectId')]",
                                            "permissions": {
                                                "keys": [
                                                    "get",
                                                    "list"
                                                ],
                                                "secrets": [
                                                    "get",
                                                    "list"
                                                ],
                                                "certificates": [
                                                    "get",
                                                    "list"
                                                ]
                                            }
                                        }
                                    ]
                                }
                            }
                        ]
                    }
                }
            }
        ]
    }

【问题讨论】:

  • 您在问题中的代码缺少 { 作为第一个字符。其余的看起来还可以。
  • 我确实有 { 作为第一个字符,但我收到了这个错误
  • 是的,这看起来不错,除非您将一些垃圾传递给参数
  • 怎么样?你的问题解决了吗?
  • 嗨@AdyM,很高兴您的问题已得到解决。请单击答案旁边的复选标记将其从灰色切换为填写以接受它作为答案,以便帮助其他人并关闭此查询:)

标签: azure deployment arm-template


【解决方案1】:

如果您只想向现有 Azure Key Vault 添加一些访问策略,我将您的模板修改如下:

{
    "contentVersion": "1.0.0.0",
    "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json",
    "parameters": {
        "keyVault": {
            "type": "string"
        },
        "tenantId": {
            "type": "string"
        },
        "objectId": {
            "type": "string"
        }
    },
    "resources": [{

            "type": "Microsoft.KeyVault/vaults/accessPolicies",
            "name": "[concat(parameters('keyVault'), '/add')]",
            "apiVersion": "2018-02-14",
            "properties": {
                "accessPolicies": [{
                        "tenantId": "[parameters('tenantId')]",
                        "objectId": "[parameters('objectId')]",
                        "permissions": {
                            "keys": [
                                "get",
                                "list"
                            ],
                            "secrets": [
                                "get",
                                "list"
                            ],
                            "certificates": [
                                "get",
                                "list"
                            ]
                        }
                    }
                ]
            }
        }

    ]
}

我已经通过 PowerShell 进行了测试,它可以正常工作。 结果:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-01
    • 1970-01-01
    • 2023-03-20
    • 2017-06-07
    • 1970-01-01
    • 2014-08-24
    • 2016-10-19
    • 1970-01-01
    相关资源
    最近更新 更多