Using azure portal with loganalyticsworkspace
TypeScriptIf 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
. Theazure-native
provider is the Pulumi native Azure provider which maps directly to Azure Resource Manager API, hence it's the latest and preferred over theazure
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:
-
We import the necessary modules from Pulumi:
pulumi
for general Pulumi functionalities, andazure_native
which contains the Azure resources we can create and manage. -
We create an Azure resource group using
azure_native.resources.ResourceGroup
. This acts as a container that holds related resources for an Azure solution. -
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" forsku.name
represents a flexible pricing model which is good for generic cases. -
Finally, we export the
workspaceId
andworkspaceUrl
. TheworkspaceId
is the unique identifier for the workspace in Azure, and theworkspaceUrl
is a convenient URL that will take you directly to the workspace in the Azure Portal. Thepulumi.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.
-