ARM模板的Appservice和插槽部署问题

时间:2020-02-21 01:25:11

标签: azure azure-resource-manager azure-deployment-slots

我有一个ARM模板代码,可根据条件将webapp和插槽创建以及与app一起部署到环境中。当我尝试使用模板部署资源时,它仅部署Web应用程序,并且未使用该应用程序上的设置创建该广告位。我是ARM的新手,有人可以帮我解决我做错模板的问题吗?

       {
        "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
        "contentVersion": "1.0.0.0",
        "parameters": {
        "resourceGroup": {
        "type": "string"
        },
"displayNameTag": {
  "type": "string"
},
"appInsightName": {
  "type": "string"
},
  "environment": {
    "type": "string"
  },
  "appType": {
    "type": "string"
  },
  "appServicePlanName": {
    "type": "string"
  },
  "alwaysOn": {
    "type": "bool"
  },
  "currentStack": {
    "type": "string"
  },
  "netFrameworkVersion": {
    "type": "string",
    "defaultValue": "v4.0"

  },
  "secondaryApp":{
    "type":"string"
  }
},
    "variables": {

"AustraliaEast": {
  "countryCode": "au",
  "regionShortCode": "aue",
  "regionShortCodePair": "aue",
  "omsLocation": "AustraliaEast",
  "omsLocationShortCode": "aue",
  "PrimaryRegion": true,
  "SecondaryRegion": "AustraliaSoutheast",
  "regionLocation":"AustraliaEast"
},
"AustraliaSoutheast": {
  "countryCode": "au",
  "regionShortCode": "aus",
  "regionShortCodePair": "aue",
  "PrimaryRegion": false,
  "regionLocation":"AustraliaSoutheast"
},

"regionSpec": "[variables(resourceGroup().location)]",
"applicationRegion" : "[if(equals(parameters('secondaryApp'),'Yes'),variables('AustraliaSoutheast'),variables('regionspec'))]",
"appName": "[concat('myapp-',parameters('environment'),'-',parameters('appType'),'-',variables('applicationRegion').regionShortcode,'-',parameters('displayNameTag'))]"
  },
   "resources": [
{
  "apiVersion": "2018-11-01",
  "name": "[variables('appName')]",
  "type": "Microsoft.Web/sites",
  "location": "[variables('applicationRegion').regionLocation]",
  "tags": {
    "displayName": "[parameters('displayNameTag')]",
    "environment": "[parameters('environment')]"
  },
  "dependsOn": [],
  "properties": {
    "name": "[variables('appName')]",
    "mode": "incremental",
    "siteConfig": {
      "appSettings": [
        {
          "name": "APPINSIGHTS_INSTRUMENTATIONKEY",
          "value": "[reference(resourceId('Microsoft.Insights/components', parameters('appInsightName')), '2015-05-01').InstrumentationKey]"
        },
        {
          "name": "APPLICATIONINSIGHTS_CONNECTION_STRING",
          "value": "[concat('InstrumentationKey=',reference(resourceId('Microsoft.Insights/components', parameters('appInsightName')), '2015-05-01').InstrumentationKey)]"
        }
      ],
      "metadata": [
        {

          "name": "CURRENT_STACK",
          "value": "[parameters('currentStack')]"
        }
      ],
      "netFrameworkVersion": "[parameters('netFrameworkVersion')]",
      "alwaysOn": "[parameters('alwaysOn')]"
    },
    "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('appServicePlanName'))]",
    "clientAffinityEnabled": true
  }
},
{

  "condition":"[equals(parameters('secondaryApp'),'Yes')]",
  "apiVersion": "2018-11-01",
  "type": "Microsoft.Web/sites/slots",
  "name": "[concat(variables('appName'), '/', 'Slot-Staging')]",
  "location": "[variables('applicationRegion').regionLocation]",
  "comments": "This specifies the web app slots.",
  "tags": {
    "displayName": "WebAppSlots"
  },
  "properties": {
    "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('appServicePlanName'))]"
  },
  "dependsOn": [
    "[resourceId('Microsoft.Web/sites', variables('appName'))]"
  ]
}
 ],
 "outputs": {
"webAppName": {
  "type": "string",
  "value": "[variables('appName')]"
  }
  }
 }'

1 个答案:

答案 0 :(得分:0)

请尝试添加在ARM模板中删除的json代码。

"resources": [
    {
      "apiVersion": "2015-08-01",
      "name": "appsettings",
      "type": "config",
      "dependsOn": [
        "[resourceId('Microsoft.Web/Sites/Slots', variables('webSiteName'), 'Staging')]"
      ],
      "properties": {
        "AppSettingKey1": "Some staging value",
        "AppSettingKey2": "My second staging setting",
        "AppSettingKey3": "My third staging setting"
      }
    }
  ]

Follow this SO for complete reference.

相关问题