1. Publishing events to an Event Hub from an Azure Logic App

    TypeScript

    To publish events to an Azure Event Hub from an Azure Logic App, you'll need to perform the following steps with Pulumi:

    1. Create an Azure Resource Group to contain all your resources.
    2. Deploy an Event Hubs namespace, which is a container for all Event Hubs.
    3. Create an Event Hub within the namespace.
    4. Create an Azure Logic App.
    5. Add an action within the Logic App workflow that sends events to the Event Hub.

    Below is a Pulumi program written in TypeScript that sets up these Azure resources. This program assumes you have already configured your Pulumi for Azure by setting up the necessary credentials.

    import * as pulumi from "@pulumi/pulumi"; import * as azure from "@pulumi/azure-native"; // Create an Azure resource group const resourceGroup = new azure.resources.ResourceGroup("resourceGroup"); // Create an Event Hubs namespace const namespace = new azure.eventhub.Namespace("namespace", { resourceGroupName: resourceGroup.name, sku: { name: "Standard", }, location: resourceGroup.location, }); // Create an Event Hub inside the namespace const eventHub = new azure.eventhub.EventHub("eventHub", { resourceGroupName: resourceGroup.name, namespaceName: namespace.name, messageRetentionInDays: 1, partitionCount: 2, }); // Create an Azure Logic App const logicApp = new azure.logic.Workflow("logicAppWorkflow", { resourceGroupName: resourceGroup.name, location: resourceGroup.location, definition: { "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#", "contentVersion": "1.0.0.0", "actions": { "Send_event": { "type": "ApiConnection", "runtimeConfiguration": { "contentTransfer": { "transferMode": "Chunked" } }, "inputs": { "host": { "connection": { "name": "@parameters('$connections')['eventhubs']['connectionId']" } }, "method": "post", "path": "/@{encodeURIComponent(encodeURIComponent('your-event-hub-name'))}/messages", "authentication": "@parameters('$authentication')" // You will need to replace 'your-event-hub-name' with your Event Hub name and set authentication parameters } } }, "triggers": { // Define your Logic App's triggers here }, "outputs": {}, "parameters": { "$connections": { "defaultValue": {}, "type": "Object" }, "$authentication": { "defaultValue": {}, "type": "SecureObject" } } }, parameters: { "$connections": { "value": { "eventhubs": { "connectionId": `/subscriptions/${pulumi.config.require("azure:subscriptionId")}/resourceGroups/${resourceGroup.name}/providers/Microsoft.Web/connections/eventhubs-connection`, "connectionName": "eventhubs-connection", "id": `/subscriptions/${pulumi.config.require("azure:subscriptionId")}/providers/Microsoft.Web/locations/${resourceGroup.location}/managedApis/eventhubs` } } } }, }); // Export the resource group name and the created Event Hub name export const resourceGroupName = resourceGroup.name; export const eventHubName = eventHub.name;

    In this program:

    • We use the azure-native package to work with Azure resources.
    • The ResourceGroup is a logical container into which Azure resources are deployed and managed.
    • The Namespace is required by Event Hubs as a scoping container, which provides an isolated environment for the Event Hubs located within it.
    • The actual EventHub is where the events are sent. We've configured it to retain messages for one day and set up two partitions.
    • The Workflow represents the Logic App. The Logic App definition JSON describes the triggers and actions. Here I've set up a placeholder for the Logic App to send events to the Event Hub, but you will need to substitute 'your-event-hub-name' with the actual name of your Event Hub and configure the authentication parameters.
    • Finally, we export the names of the resource group and Event Hub for easy access and reference.

    Note that you need to fill in the authentication details and additional configurations for the Logic App. The triggers for the Logic App will depend on your use case, like a schedule, an HTTP request, or another integration.

    Remember, this program needs to be executed via the Pulumi CLI and assumes that you have set up your Azure credentials for use with Pulumi. Once applied, this program will configure the resources in Azure, but you will still need to set up the specific Logic App triggers and actions according to your business logic.