In thisย ย Azureย and Terraform blog post, weโll show how to Deploy Azure OpenAI Resource and Model with Terraform.
Terraform is an open-source infrastructure as a code software tool that enables you to safely and predictably create, change, and improve infrastructure.
Below is the Terraform code needed to achieve this. Weโll create a resource group, an Azure OpenAI resource, and deploy a model.
- Install Terraform: Before you begin, ensure you have Terraform installed on your machine.
- Provider Configuration: The first step in the Terraform script is to configure the Azure provider. This allows Terraform to interact with your Azure subscription.
- Create a Resource Group: Resource groups in Azure are logical containers where Azure resources are deployed and managed.
- Create an Azure OpenAI Resource: This resource represents the Azure Cognitive Serviceโs OpenAI instance.
- Deploy a Model: Finally, weโll deploy the GPT-4 model on the Azure OpenAI resource. Here, you specify the model and the scale settings.
How to Deploy Azure OpenAI Resource and Model with Terraform
Use the code below to deploy the resource and model.
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "example" {
name = "rg-terraform-ai"
location = "east US"
}
resource "azurerm_cognitive_account" "example" {
name = "aoi-terraform-ai"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
sku_name = "S0"
kind = "OpenAI"
}
resource "azurerm_cognitive_deployment" "example" {
name = "gpt4"
cognitive_account_id = azurerm_cognitive_account.example.id
model {
format = "OpenAI"
name = "gpt-4"
#version = "0613" # you can set a model version or remove for default
}
scale {
type = "Standard"
}
}
Applying the Configuration
To apply this Terraform configuration, follow these steps:
- Initialize Terraform: Runย
terraform initย to initialize your working directory containing the Terraform configuration files. This step is required to download the provider specified in the configuration.ยerraform init - Plan the Deployment: Runย
terraform planย to create an execution plan. This command helps you see the changes that Terraform will make to your infrastructure.ยterraform plan - Apply the Configuration: Finally, runย
terraform applyย to create the resources defined in your configuration.ยterraform applyย Confirm the operation by typingยyesย when prompted.
Related Posts
Discover more from CPI Consulting -Specialist Azure Consultancy
Subscribe to get the latest posts sent to your email.