简体   繁体   English

我们何时应该使用参数何时在ARM模板中使用变量

[英]When should we use a parameter when to use variable in ARM templates

I am confused about where to use a variable and where to use a parameter in ARM templates. 我很困惑在哪里使用变量以及在ARM模板中使用参数的位置。 How do we make this call ? 我们如何打这个电话?

The referenced script uses both. 引用的脚本使用两者。 I am more curious of the justification of using variables. 我更好奇使用变量的理由。

在此输入图像描述

Reference 参考

Sample Service Fabric Azure Deploy Script 示例服务Fabric Azure部署脚本

https://raw.githubusercontent.com/azure/azure-quickstart-templates/master/service-fabric-oms/azuredeploy.json https://raw.githubusercontent.com/azure/azure-quickstart-templates/master/service-fabric-oms/azuredeploy.json

In the Azure template json file: 在Azure模板中的json文件:

parameters :Values that are provided when deployment is executed to customize resource deployment. 参数 :执行部署以自定义资源部署时提供的值。

variables :Values that are used as JSON fragments in the template to simplify template language expressions. 变量 :在模板中用作JSON片段的值,用于简化模板语言表达式。

More information please refer to this official document: Understand the structure and syntax of Azure Resource Manager templates . 有关更多信息,请参阅此官方文档: 了解Azure Resource Manager模板的结构和语法

I am more curious of the justification of using variables. 我更好奇使用变量的理由。

Based on my experience, if you only use the variable once, you don't need use variables. 根据我的经验,如果您只使用一次变量,则不需要使用变量。 But if you want to use the variable multiple times, you had better use variables. 但是如果你想多次使用变量,最好使用变量。 Using variable can simplify your template to avoid duplication of content. 使用变量可以简化模板以避免重复内容。

For example, if you don't use supportLogStorageAccountName more than once, you can just do: 例如,如果您不多次使用supportLogStorageAccountName ,则可以执行以下操作:

"name": "[toLower(concat('sf', uniqueString(resourceGroup().id),'2'))]"

However if you use provide variable supportLogStorageAccountName several\\many times, you can use variable to avoid duplication. 但是,如果您多次使用提供变量supportLogStorageAccountName ,则可以使用变量来避免重复。

ARM templates are usually used to create a set of close to identical environments. ARM模板通常用于创建一组接近相同的环境。 The parameters are what differs them. 参数是不同的。 This is commonly used for environment type (prod, dev, test) and performance/cost related parameters. 这通常用于环境类型(prod,dev,test)和性能/成本相关参数。 Variables are used to create unique names for services based on or calculated from the parameters. 变量用于基于参数或根据参数计算服务的唯一名称。

An example of this would the name of a storage account. 这样的一个例子是存储帐户的名称。 This is usually done by concatenating a common name like _storage and an environment name parameter like “test” and store it in a variable. 这通常通过连接像_storage这样的通用名称和像“test”这样的环境名称参数来完成,并将其存储在变量中。 When you create another environment all you must do is change the environment type parameter. 当您创建另一个环境时,您必须做的就是更改环境类型参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 ARM 模板中使用“格式” - Use of 'format' in ARM templates 我们何时应在Azure资源组中使用重新部署按钮 - When should we use redeploy button in Azure Resource groups ARM嵌套模板:部署带有嵌套模板的模板时,_artifactLocation参数未正确填充 - ARM nested templates: _artifactLocation parameter is not populated correctly when deploying template with nested templates ARM模板中元数据下生成器的使用 - Use of generators under metadata in ARM Templates ARM Resource Not Found 在尝试使用 Outputs 时,已经尝试了很多 - ARM Resource Not Found when trying to use Outputs, have tried a lot 提取FQDN参数字符串并将其分块以在变量中使用(Azure ARM模板) - Taking a FQDN parameter string and chunking it up to use in a variable (Azure ARM Template) 如何在 Azure Arm 模板 (2019) 中使用粘性暂存槽 - How to use sticky staging slots in Azure Arm Templates (2019) 在 ARM 模板中有没有办法使用 Case-like 语句? - Is there any way in ARM Templates to use a Case-like statement? 如何在Azure Arm模板中使用粘性临时插槽 - How to use sticky staging slots in Azure Arm Templates 如何在 ARM 模板中设置变量的值? 在 ARM 模板中使用或条件 - How to set the value for variable in ARM template? Or Use of Or condition in ARM template
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM