azure - 在arm模板中传递除参数文件之外的其他参数
问题描述
我有一些 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 变量引用的参数文件中。但除此之外,我需要传递额外的参数,比如密码或任何必需的参数,我可能是从保险库等外部源读取的,并且需要从命令行传递。我将如何在资源中的参数部分传递它。
我用来部署天蓝色模板的命令如下:
az group deployment create --resource-group testrg --template-file ${WORKSPACE}/azuredeploy.json --parameters @${WORKSPACE}/networksubnetnsgtest.parameters.json --parameters DBMasterUserPassword=${DBMasterUserPassword}
解决方案
摘自官方文档:
az group deployment create -g MyResourceGroup --template-file azuredeploy.json \
--parameters @params.json --parameters https://mysite/params.json --parameters MyValue=This MyArray=@array.json
https://docs.microsoft.com/en-us/cli/azure/group/deployment?view=azure-cli-latest#examples
推荐阅读
- go - 使用 os/exec 命令从 Windows 交叉编译到 Linux
- css - CSS > 选择器传播到孩子之外?
- python - Geopy 没有所有相同的地址键
- prolog - 为什么这个 Prolog 规则没有进入无限循环?
- python - 如何更改用户输入?
- r - 在 R 中编写一个函数 - 从历史记录中计算价值并添加到未来的记录中
- amazon-web-services - 在 CloudFormation 堆栈之间移动资源
- sonarqube - coverity-sonar-plugin 无法连接 synopsys 存储库
- android - 获取不同孩子的值列表
- python - 带有子类和类列表的 Python 类型注释