gpt4 book ai didi

azure - 如何为链接模板同时使用 uri 和传入参数?

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

假设您有以下文件,这些文件是在 Visual Studio 中通过选择新的 Azure 资源组部署然后添加嵌套模板两次而创建的

azuredeploy.json

{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"_artifactsLocation": {
"type": "string"
},
"_artifactsLocationSasToken": {
"type": "securestring"
}
},
"variables": {
"linkedTemplateTemplateFolder": "nestedtemplates",
"linkedTemplateTemplateFileName": "linkedTemplate.json",
"linkedTemplateTemplateParametersFileName": "linkedTemplate.parameters.json"
},
"resources": [
{
"name": "linkedTemplate",
"type": "Microsoft.Resources/deployments",
"apiVersion": "2016-09-01",
"dependsOn": [],
"properties": {
"mode": "Incremental",
"templateLink": {
"uri":
"[concat(parameters('_artifactsLocation'), '/', variables('linkedTemplateTemplateFolder'), '/', variables('linkedTemplateTemplateFileName'), parameters('_artifactsLocationSasToken'))]",
"contentVersion": "1.0.0.0"
},
"parametersLink": {
"uri":
"[concat(parameters('_artifactsLocation'), '/', variables('linkedTemplateTemplateFolder'), '/', variables('linkedTemplateTemplateParametersFileName'), parameters('_artifactsLocationSasToken'))]",
"contentVersion": "1.0.0.0"
},
"parameters": {
"_artifactsLocation": { "value": "[parameters('_artifactsLocation')]" },
"_artifactsLocationSasToken": { "value": "[parameters('_artifactsLocationSasToken')]" }
}
}
}
],
"outputs": {
"result": {
"type": "object",
"value": "[reference('linkedTemplate').outputs.result.value]"
}
}
}

azuredeploy.parameters.json

{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
}
}

嵌套模板\linkedTemplate.json

{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"Foo": {
"type": "string"
},
"_artifactsLocation": {
"type": "string"
},
"_artifactsLocationSasToken": {
"type": "securestring"
}
},
"variables": {
"thirdTeirTemplateFolder": "nestedtemplates",
"thirdTeirTemplateFileName": "thirdTeir.json",
"thirdTeirTemplateParametersFileName": "thirdTeir.parameters.json"
},
"resources": [
{
"name": "thirdTeir",
"type": "Microsoft.Resources/deployments",
"apiVersion": "2016-09-01",
"dependsOn": [],
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "[concat(parameters('_artifactsLocation'), '/', variables('thirdTeirTemplateFolder'), '/', variables('thirdTeirTemplateFileName'), parameters('_artifactsLocationSasToken'))]",
"contentVersion": "1.0.0.0"
},
"parameters": {
"Foo": {"value": "[parameters('Foo')]"}
}
}
}
],
"outputs": {
"result": {
"type": "string",
"value": "[reference('thirdTeir').outputs.result]"
}
}
}

nestedtemplates\linkedTemplate.parameters.json

{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"Foo": {
"value": "Foo!"
}
}
}

嵌套模板\thirdTeir.json

{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"Foo": {
"type": "string"
}
},
"variables": {},
"resources": [],
"outputs": {
"result": {
"type": "string",
"value": "[parameters('Foo')]"
}
}
}

这自然会失败并出现错误

Error: Code=InvalidDeployment; Message=The deployment 'linkedTemplate' cannot have both the ParameterLink and Parameter property set. Please use one or the other. Please see https://aka.ms/arm-deploy for usage details.

这是完全有道理的,因为 the documentation states您不能同时使用 parametersLinkparameters

在这种情况下我应该采取什么解决方法,如何将 _artifactsLocation_artifactsLocationSasToken 传递到模板的中间层,同时仍然允许单独的文件保存配置将传入的值?

以防万一我问的是 XY 问题,我想要解决的真正问题是是否有某种方法可以直接读取包含通过 uri 传入的一些配置数据并访问其内容的 json 文件?这是我真正需要做的事情。

最佳答案

我认为您试图解决的根本问题是将参数和链接参数传递给嵌套部署...我可以想到一些选项,但没有一个非常优雅:

  1. 让您的部署脚本读取链​​接的 json 文件参数并使用嵌套部署中的所有参数
  2. 让您的部署脚本在暂存参数文件之前写入位置和 sasToken
  3. 将位置和 sasToken 写入部署输出,并从输出中引用它们,而不是作为参数
  4. 将位置和 sasToken 写入 keyvault,并将对 keyvault 的参数引用放入链接的参数文件中 - 这很棘手,因为您必须在部署之前(创建参数文件时)知道保管库引用。

3 可能是最简单的,可以完全在模板内完成,但可能使您的 sasToken 不再保密。 (我认为,不确定是否可以将其保留为 secureString)。

有帮助吗?

关于azure - 如何为链接模板同时使用 uri 和传入参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46457662/

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