首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >尝试验证任何ARM模板,但得到:“将值<...MyTemplate...>转换为”....Templates.Schema.Template“的错误

尝试验证任何ARM模板,但得到:“将值<...MyTemplate...>转换为”....Templates.Schema.Template“的错误
EN

Stack Overflow用户
提问于 2019-09-20 20:27:03
回答 1查看 2.3K关注 0票数 1

我试图验证一个arm模板-任何arm模板-但我总是得到相同的错误:

代码语言:javascript
复制
The request content was invalid and could not be deserialized: 'Error converting value "
{
...
}" to type 'Microsoft.WindowsAzure.ResourceStack.Frontdoor.Templates.Schema.Template'. Path 'properties.template', line 1, position 1202.'.

我在蔚蓝门户上创建了ARM模板,并将其插入:

代码语言:javascript
复制
#!/usr/bin/env python3                                                                                                                                                                   

# https://learn.microsoft.com/en-us/azure/azure-resource-manager/resource-group-authoring-templates                                                                                       
t='''                                                                                                                                                                                    
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1",
    "apiProfile": "",
    "parameters": {
        "testType": {
            "type": "string",
            "defaultValue": "Standard_LRS",
            "allowedValues": [
                "Standard_LRS",
                "Standard_ZRS",
                "Standard_GRS",
                "Standard_RAGRS",
                "Premium_LRS"
            ]
        }
    },
    "variables": {
        "testName": "[concat('test', uniqueString(resourceGroup().id))]"
    },
    "functions": [],
    "resources": [
        {
            "name": "[variables('testName')]",
            "type": "Microsoft.Storage/storageAccounts",
            "location": "[resourceGroup().location]",
            "apiVersion": "2015-06-15",
            "dependsOn": [],
            "tags": {
                "displayName": "test"
            },
            "properties": {
                "accountType": "[parameters('testType')]"
            }
        }
    ],
    "outputs": {}
}    

'''
from azure.common.client_factory import get_client_from_cli_profile
from azure.mgmt.resource import ResourceManagementClient
c = get_client_from_cli_profile(ResourceManagementClient)

print(c.deployments.validate('PAWS_Resources', 'food', c.models().DeploymentProperties(mode='incremental', template=t)).error.message)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-09-20 21:18:14

根据医生的说法:

模板对象模板内容。如果希望直接在请求中传递模板语法,而不是链接到现有模板,则可以使用此元素。它可以是JObject或格式良好的JSON字符串。使用templateLink属性或模板属性,但不能同时使用。

但是,它需要一个python对象,而不是一个“格式良好的JSON字符串”。

从模板数据中删除引号可以使其工作。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58034772

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档