【问题标题】:Azure ARM - Resource name based on variableAzure ARM - 基于变量的资源名称
【发布时间】:2020-04-17 13:25:08
【问题描述】:

我的目标是为我要部署的所有环境提供一个 ARM 模板。

我希望能够将变量定义为发布管道的一部分,例如“dev”或“prod”,然后让 ARM 模板将其用作已部署资源名称的一部分。

例如:

myapi-dev-appserviceplan myapi-prod-appserviceplan

【问题讨论】:

    标签: azure deployment azure-devops continuous-deployment continuous-delivery


    【解决方案1】:

    只需创建参数并在 JSON 文件中使用它们。注意有“参数”和“变量”。 就我而言,我使用参数来创建变量,但有时,我直接使用环境名称的参数(即:在我的情况下,环境是“dev”、“uat”、“prd”并注入资源名称)

    这是一个完整的示例,显示了您想要做什么

    {
        "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
        "contentVersion": "1.0.0.0",
        "parameters": { 
            "environment": {
                "type": "String" 
            },
            "sku": {
                "type": "string",
                "defaultValue": "S1"
            }
        },
        "variables": {
            "webappPrefix": "lovelyfront",
          "location": "westeurope",
            "aiName": "[concat('ai-',variables('webappPrefix'), '-', parameters('environment'))]",
            "webappName": "[concat('wa-',variables('webappPrefix'), '-', parameters('environment'))]",
            "webappNameStagingSlot": "[concat(variables('webappName'), '/', 'staging')]",
            "appServicePlanName": "[concat('asp-',variables('webappPrefix'), '-', parameters('environment'))]",
            "storageAccountName": "[concat('stolovefront', toLower(parameters('environment')))]",
            "cognitiveEndpointName": "[concat('cog-',variables('webappPrefix'), '-', parameters('environment'))]",
            "signalRName": "[concat('sig-',variables('webappPrefix'), '-', parameters('environment'))]"
        },
      "resources": [
        {
          "apiVersion": "2014-04-01",
          "name": "[variables('aiName')]",
          "type": "Microsoft.Insights/components",
          "location": "[variables('location')]",
          "properties": {
            "ApplicationId": "[variables('aiName')]"
          }
        },
        {
          "apiVersion": "2017-08-01",
          "type": "Microsoft.Web/serverfarms",
          "kind": "app",
          "name": "[variables('appServicePlanName')]",
          "location": "[variables('location')]",
          "properties": {},
          "dependsOn": [],
          "sku": {
            "name": "[parameters('sku')]"
          }
        },
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-11-08
      • 1970-01-01
      • 1970-01-01
      • 2019-07-02
      • 2017-02-25
      • 2023-04-02
      • 2020-05-07
      相关资源
      最近更新 更多