ARM-将现有的应用程序见解资源映射到应用程序服务

时间:2018-09-17 05:28:27

标签: azure azure-devops azure-resource-manager

我需要将现有的应用程序见解资源从其他资源组映射到应用程序服务

我正在创建一个应用服务,作为ARM模板的一部分。您能否让我知道,我将如何进行映射。

PFB我正在尝试使用的模板来创建新的应用程序服务

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
"serverFarmName": {
  "type": "string",
  "defaultValue": "asp-prod-brand-digital-onlinesetup-shared"
},
"serverFarmResourceGroup": {
  "type": "string",
  "defaultValue": "rg-prod-brand-digital-onlinesetup-shared"
},
"ss-prod-brand-digitial-onlinesetup-govAdminLogin": {
  "type": "string",
  "minLength": 1
},
"ss-prod-brand-digitial-onlinesetup-govAdminLoginPassword": {
  "type": "securestring"
},
"db-prod-brand-digital-onlinesetup-govName": {
  "type": "string",
  "minLength": 1
},
"db-prod-brand-digital-onlinesetup-govCollation": {
  "type": "string",
  "minLength": 1,
  "defaultValue": "SQL_Latin1_General_CP1_CI_AS"
},
"db-prod-brand-digital-onlinesetup-govEdition": {
  "type": "string",
  "defaultValue": "Standard",
  "allowedValues": [
    "Basic",
    "Standard",
    "Premium"
  ]
},
"db-prod-brand-digital-onlinesetup-govRequestedServiceObjectiveName": {
  "type": "string",
  "defaultValue": "S2",
  "allowedValues": [
    "Basic",
    "S0",
    "S1",
    "S2",
    "P1",
    "P2",
    "P3"
  ],
  "metadata": {
    "description": "Describes the performance level for Edition"
  }
}},
  "variables": {
"ap-prod-brand-digital-onlinesetup-govName": "[concat('ap-prod-brand-digital-onlinesetup-gov', uniqueString(resourceGroup().id))]",
"ss-prod-brand-digitial-onlinesetup-govName": "[concat('ss-prod-brand-digitial-onlinesetup-gov', uniqueString(resourceGroup().id))]"},
  "resources": [
{
  "name": "[variables('ap-prod-brand-digital-onlinesetup-govName')]",
  "type": "Microsoft.Web/sites",
  "location": "australiasoutheast",
  "apiVersion": "2015-08-01",
  "dependsOn": [ ],
  "tags": {
    "[concat('hidden-related:', resourceId(parameters('serverFarmResourceGroup'), 'Microsoft.Web/serverFarms', parameters('serverFarmName')))]": "Resource",
    "displayName": "ap-prod-brand-digital-onlinesetup-gov"
  },
  "properties": {
    "name": "[variables('ap-prod-brand-digital-onlinesetup-govName')]",
    "serverFarmId": "[resourceId(parameters('serverFarmResourceGroup'), 'Microsoft.Web/serverFarms', parameters('serverFarmName'))]"
  }
},
{
  "name": "[variables('ss-prod-brand-digitial-onlinesetup-govName')]",
  "type": "Microsoft.Sql/servers",
  "location": "[resourceGroup().location]",
  "apiVersion": "2014-04-01-preview",
  "dependsOn": [ ],
  "tags": {
    "displayName": "ss-prod-brand-digitial-onlinesetup-gov"
  },
  "properties": {
    "administratorLogin": "[parameters('ss-prod-brand-digitial-onlinesetup-govAdminLogin')]",
    "administratorLoginPassword": "[parameters('ss-prod-brand-digitial-onlinesetup-govAdminLoginPassword')]"
  },
  "resources": [
    {
      "name": "AllowAllWindowsAzureIps",
      "type": "firewallrules",
      "location": "[resourceGroup().location]",
      "apiVersion": "2014-04-01-preview",
      "dependsOn": [
        "[resourceId('Microsoft.Sql/servers', variables('ss-prod-brand-digitial-onlinesetup-govName'))]"
      ],
      "properties": {
        "startIpAddress": "0.0.0.0",
        "endIpAddress": "0.0.0.0"
      }
    },
    {
      "name": "[parameters('db-prod-brand-digital-onlinesetup-govName')]",
      "type": "databases",
      "location": "[resourceGroup().location]",
      "apiVersion": "2014-04-01-preview",
      "dependsOn": [
        "[resourceId('Microsoft.Sql/servers', variables('ss-prod-brand-digitial-onlinesetup-govName'))]"
      ],
      "tags": {
        "displayName": "db-prod-brand-digital-onlinesetup-gov"
      },
      "properties": {
        "collation": "[parameters('db-prod-brand-digital-onlinesetup-govCollation')]",
        "edition": "[parameters('db-prod-brand-digital-onlinesetup-govEdition')]",
        "maxSizeBytes": "1073741824",
        "requestedServiceObjectiveName": "[parameters('db-prod-brand-digital-onlinesetup-govRequestedServiceObjectiveName')]"
      }
    }
  ]
}],
  "outputs": {}
}

我需要将现有的应用程序见解映射到应用程序服务“ ap-prod-brand-digital-onlinesetup-gov”,这是现有ARM模板的一部分。

请在同一点上提出建议。

1 个答案:

答案 0 :(得分:1)

要将应用程序见解设置为应用程序服务,实际上是将名为APPINSIGHTS_INSTRUMENTATIONKEY的应用程序设置添加到应用程序服务。

您可以尝试将模板代码段添加到模板中。

参数:

 "applicationinsightkey": {
            "type": "String"
        }

资源:

"siteConfig": {
                    "appSettings": [
                        {
                            "name": "APPINSIGHTS_INSTRUMENTATIONKEY",
                            "value": "[parameters('applicationinsightkey')]"
                        }
                    ]
                }

完成示例模板:

{
    "parameters": {
        "name": {
            "type": "string"
        },
        "hostingPlanName": {
            "type": "string"
        },
        "location": {
            "type": "string"
        },
        "hostingEnvironment": {
            "type": "string"
        },
        "serverFarmResourceGroup": {
            "type": "string"
        },
        "subscriptionId": {
            "type": "string"
        },
           "applicationinsightkey": {
            "type": "String"
        }

    },
    "resources": [
        {
            "apiVersion": "2016-03-01",
            "name": "[parameters('name')]",
            "type": "Microsoft.Web/sites",
            "properties": {
                "name": "[parameters('name')]",
                "siteConfig": {
                    "appSettings": [
                        {
                            "name": "APPINSIGHTS_INSTRUMENTATIONKEY",
                            "value": "[parameters('applicationinsightkey')]"
                        }
                    ]
                },
                "serverFarmId": "[concat('/subscriptions/', parameters('subscriptionId'),'/resourcegroups/', parameters('serverFarmResourceGroup'), '/providers/Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]",
                "hostingEnvironment": "[parameters('hostingEnvironment')]"
            },
            "location": "[parameters('location')]"
        }
    ],
    "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0"
}

在我这边工作正常。

enter image description here

enter image description here

您可以在门户中导航至应用程序见解,以获取applicationinsightkey,请参阅屏幕快照。 注意,该模板将覆盖您应用服务中的所有应用设置。

enter image description here

此外,我建议您使用REST API,而不是使用ARM模板,从本质上讲,该模板也在调用API。