在创建事件订阅之前,从ARM部署功能。

问题描述 投票:0回答:1

我使用ARM创建了一个 function APP 和一个 event grid topic.

现在,从同一个ARM中,我想创建一个主题的订阅,但要做到这一点,我需要将函数部署到的 function App 前。

是否可以从同一个ARM部署我的功能?或者我必须有两个不同的ARM,一个用来创建所有的东西(storagetopics),除了函数相关的,还有一个是创建所有需要部署函数的资源(event subscriptions)? 在第二种情况下,我需要在中间部署功能。

我正在寻找一个ARM来从零开始部署完整的基础设施(包括 functionsfunction app). 这可能吗?如何实现?

azure azure-functions azure-resource-manager azure-eventgrid
1个回答
0
投票

根据我的测试,我们可以在一个模板中创建这些资源。例如,我们可以在一个模板中创建这些资源。

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "eventGridTopicName": {
      "type": "string",
      "defaultValue": "EventGridTopic",
      "metadata": {
        "description": "The name of the Event Grid custom topic."
      }
    },
    "eventGridSubscriptionName": {
      "type": "string",
      "defaultValue": "EventGridSub",
      "metadata": {
        "description": "The name of the Event Grid custom topic's subscription."
      }
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
        "description": "The location in which the Event Grid resources should be deployed."
      }
    },
    "appName": {
      "type": "string",
      "defaultValue": "Func",
      "metadata": {
        "description": "The name of the function app that you wish to create."
      }
    },
    "functionName": {
      "type": "string",
      "defaultValue": "EventGridFunction",
      "metadata": {
        "description": "Function App Name"
      }
    },
    "storageAccountType": {
      "type": "string",
      "defaultValue": "Standard_LRS",
      "allowedValues": [
        "Standard_LRS",
        "Standard_GRS",
        "Standard_RAGRS"
      ],
      "metadata": {
        "description": "Storage Account type"
      }
    },
    "runtime": {
      "type": "string",
      "defaultValue": "dotnet",
      "allowedValues": [
        "node",
        "dotnet",
        "java"
      ],
      "metadata": {
        "description": "The language worker runtime to load in the function app."
      }
    }
  },
  "variables": {
    "eventGridTopic": "[concat(uniquestring(resourceGroup().id),parameters('EventGridTopicName'))]",
    "eventGridSub": "[concat(uniquestring(resourceGroup().id),parameters('eventGridSubscriptionName'))]",
    "functionUrl": "[concat('https://', variables('FunctionAppName'),'.azurewebsites.net/runtime/webhooks/eventgrid?functionName=', parameters('FunctionName'),'&code=')]",
    "functionAppName": "[concat(uniquestring(resourceGroup().id),parameters('appName'))]",
    "hostingPlanName": "[parameters('appName')]",
    "applicationInsightsName": "[parameters('appName')]",
    "storageAccountName": "[concat(uniquestring(resourceGroup().id), 'azfunction')]",
    "functionWorkerRuntime": "[parameters('runtime')]"
  },
  "resources": [
   // create event topic
    {
      "name": "[variables('eventGridTopic')]",
      "type": "Microsoft.EventGrid/topics",
      "location": "[parameters('location')]",
      "apiVersion": "2020-04-01-preview",

    },
    // create event topic subscrition
    {
      "name": "[concat(variables('eventGridTopic'), '/Microsoft.EventGrid/', variables('eventGridSub'))]",
      "type": "Microsoft.EventGrid/topics/providers/eventSubscriptions",
      "location": "[parameters('location')]",
      "apiVersion": "2020-04-01-preview",
        "dependsOn": [
          "[variables('eventGridTopic')]",
          "[resourceId('Microsoft.Web/sites/functions/', variables('functionAppName'), parameters('functionName'))]"

        ],
      "properties": {
        "destination": {
          "endpointType": "AzureFunction",
          "properties": {
            "resourceId": "[resourceId('Microsoft.Web/sites/functions/', variables('functionAppName'), parameters('functionName'))]"
          }
        },
          "filter": {
          }
        }
      },
     // create storage account
      {
        "type": "Microsoft.Storage/storageAccounts",
        "name": "[variables('storageAccountName')]",
        "apiVersion": "2016-12-01",
        "location": "[parameters('location')]",
        "kind": "Storage",
        "sku": {
          "name": "[parameters('storageAccountType')]"
        }
      },
      // create host plan
      {
        "type": "Microsoft.Web/serverfarms",
        "apiVersion": "2018-02-01",
        "name": "[variables('hostingPlanName')]",
        "location": "[parameters('location')]",
        "sku": {
          "name": "Y1",
          "tier": "Dynamic"
        },
        "properties": {
          "name": "[variables('hostingPlanName')]",
          "computeMode": "Dynamic"
        }
      },
      // create function app
      {
        "apiVersion": "2015-08-01",
        "type": "Microsoft.Web/sites",
        "name": "[variables('functionAppName')]",
        "location": "[parameters('location')]",
        "kind": "functionapp",
        "dependsOn": [
          "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]",
          "[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]",
          "[concat('microsoft.insights/components/', variables('applicationInsightsName'))]"
        ],
        "properties": {
          "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]",
          "siteConfig": {
            "appSettings": [
              {
                "name": "AzureWebJobsStorage",
                "value": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('storageAccountName'), ';AccountKey=', listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName')),'2015-05-01-preview').key1)]"
              },
              {
                "name": "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING",
                "value": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('storageAccountName'), ';AccountKey=', listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName')),'2015-05-01-preview').key1)]"
              },
              {
                "name": "WEBSITE_CONTENTSHARE",
                "value": "[toLower(variables('functionAppName'))]"
              },
              {
                "name": "FUNCTIONS_EXTENSION_VERSION",
                "value": "~3"
              },
              {
                "name": "APPINSIGHTS_INSTRUMENTATIONKEY",
                "value": "[reference(resourceId('microsoft.insights/components/', variables('applicationInsightsName')), '2015-05-01').InstrumentationKey]"
              },
              {
                "name": "FUNCTIONS_WORKER_RUNTIME",
                "value": "[variables('functionWorkerRuntime')]"
              }

            ]
          }
        }
      },
      // create event gride trigger function
      {
       "apiVersion": "2019-08-01",
      "name": "[concat(variables('functionAppName'),'/', parameters('functionName'))]",
      "type": "Microsoft.Web/sites/functions",
      "dependsOn":[ "[variables('functionAppName')]"],
      "properties": {
        "config": {
          "bindings": [
            {
              "name": "eventGridEvent",

              "direction": "in",
              "type": "eventGridTrigger"
            }
          ]

        },
        "files":{
          // the code
           "run.csx":"#r \"Microsoft.Azure.EventGrid\"\r\nusing Microsoft.Azure.EventGrid.Models;\r\n\r\npublic static void Run(EventGridEvent eventGridEvent, ILogger log)\r\n{\r\n    log.LogInformation(eventGridEvent.Data.ToString());\r\n}"
          }
       }
      },
      // create application insight
      {
        "apiVersion": "2018-05-01-preview",
        "name": "[variables('applicationInsightsName')]",
        "type": "microsoft.insights/components",
        "location": "East US",
        "tags": {
          "[concat('hidden-link:', resourceGroup().id, '/providers/Microsoft.Web/sites/', variables('applicationInsightsName'))]": "Resource"
        },
        "properties": {
          "ApplicationId": "[variables('applicationInsightsName')]",
          "Request_Source": "IbizaWebAppExtensionCreate"
        }
      }
    ],
    "outputs": {

    }
  }

enter image description here更多详情,请参考 博客.

© www.soinside.com 2019 - 2024. All rights reserved.