gpt4 book ai didi

azure - 如何使用包含资源组和资源的链接模板部署 Arm 模板

转载 作者:行者123 更新时间:2023-12-03 05:21:03 25 4
gpt4 key购买 nike

我有一个“祖 parent ”主模板,它部署另一个链接的“父”模板 4 次,每次都使用不同的组名称(我只显示了第一个资源):

{
"$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"resourcegroupName": {
"type": "string",
"metadata": {
"description": "The name given to the group and all resources it contains by default"
}
},
"resourceGroupLocation": {
"type": "string",
"metadata": {
"description": "The Location of the resource group"
}
},
"templateFolderUri": {
"type": "string",
"metadata": {
"description": "The URI of the template component folder"
}
}
},
"functions": [],
"variables": {},
"resources": [
{
"name": "[concat(parameters('resourceGroupName'), 'Dev')]",
"type": "Microsoft.Resources/deployments",
"apiVersion": "2021-04-01",
"location": "[parameters('resourceGroupLocation')]",
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "[concat(parameters('templateFolderUri'), '/completeNovaRssDeploy.json')]",
"contentVersion": "1.0.0.0"
},
"parameters": {
"resourcegroupName": "[concat(parameters('resourcegroupName'), 'Dev')]",
"resourceGroupLocation": "[parameters('resourceGroupLocation')]",
"templateFolderUri": "[concat(parameters('resourcegroupName'), '/Components')]"
}
}
},

<resource repeated 3 times>

],
"outputs": {}
}

“父”模板还链接其他“子”模板,如下所示:

{
"$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"resourcegroupName": {
"type": "string",
"metadata": {
"description": "The name given to the group and all resources it contains by default"
}
},
"resourceGroupLocation": {
"type": "string",
"metadata": {
"description": "The Location of the resource group"
}
},
"templateFolderUri": {
"type": "string",
"metadata": {
"description": "The URI of the template component folder"
}
}
},
"functions": [],
"variables": {},
"resources": [
{
"comments": "Template for creating the resource group",
"name": "[parameters('resourcegroupName')]",
"type": "Microsoft.Resources/resourceGroups",
"apiVersion": "2021-04-01",
"location": "[parameters('resourceGroupLocation')]",
"properties": {}


},
{
"name": "[parameters('resourceGroupName')]",
"type": "Microsoft.Resources/deployments",
"resourceGroup": "[parameters('resourcegroupName')]",
"apiVersion": "2021-04-01",
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "[concat(parameters('templateFolderUri'), '/servicePlanCreator.json')]",
"contentVersion": "1.0.0.0"
}
},
"dependsOn": [
"[resourceId('Microsoft.Resources/resourceGroups/', parameters('resourceGroupName'))]"
]
},
{
"name": "[concat(parameters('resourceGroupName'), 'Storage')]",
"type": "Microsoft.Resources/deployments",
"resourceGroup": "[parameters('resourcegroupName')]",
"apiVersion": "2021-04-01",
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "[concat(parameters('templateFolderUri'), '/storageAccountTemplate.json')]",
"contentVersion": "1.0.0.0"
},
"parameters": {}
},
"dependsOn": [
"[resourceId('Microsoft.Resources/resourceGroups/', parameters('resourceGroupName'))]"
]
},
{
"name": "[concat(parameters('resourceGroupName'), 'Vault')]",
"type": "Microsoft.Resources/deployments",
"resourceGroup": "[parameters('resourcegroupName')]",
"apiVersion": "2021-04-01",
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "[concat(parameters('templateFolderUri'), '/keyVaultCreator.json')]",
"contentVersion": "1.0.0.0"
},
"parameters": {}
},
"dependsOn": [
"[resourceId('Microsoft.Resources/resourceGroups/', parameters('resourceGroupName'))]"
]
},
{
"name": "[concat(parameters('resourceGroupName'), 'App')]",
"type": "Microsoft.Resources/deployments",
"resourceGroup": "[parameters('resourcegroupName')]",
"apiVersion": "2021-04-01",
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "[concat(parameters('templateFolderUri'), '/dualSlotWebApp.json')]",
"contentVersion": "1.0.0.0"
},
"parameters": {}
},
"dependsOn": [
"[resourceId('Microsoft.Resources/resourceGroups/', parameters('resourceGroupName'))]",
"[resourceId('Microsoft.Resources/deployments', parameters('resourceGroupName'))]"
]
}
],
"outputs": {}
}

