gpt4 book ai didi

azure - 从 CLI 将 url 作为 ARM 模板中的参数传递

转载 作者:行者123 更新时间:2023-12-02 06:28:09 24 4
gpt4 key购买 nike

我正在尝试使用链接的ARM模板部署azure资源,为此我将参数文件和模板文件放置在blob存储上。从 CLI 执行 azure 命令时,我需要将参数文件和 Blob 存储的链接作为参数传递。下面是我的示例 masterazuredeploy.json

{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"variables": {
"templateBaseUrl": "[parameters('templateBaseUrl')]",
"parameterBaseUrl": "[parameters('parameterBaseUrl')]",
"keyVaultDeployTemplateUrl": "[uri(variables('templateBaseUrl'), 'keyvaultdeploy.json')]"
},
"resources": [
{
"apiVersion": "[variables('apiVersionResourceDeployment')]",
"name": "keyVaultDeployment",
"type": "Microsoft.Resources/deployments",
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "[variables('keyVaultDeployTemplateUrl')]"
},
"parametersLink": {
"uri": "[variables('keyVaultparameterFileUrl')]"
}
}
}

]
}

要执行此操作,我给出以下 CLI 命令:

az group deployment create --resource-group abc-devops-test --template-file .\masterazuredeploy.json  --parameters templateBaseUrl="https://test.blob.core
.windows.net/azurestackautomationtest/resourcetemplates/" parameterBaseUrl="https://test.blob.core.windows.net/azurestackautomationtest/parameters/dev/" --verbose

执行时出现以下错误:

unrecognized template parameter 'templateBaseUrl'. Allowed parameters:
command ran in 1.918 seconds.

我尝试了不带倒引号、带单引号的参数值。还是行不通。我到底缺少什么。

还尝试了另一种方法,将两个参数放置在 global.parameters.json 中,如下所示,

{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"templateBaseUrl": {
"value": "https://test.blob.core.windows.net/azurestackautomation/resourcetemplates/"
},
"parameterBaseUrl": {
"value": "https://test.blob.core.windows.net/azurestackautomation/parameters/dev/"
}
}
}

并将此文件上传到 Blob 存储,并给定 Blob 存储路径作为参数

az group deployment create --resource-group abc-devops-test --template-file .\masterazuredeploy.json  --parameters https://test.blob.core.windows.net/azur
estackautomationtest/parameters/dev/global.parameters.json --verbose

但是出现以下错误:

400 Client Error: Bad Request for url: https://management.azure.com/subscriptions/XXXX-xx-x-x-x--x-x/resourcegroups/abc-devops-test/providers/Microsoft.Resources/deployments/masterazuredeploy?api-version=2018-05-01
command ran in 5.646 seconds.

最佳答案

正如我在您的模板中看到的,您错过了设置参数,您所做的是将参数值输入到模板中的参数中,无论您提供了两个 CLI 命令。但你没有设置参数,所以没有参数可以使用。我建议您将模板更改为以下内容:

    {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"templateBaseUrl": {
"type": "string"
},
"parameterBaseUrl": {
"type": "string"
}
},
"variables": {
"keyVaultDeployTemplateUrl": "[uri(parameters('templateBaseUrl'), 'keyvaultdeploy.json')]"
},
"resources": [
{
"apiVersion": "[variables('apiVersionResourceDeployment')]", #1
"name": "keyVaultDeployment",
"type": "Microsoft.Resources/deployments",
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "[variables('keyVaultDeployTemplateUrl')]"
},
"parametersLink": {
"uri": "[variables('keyVaultparameterFileUrl')]" #2
}
}
}

]
}

您还错过了设置变量 apiVersionResourceDeploymentkeyVaultparameterFileUrl。您可以根据需要使用参数和变量。

关于azure - 从 CLI 将 url 作为 ARM 模板中的参数传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59659185/

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