1. Creating a Log Analytics Workspace for centralized log management

    TypeScript

    Creating a Log Analytics Workspace on Microsoft Azure allows you to collect, aggregate, and analyze data from various sources in one centralized location. This can be useful for monitoring the health and performance of your applications, as well as for incident response and compliance purposes.

    In this Pulumi program, we will use the azure-native provider, which is the Pulumi provider for Azure that provides access to all of the services in the Azure Resource Manager (ARM) API, including the Azure Log Analytics Workspace.

    We will be creating an instance of Workspace, which represents a Log Analytics Workspace on Azure for storing and querying logging data. We will specify a few properties such as location and SKU, which determine where the workspace will be located and what type of features it will support.

    Below is the TypeScript code that creates a Log Analytics Workspace:

    import * as pulumi from "@pulumi/pulumi"; import * as azure_native from "@pulumi/azure-native"; const resourceGroupName = 'my-rg'; // Specify your resource group name const workspaceName = 'my-log-analytics-workspace'; // Specify your Log Analytics Workspace name const location = 'East US'; // Specify your Azure region // Create a new Log Analytics Workspace const logAnalyticsWorkspace = new azure_native.operationalinsights.Workspace(workspaceName, { // Use an existing or new resource group resourceGroupName: resourceGroupName, // Give the workspace a name workspaceName: workspaceName, // Set the location for your workspace location: location, // Define the SKU for the workspace. Here, "PerGB2018" refers to a pricing tier that is based on the amount of data ingested. sku: { name: "PerGB2018", }, // Optional: Set your retention in days. By default, it's 30 days. retentionInDays: 30, // Optional: Define additional settings like network access or identity // Further customization options can be provided here as required. }); // Export the important endpoints export const workspaceId = logAnalyticsWorkspace.id;

    Within this code snippet, we instantiate a new workspace within a specified resource group and with a defined location. We apply the "PerGB2018" SKU, which is a common choice that allows you to pay for the workspace based on the volume of data ingested. The retentionInDays property specifies how long the data will be retained, which we've set as 30 days in this example but can be adjusted based on your needs.

    The export statement at the end is used to export the workspace id which could be used elsewhere, such as by other Pulumi programs or by external systems which may need to refer to this workspace through its unique identifier.

    Make sure to adjust the variables resourceGroupName, workspaceName, and location to fit your Azure setup.

    After writing this code in a .ts file, you will need to run the following commands to create the infrastructure:

    • pulumi stack init to create a new stack.
    • pulumi up to provision the resources in Azure. This command will show you a preview of the resources that will be created and prompt you for confirmation before making any changes to your cloud resources.

    This is a simple setup with plenty of room for customization. For example, you can configure additional workspace settings such as network access controls, set up linked services, and specify additional tags. Feel free to explore these options based on the requirements of your centralized logging solution.