Member-only story
How to Send Azure OpenAI Logs and Events to Azure Log Analytics using Terraform
In this story, we will learn how to send the Azure OpenAI logs to an Azure Log Analytics Workspace using Terraform.
We will deploy an Azure OpenAI (Azure Cognitive Account) with a single ChatGPT deployment and an Azure Log Analyzer Workspace.
Then, we will configure the Azure Cognitive Account to send the logs to the Azure Log Analyzer Workspace.
For simplicity, we are deploying an Azure OpenAI without a Private Endpoint.
If you are looking for an example of deploying an Azure OpenAI with a Private Endpoint, please check the How to Deploy Azure OpenAI with Private Endpoint and ChatGPT using Terraform story.
1. Defining the Azure Provider
First, we will define the Azure authentication variables.
We will use a Service Principal with a Client Secret. Check the link below for more info about Azure authentication for Terraform: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/guides/service_principal_client_secret
variable "azure_subscription_id" {
type = string
description = "Azure Subscription ID"
}
variable "azure_client_id" {
type = string
description = "Azure Client ID"
}
variable "azure_client_secret" {
type = string
description = "Azure Client Secret"
}
variable "azure_tenant_id" {
type = string
description = "Azure Tenant ID"
}
Then, we will configure Terraform and the Azure provider:
# Define Terraform provider
terraform {
required_version = "~> 1.8"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
}
}
}
# Configure the Azure provider
provider "azurerm" {
features {}
environment = "public"
subscription_id = var.azure_subscription_id
client_id = var.azure_client_id
client_secret = var.azure_client_secret
tenant_id = var.azure_tenant_id
}
2. Creating a Resource Group for OpenAI Resources
In this step, we will create an Azure Resource Group to store all the Azure resources created by our Terraform code.