Azure 部署失败后获取已解析的ARM模板
在Azure门户中运行时,在解析变量和参数的情况下,是否可以获得ARM模板 示例如下: AzureDeploy.jsonAzure 部署失败后获取已解析的ARM模板,azure,azure-devops,azure-resource-manager,arm-template,Azure,Azure Devops,Azure Resource Manager,Arm Template,在Azure门户中运行时,在解析变量和参数的情况下,是否可以获得ARM模板 示例如下: AzureDeploy.json { "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "environment": { "type": "string",
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"environment": {
"type": "string",
"defaultValue": "dev",
},
"storageSKU": {
"type": "string",
"defaultValue": "Standard_LRS",
"allowedValues": [
"Standard_LRS",
"Standard_GRS",
"Standard_RAGRS",
"Standard_ZRS",
"Premium_LRS",
"Premium_ZRS",
"Standard_GZRS",
"Standard_RAGZRS"
]
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]"
}
},
"variables": {
"storageAccountName": "[concat('companyname',parameters('environment'),'sa01'))]"
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2019-04-01",
"name": "[variables('storageName')]",
"location": "[parameters('location')]",
"sku": {
"name": "[parameters('storageSKU')]"
},
"kind": "StorageV2",
"properties": {
"supportsHttpsTrafficOnly": true
}
}
]
}
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"environment": {
"value": "dev"
}
}
}
AzureDeploy.parameters.json
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"environment": {
"type": "string",
"defaultValue": "dev",
},
"storageSKU": {
"type": "string",
"defaultValue": "Standard_LRS",
"allowedValues": [
"Standard_LRS",
"Standard_GRS",
"Standard_RAGRS",
"Standard_ZRS",
"Premium_LRS",
"Premium_ZRS",
"Standard_GZRS",
"Standard_RAGZRS"
]
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]"
}
},
"variables": {
"storageAccountName": "[concat('companyname',parameters('environment'),'sa01'))]"
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2019-04-01",
"name": "[variables('storageName')]",
"location": "[parameters('location')]",
"sku": {
"name": "[parameters('storageSKU')]"
},
"kind": "StorageV2",
"properties": {
"supportsHttpsTrafficOnly": true
}
}
]
}
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"environment": {
"value": "dev"
}
}
}
如果此部署在诸如名称或SKU之类的问题上失败,我是否能够访问门户或以某种方式查看在运行脚本时如何解析这些值
部署发生在AzureDevops的CD管道中,我可以控制变量组等。所以我知道传入的是什么,但不知道它是如何解析的。在更复杂的模板中,我有一个错误,声称未在Logic App API连接上设置Id,但我无法判断该错误是否是由于我在concat函数中使用的变量引起的,或者该值是否确实不正确(根据传入的数据解析为OK)
如果任何人都熟悉通过Azure中的刀片部署解决这些问题,那么您可能会有一些关于如何查看更详细视图的提示
谢谢
编辑:
下面的代码在VisualStudio2019中触发Intellisense,但已确认在部署期间工作。根据注释,VS代码中没有警告。为了简洁起见,省略了大部分代码
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"environment": {
"type": "string",
"defaultValue": "dev"
},
"increment": {
"type": "string",
"defaultValue": "01"
},
"keyvaultName": {
"type": "string",
"defaultValue": "randomKeyVaultName",
"metadata": {
"description": "Keyvault Name for deployment"
}
}
},
"variables": {
"uniqueKeyVaultName": "[parameters('keyvaultName')]"
},
"resources": [
{
"type": "Microsoft.KeyVault/vaults/secrets",
"apiVersion": "2016-10-01",
"name": "[concat(variables('uniqueKeyVaultName'), '/407045A0-1B78-47B5-9090-59C0AE9A96F6')]",
"location": "northeurope",
"dependsOn": [
"[resourceId('Microsoft.Resources/deployments', 'cosmosdb_linkedtemplate')]"
],
"properties": {
"contentType": "Graph",
"value": "[concat('{''D'': ''DatabaseName'', ''U'': ''https://randomcosmosdb-',parameters('environment'),'-cdb-',parameters('increment'),'.documents.azure.com'', ''C'': ''CollectionName'', ''K'': ''',reference('cosmosdb_linkedtemplate').outputs.accountKey.value,'''}')]",
"attributes": {
"enabled": true
}
}
}
],
"outputs": {}
}
如果您想查看评估过的模板,您可以做一些事情来获得它,而无需部署: 1) 调用/validate api:--但此时需要使用较旧的api版本(例如2017-05-01)。。。响应将包含完全评估的模板。如果您有较旧版本的PowerShell或CLI,则可以使用-debug开关查看rest API的响应。但请记住,较新版本的PS/CLI将使用较新的apiVersion,而这些版本不会返回完整模板(此时) 2) /whatif api还将返回经过计算的JSON,但如果您只想得到经过计算的模板,那么还需要做更多的工作:
有什么帮助?我只是想澄清一下,这是我从Microsoft文档中获取的一个模板,我刚刚注意到“变量('storageName')”中的打字错误,应该是“变量('storageAccountName')”。我只是在寻找比部署期间生成的标准输出日志更详细的内容。Cheers从部署页面可以看到arm模板的输入内容。这就是你的意思吗?不完全是,我知道输入是什么,因为我在管道中设置了它们,虽然我没有注意到你可以从这个刀片上看到,所以谢谢你。我想看看脚本会是什么样子,如果你能想象它是用输入硬编码的,例如“storageAccountName”:“[concat('companyname',parameters('environment'),'sa01')]”会变成“storageAccountName”:“FakeCompanyDefSa01”我还没有试过,因为我克服了我的困难,但看看链接和其他帖子,这看起来确实是答案。我遇到的问题是在使用concat时转义单引号,IDE不断给出红色的波形。事实证明,它们不是实际的错误,如果忽略它们,字符串连接会很好。不过我以后肯定会用这个。谢谢你的帮助。你正在使用哪个IDE?你能给我寄一份产生这种扭曲的样品吗?(这听起来像一个bug(如果它在VS代码中的话))我在模板中截取了一段有问题的部分,并省略了其余的参考资料供您查看。我使用VS 2019社区版本16.5.4,我刚刚在VS代码版本1.44.2中测试了相同的版本,它很好(没有intellisense警告)。我正在VS代码中使用官方的Microsoft Azure资源管理器扩展。我将在原始问题中用代码发布详细信息。谢谢你。。。知道了。VS代码比VS+更“最新”。。。我会给我们的VS人发邮件。