“父”模板在单独运行时可以工作,而父模板则不能。我收到祖 parent 模板中每个资源类型的错误:

##[error]Multiple error occurred: BadRequest,BadRequest,BadRequest,BadRequest. Please see details.
##[error]Details:
##[error]InvalidTemplate: The nested deployment 'NovaArmTestDev' failed validation: 'Error converting value "NovaArmTestDev" to type 'Azure.Deployments.Core.Definitions.DeploymentParameterDefinition'. Path 'properties.parameters.resourcegroupName', line 1, position 476.'.
##[error]InvalidTemplate: The nested deployment 'NovaArmTestTest' failed validation: 'Error converting value "NovaArmTestTest" to type 'Azure.Deployments.Core.Definitions.DeploymentParameterDefinition'. Path 'properties.parameters.resourcegroupName', line 1, position 479.'.
##[error]InvalidTemplate: The nested deployment 'NovaArmTestCat' failed validation: 'Error converting value "NovaArmTestCat" to type 'Azure.Deployments.Core.Definitions.DeploymentParameterDefinition'. Path 'properties.parameters.resourcegroupName', line 1, position 476.'.
##[error]InvalidTemplate: The nested deployment 'NovaArmTest' failed validation: 'Error converting value "NovaArmTest" to type 'Azure.Deployments.Core.Definitions.DeploymentParameterDefinition'. Path 'properties.parameters.resourcegroupName', line 1, position 467.'.
##[warning]Validation errors were found in the Azure Resource Manager template. This can potentially cause template deployment to fail. Task failed while creating or updating the template deployment.. Please follow https://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/template-syntax
Starting Deployment.
Deployment name is completeNovaRssDeploy-20220527-130154-2824
There were errors in your deployment. Error code: DeploymentFailed.
##[error]At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/DeployOperations for usage details.
##[error]Details:
##[error]InvalidRequestContent: The request content was invalid and could not be deserialized: 'Error converting value "NovaArmTest" to type 'Azure.Deployments.Core.Definitions.DeploymentParameterDefinition'. Path 'properties.parameters.resourcegroupName', line 1, position 266.'.
##[error]InvalidRequestContent: The request content was invalid and could not be deserialized: 'Error converting value "NovaArmTestCat" to type 'Azure.Deployments.Core.Definitions.DeploymentParameterDefinition'. Path 'properties.parameters.resourcegroupName', line 1, position 269.'.
##[error]InvalidRequestContent: The request content was invalid and could not be deserialized: 'Error converting value "NovaArmTestDev" to type 'Azure.Deployments.Core.Definitions.DeploymentParameterDefinition'. Path 'properties.parameters.resourcegroupName', line 1, position 269.'.
##[error]InvalidRequestContent: The request content was invalid and could not be deserialized: 'Error converting value "NovaArmTestTest" to type 'Azure.Deployments.Core.Definitions.DeploymentParameterDefinition'. Path 'properties.parameters.resourcegroupName', line 1, position 270.'.
##[error]Check out the troubleshooting guide to see if your issue is addressed: https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/azure-resource-group-deployment?view=azure-devops#troubleshooting
##[error]Task failed while creating or updating the template deployment.

我相信我明白为什么会发生这种情况,因为在“祖 parent ”模板中,当“父”模板时,我将“父”链接为 "type": "Microsoft.Resources/deployments"部署资源组并在订阅范围上操作。我还尝试将类型设置为 "type": "Microsoft.Resources/resourceGroups" 但这也不起作用。我相信可以通过将资源组从“父”模板移动到“祖 parent ”来解决此问题,但我想知道是否有一种资源类型可以更轻松地在同一链接模板中容纳这两种类型。

最佳答案

将参数传递给链接模板时,参数需要添加一个名为 "value": ... 的附加属性。

修复所提供示例的一部分,结果如下

...
"parameters": {
"resourcegroupName": {
"value": "[concat(parameters('resourcegroupName'), 'Dev')]"
},
"resourceGroupLocation": {
"value": "[parameters('resourceGroupLocation')]"
},
"templateFolderUri": {
"value": "[concat(parameters('templateFolderUri'), '/Components')]"
}
}
...

引用:https://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/linked-templates?tabs=azure-powershell#:~:text=To%20pass%20parameter%20values%20inline

关于azure - 如何使用包含资源组和资源的链接模板部署 Arm 模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72406771/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com