我有下面给出的示例 ARM 模板。订阅、资源组和位置字段在第一部分 ARM 模板中在部署时向用户提供,参数部分在此之后提供。资源组是 Azure ARM 本身提供的下拉字段,我需要在其中提供任何一个资源组作为列表中存在的默认资源组。这怎么可能?
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"writePermission": {
"defaultValue": "No",
"allowedValues": [
"No",
"Yes"
],
"type": "String",
"metadata": {
"description": "the permission type"
}
}
},
"variables": {
"location": "[resourceGroup().location]",
"templateUri": "[deployment().properties.templateLink.uri]"
},
"resources": [
],
"outputs": {
"result": {
"type": "String",
"value": "[variables('templateUri')]"
}
}
}
这就是模板的渲染方式。
预期解决方案: 应使用资源组下拉列表中的第一个字段预先填充该值,而不是资源组中的空白值。
最佳答案
使用 ARM 模板的部署始终在模板外部提供部署资源组。部署始终基于您在模板外部作为参数提供的资源组。使用 PS 进行部署的命令名称为:New-AzResourceGroupDeployment,表示您以提供的资源组作为基础,并且用于选择资源组的参数名为:-ResourceGroup
所以基本上您无法在 ARM 模板内选择基本资源组,因为它是在外部提供的,以便 API 了解从哪里开始部署。
这是进行部署的 PS 命令:
New-AzResourceGroupDeployment
[-Name <String>]
-ResourceGroupName <String>
[-Mode <DeploymentMode>]
[-DeploymentDebugLogLevel <String>]
[-RollbackToLastDeployment]
[-RollBackDeploymentName <String>]
[-Tag <Hashtable>]
[-WhatIfResultFormat <WhatIfResultFormat>]
[-WhatIfExcludeChangeType <String[]>]
[-Force]
[-AsJob]
-TemplateFile <String>
[-SkipTemplateParameterPrompt]
[-ApiVersion <String>]
[-Pre]
[-DefaultProfile <IAzureContextContainer>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
PS 命令使用的是 ARM Rest API,这与 Azure Portal 使用的 API 相同,查看 Rest API,您还可以看到 ResourceGroup 是需要在 ARM 模板外部提供的参数:
https://learn.microsoft.com/en-us/rest/api/resources/deployments/createorupdate
所以我的意思是,您不能使用模板来操作基本资源组的下拉框,您可以做到这一点的唯一方法是通过使用 RBAC 限制用户的访问权限,以便用户只能看到该用户应该能够部署到的资源组。
关于azure - 如何在ARM模板部署中为资源组字段赋予默认值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63501987/