-1

我有一个 ARM 模板代码来部署 webapp 和插槽创建以及应用程序与基于条件的相应环境。当我尝试使用模板部署资源时,它仅部署 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')]"
  }
  }
 }'
4

1 回答 1

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"
      }
    }
  ]

遵循此 SO 以获取完整参考。

于 2020-02-21T08:01:59.717 回答