部署失败后获取解析的ARM模板
Get resolved ARM template after failed deployment
是否可以在 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",
"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
}
}
]
}
AzureDeploy.parameters.json
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"environment": {
"value": "dev"
}
}
}
如果此部署在名称或 SKU 等方面失败,我是否能够访问门户或以某种方式查看当脚本为 运行 时这些值是如何解析的?
部署发生在 AzureDevops 的 CD 管道中,我可以控制变量组等,所以我知道传入的是什么,但不知道它是如何解析的。在一个更复杂的模板中,我有一个错误,声称 Id 未在逻辑应用程序 API 连接上设置,但我无法判断该错误是由于我在 concat 函数中使用的变量还是值是确实不正确(根据传入的数据解决问题)。
如果有人熟悉通过 Azure 中的部署 blade 解决这些问题,那么您可能会获得一些关于如何查看更详细视图的提示。
谢谢,
编辑:
下面的代码会在 Visual Studio 2019 年触发 Intellisense,但已确认在部署期间有效。根据评论,VS Code 中没有警告。为简洁起见省略了大部分代码。
{
"$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: https://docs.microsoft.com/en-us/rest/api/resources/deployments/validate -- 但你现在需要使用较旧的 api 版本(例如 2017-05-01)。 . 响应将包含经过全面评估的模板。如果您使用的是旧版本的 PowerShell 或 CLI,则可以使用 -debug 开关查看其余 API 的响应。但请记住,PS/CLI 的较新版本将使用较新的 api 版本,而那些 return 不是完整模板(此时)。
2) /whatif api 也将 return 评估 JSON 但如果您所追求的只是评估的模板,还有更多的事情要做:https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/template-deploy-what-if
有帮助吗?
是否可以在 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",
"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
}
}
]
}
AzureDeploy.parameters.json
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"environment": {
"value": "dev"
}
}
}
如果此部署在名称或 SKU 等方面失败,我是否能够访问门户或以某种方式查看当脚本为 运行 时这些值是如何解析的?
部署发生在 AzureDevops 的 CD 管道中,我可以控制变量组等,所以我知道传入的是什么,但不知道它是如何解析的。在一个更复杂的模板中,我有一个错误,声称 Id 未在逻辑应用程序 API 连接上设置,但我无法判断该错误是由于我在 concat 函数中使用的变量还是值是确实不正确(根据传入的数据解决问题)。
如果有人熟悉通过 Azure 中的部署 blade 解决这些问题,那么您可能会获得一些关于如何查看更详细视图的提示。
谢谢,
编辑:
下面的代码会在 Visual Studio 2019 年触发 Intellisense,但已确认在部署期间有效。根据评论,VS Code 中没有警告。为简洁起见省略了大部分代码。
{
"$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: https://docs.microsoft.com/en-us/rest/api/resources/deployments/validate -- 但你现在需要使用较旧的 api 版本(例如 2017-05-01)。 . 响应将包含经过全面评估的模板。如果您使用的是旧版本的 PowerShell 或 CLI,则可以使用 -debug 开关查看其余 API 的响应。但请记住,PS/CLI 的较新版本将使用较新的 api 版本,而那些 return 不是完整模板(此时)。
2) /whatif api 也将 return 评估 JSON 但如果您所追求的只是评估的模板,还有更多的事情要做:https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/template-deploy-what-if
有帮助吗?