我们有一个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值
发布评论