1

我们有一个 Azure ARM 模板,它正在为 Microsoft.Web/site 添加 appsettings。

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

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

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

模板及其参数有利于约定而不是配置。这在大多数情况下运行良好,并导致以下MY_SERVICE_URL值。

问题是我们想打破dev环境的惯例。也就是说,我们希望它MY_SERVICE_URL看起来像这样:

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

我的第一个虽然是使用这样的条件,但这样的 ARM 函数似乎不可用。

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

2 回答 2

2

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

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

好的,那么这是如何工作的。您传入参数“DeploymentType”,它可以是 PROD 或 DEV。如果您通过 DEV "DeploymentVariable": "[variables(parameters('DeploymentType'))]",- 这将评估"[variables('Dev')]"并获取"Dev": "https://some_service-ci.domain.com",

于 2017-03-08T17:39:33.647 回答
0

对于问题中的示例,答案最终如下所示:

"variables": {
   "myServiceUrl_default": "[concat('https://myservice-', parameters('env'), '.domain.ca')]",
   "myServiceUrl_dev": "https://abc123.foo.bar.baz.ca",
   "myServiceUrl_ci": "[variables('myServiceUrl_default')]",
   "myServiceUrl_qa": "[variables('myServiceUrl_default')]",
   "myServiceUrl_prod": "[variables('myServiceUrl_default')]",
   "myServiceUrl": "[variables(concat('myServiceUrl_', 'parameters('env')'))]"  
},

...

"appSettings: [
   {
      "name": "MY_SERVICE_URL",
      "value": "[variables('myServiceUrl')]"
   }
]
于 2017-03-08T18:35:43.127 回答