【发布时间】:2019-11-21 15:45:28
【问题描述】:
我有一些 arm 模板,其中子网资源的创建依赖于 VNet 的创建。下面是代码:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vnetName": {
"type": "string",
"metadata": {
"description": "Name of the Virtual Network"
}
},
"vnetAddressPrefix": {
"type": "string",
"metadata": {
"description": "The IP Address pool for the virtual network in CIDR format."
}
},
"subnetPrefix": {
"type": "string",
"metadata": {
"description": "The IP Address pool for the Subnet in CIDR format."
}
},
"subnetName": {
"type": "string",
"metadata": {
"description": "Name of the Subnet"
}
}
},
"variables": {
"templateBaseUrl": "[deployment().properties.templateLink.uri]",
"virtualNetworkTemplateUrl": "[uri(variables('templateBaseUrl'), 'VirtualNetwork.json')]",
"subnetTemplateUrl": "[uri(variables('templateBaseUrl'), 'Subnet.json')]",
"parametersUrl": "[uri(variables('templateBaseUrl'), 'networksubnetnsgtest.parameters.json')]"
},
"resources": [
{
"apiVersion": "2017-05-10",
"name": "VnetDeployment",
"type": "Microsoft.Resources/deployments",
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "[variables('virtualNetworkTemplateUrl')]"
},
"parameters": {
"uri": {
"value": "[variables('parametersUrl')]"
}
}
}
},
{
"apiVersion": "2017-05-10",
"name": "SubnetDeployment",
"type": "Microsoft.Resources/deployments",
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "[variables('subnetTemplateUrl')]"
},
"parameters": {
"uri": {
"value": "[variables('parametersUrl')]"
}
}
},
"dependsOn": [
"VnetDeployment"
]
}
],
"outputs": {
"returnedVnetName": {
"type": "string",
"value": "[resourceId('Microsoft.Network/virtualNetworks', parameters('vnetName'))]"
},
"returnedVnetAddressPrefix": {
"type": "string",
"value": "[resourceId('Microsoft.Network/virtualNetworks', parameters('vnetAddressPrefix'))]"
}
}
}
如您所见,parameterUrl 变量引用的参数文件中保存的参数很少。但除此之外,我需要传递额外的参数,比如密码或任何必需的参数,我可能是从保险库等外部源读取的,并且需要从命令行传递。 我将如何在资源中的 parameters 部分传递它。
我用来部署 azure 模板的命令如下:
az group deployment create --resource-group testrg --template-file ${WORKSPACE}/azuredeploy.json --parameters @${WORKSPACE}/networksubnetnsgtest.parameters.json --parameters DBMasterUserPassword=${DBMasterUserPassword}
【问题讨论】:
-
您好,想看看4c74356b41最后的建议对您有用吗?如果没有,请随时在下面发表评论。然后我们可以继续帮助解决这个问题。
-
@MerlinLiang-MSFT 我仍然有疑问。在上面的 json 中,我有 2 个资源,1 个 VNetDeployment 和 2) SubnetDeployment。现在 SubNetDeployment 需要 2 类参数。 1)在我作为“uri”传递的networksubnetnsgtest.parameters.json文件中提到:{“value”:“[variables('parametersUrl')]”} 2)在一些密码上,我作为--parameter =
在 CLI 命令执行期间。现在我将如何将 = 作为参数传递给参数 {} 部分中的 SubnetDeployment 资源。或者我不需要传入参数 {} 部分。
标签: azure azure-devops azure-resource-manager