1. Using azure portal with loganalyticsworkspace

    TypeScript

    If you want to use Azure Portal to work with a Log Analytics Workspace using Pulumi, you'll need to define a Log Analytics Workspace resource within your Pulumi program. In Azure, a Log Analytics Workspace is a unique environment for Azure Monitor log data. Each workspace has its own data repository and configuration, and data sources and solutions are configured to store their data in a particular workspace.

    Below you will find a TypeScript program that defines a Log Analytics Workspace using @pulumi/azure-native. The azure-native provider is the Pulumi native Azure provider which maps directly to Azure Resource Manager API, hence it's the latest and preferred over the azure classic package.

    We will define an azure-native.operationalinsights.Workspace resource, which corresponds to the Log Analytics Workspace in Azure. This will create a workspace which you can then interact with through the Azure Portal.

    import * as pulumi from "@pulumi/pulumi"; import * as azure_native from "@pulumi/azure-native"; // Create an Azure Resource Group const resourceGroup = new azure_native.resources.ResourceGroup("my-resource-group"); // Create an Azure Log Analytics Workspace const workspace = new azure_native.operationalinsights.Workspace("my-workspace", { resourceGroupName: resourceGroup.name, location: resourceGroup.location, sku: { name: "PerGB2018", // This is generally the most flexible pricing tier }, retentionInDays: 30, // Data retention period in days }); // Export the Workspace ID and the Workspace URL, which can be used to access the workspace in Azure Portal. export const workspaceId = workspace.id; export const workspaceUrl = pulumi.interpolate`https://portal.azure.com/#resource${workspace.id}`;

    Let's break down what's happening in the program above:

    1. We import the necessary modules from Pulumi: pulumi for general Pulumi functionalities, and azure_native which contains the Azure resources we can create and manage.

    2. We create an Azure resource group using azure_native.resources.ResourceGroup. This acts as a container that holds related resources for an Azure solution.

    3. Then we create the Log Analytics Workspace itself using azure_native.operationalinsights.Workspace. We pass in the name of the resource group we previously created, a geographic location for our resources, the pricing tier, and a data retention period. The name "PerGB2018" for sku.name represents a flexible pricing model which is good for generic cases.

    4. Finally, we export the workspaceId and workspaceUrl. The workspaceId is the unique identifier for the workspace in Azure, and the workspaceUrl is a convenient URL that will take you directly to the workspace in the Azure Portal. The pulumi.interpolate function is used here to construct the URL using the workspace ID.

    This Pulumi program describes the desired state of your cloud resources. To bring up this infrastructure, you would run pulumi up. Pulumi takes care of making the necessary calls to Azure to create or update your resources according to this program.

    Remember that before running the Pulumi program, you will need to have the Pulumi CLI installed, be logged in and have your Azure credentials configured appropriately. You can find more information on how to set up Pulumi and authenticate with Azure here.