[英]Azure ARM Template - conditional input parameter
In Short:简而言之:
Is it possible to have condition
field (or something else to achieve this functionality), inside a parameter
, so that this parameter input will be asked to the user, only based on another parameter's value.是否可以在参数中包含condition
字段(或其他实现此功能的东西),以便仅根据另一个parameter
的值向用户询问此参数输入。
ie, Only if user selects Create New
on a parameter, the input for the name of that parameter should be asked.即,仅当用户在参数上选择Create New
时,才应询问该参数名称的输入。
In Detail:详细地:
I have a parameter virtualNetworkCreateNewOrUseExisting
which will accept two values - Create New
and Use Existing
.我有一个参数virtualNetworkCreateNewOrUseExisting
将接受两个值 - Create New
和Use Existing
。
"parameters": {
"virtualNetworkCreateNewOrUseExisting": {
"type": "string",
"defaultValue": "Create New",
"allowedValues": [
"Create New",
"Use Existing"
]
},
// Other parameters
}
I am trying to create a Virtual Network
based on an input from user.我正在尝试根据用户的输入创建一个Virtual Network
。 If user selects Create New
, it will be created, and if they select Use Existing
, it will be skipped.如果用户选择Create New
,它将被创建,如果他们 select Use Existing
,它将被跳过。 I see that this is achievable by using condition
field inside the resource
.我看到这是可以通过在resource
中使用condition
字段来实现的。
"resources": [
{
"condition": "[equals(parameters('virtualNetworkCreateNewOrUseExisting'), 'Create New')]",
// Other fields
}
// Other resources
]
Now, my question here is that,现在,我的问题是,
Similar to this, is it possible to have condition
field, inside another parameter
, so that this parameter input will be asked to the user, only based on the previous parameter value.与此类似,是否可以在另一个parameter
中包含condition
字段,以便仅根据先前的参数值向用户询问此参数输入。
ie, Only if user selects Create New
, the input for Virtual Network Name
should be asked.即,仅当用户选择Create New
时,才应询问Virtual Network Name
的输入。
Something like this, by using a condition
field:像这样,通过使用condition
字段:
"parameters": {
"virtualNetworksName": {
"condition": "[equals(parameters('virtualNetworkCreateNewOrUseExisting'), 'Create New')]",
"defaultValue": "vn-1",
"type": "string"
},
// Other parameters
}
But, I see that condition
field, is not supported inside parameters (at least as of now).但是,我看到参数内部不支持该condition
字段(至少到目前为止)。
Or, is it at least possible to have, if
statements, like this (So that, the value of the field will be displayed empty
by default if user selects Use Existing
.):或者,是否至少可以有这样的if
语句(这样,如果用户选择Use Existing
,默认情况下该字段的值将显示为empty
。):
"parameters": {
"virtualNetworksName": {
"defaultValue": "[if(equals(parameters('virtualNetworkCreateNewOrUseExisting'),'Create New'), 'vn-1', '')]",
"type": "string"
},
// Other parameters
}
Or, any other way to achieve this goal?或者,有什么其他方法可以实现这个目标?
As per the current Azure documentation , we cannot add conditions to parameters in parameters block.根据当前的Azure 文档,我们不能在参数块中为参数添加条件。
As a side note you can use PowerShell parameter inline functions while deploying the template.作为旁注,您可以在部署模板时使用PowerShell 参数内联函数。
We see that there is a feature request already in place to add Support functions within the definition of parameters... · Community (azure.com) We would suggest you to make a comment & Upvote on the exiting feedback request.我们看到有一个功能请求已经到位,以在参数定义中添加支持功能... · 社区 (azure.com)我们建议您对现有的反馈请求发表评论和投票。
You can't do this natively in the template file, but in the portal user experiences for deploying the template you can... See:您不能在模板文件中本地执行此操作,但在部署模板的门户用户体验中,您可以...请参阅:
https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/template-specs-create-portal-forms https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/template-specs-create-portal-forms
and和
https://docs.microsoft.com/en-us/azure/azure-resource-manager/managed-applications/create-uidefinition-overview https://docs.microsoft.com/en-us/azure/azure-resource-manager/managed-applications/create-uidefinition-overview
You don't have to use a templateSpec or managedApp (see the "Deploy to Azure button here: https://github.com/Azure/azure-quickstart-templates/tree/master/demos/100-marketplace-sample )您不必使用 templateSpec 或 managedApp(请参阅此处的“部署到 Azure 按钮: https://github.com/Azure/azure-quickstart-templates/tree/master/demos/100-marketplace-sample )
but templateSpec or managedApp will give you a better experience if that's an option.但是如果可以的话,templateSpec 或 managedApp 会给你更好的体验。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.