在ARM模板中有条件地设置appsetting值

编程入门 行业动态 更新时间:2024-10-24 02:33:57
本文介绍了在ARM模板中有条件地设置appsetting值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我们有一个Azure ARM模板,该模板正在为Microsoft.Web/站点添加应用程序设置.

We have an Azure ARM template, which is adding appsettings for a Microsoft.Web/site.

"resources": [ { "apiVersion": "2016-03-01", "name": "myazurefunction", "type": "Microsoft.Web/sites", "properties": { "name": "myazurefunction", "siteConfig": { "appSettings": [ { "name": "MY_SERVICE_URL", "value": "[concat('myservice-', parameters('env'), '.domain.ca')]" } ] } } } ]

我们还有四个parameters.environment.json文件.例如,这是parameters.dev.json的内容.

We also have four parameters.environment.json files. For instance, this is the content of parameters.dev.json.

{ "$schema": "schema.management.azure/schemas/2015-01-01...", "contentVersion": "1.0.0.0", "parameters": { "env": { "value": "dev" } } }

模板及其参数优先于配置而不是约定.在大多数情况下,这工作得很好,并导致以下MY_SERVICE_URL值.

The template and its parameters favor convention over configuration. This is working nicely for the most part, and leads to the following MY_SERVICE_URL values.

  • myservice-dev.domain.ca
  • myservice-qa.domain.ca
  • myservice-ci.domain.ca
  • myservice-prod.domain.ca
  • myservice-dev.domain.ca
  • myservice-qa.domain.ca
  • myservice-ci.domain.ca
  • myservice-prod.domain.ca

问题是我们要打破dev环境的约定.也就是说,我们希望它的MY_SERVICE_URL看起来像这样:

The problem is that we want to break the convention for the dev environment. That is, we want it to have a MY_SERVICE_URL that looks something like this:

  • abc123.foo.bar.baz.ca

我们如何配置ARM模板以仅针对一种环境违反约定?

How can we configure the ARM template to break the convention for only one environment?

我的第一个方法是使用这样的条件,但是这样的ARM函数似乎不可用.

My first though is to use a conditional like this, but such an ARM function appears not to be available.

"name": "MY_SERVICE_URL", "value": "[parameters('env') -eq 'dev' ? 'abc123.foo.bar.baz.ca' : concat('myservice-', parameters('env'), '.domain.ca')]"

推荐答案

只需创建一个取决于参数的变量:

just create a variable that would depend on the parameter:

"parameters": { ... "DeploymentType": { "type": "string", "allowedValues": [ "Dev", "Prod" ] } ... "variables": { "Dev": "some_service-ci.domain", "Prod": "abc123.foo.bar.baz", "DeploymentVariable": "[variables(parameters('DeploymentType'))]", ... "appSettings": [ "name": "MY_SERVICE_URL", "value": "[variables('DeploymentVariable')]" ] ...

好的,这是怎么工作的.您传入参数"DeploymentType",它可以是PROD或DEV.如果您通过DEV "DeploymentVariable": "[variables(parameters('DeploymentType'))]",-这将得出"[variables('Dev')]"并获得"Dev": "some_service-ci.domain",

Ok, so how does this work. you pass in the parameter 'DeploymentType', it can be PROD or DEV. If you pass DEV "DeploymentVariable": "[variables(parameters('DeploymentType'))]", - this evaluates to "[variables('Dev')]" and gets the value of "Dev": "some_service-ci.domain",

更多推荐

在ARM模板中有条件地设置appsetting值

本文发布于:2023-10-24 08:43:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1523475.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中有   模板   条件   ARM   appsetting

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!