How to Create an Azure OpenAI Resource and Model Deployment Using Terraform

In this Azure and Terraform blog post, we’ll show how to create an Azure OpenAI resource and model deployment Using 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.

  1. Install Terraform: Before you begin, ensure you have Terraform installed on your machine.
  2. Provider Configuration: The first step in the Terraform script is to configure the Azure provider. This allows Terraform to interact with your Azure subscription.
  3. Create a Resource Group: Resource groups in Azure are logical containers where Azure resources are deployed and managed.
  4. Create an Azure OpenAI Resource: This resource represents the Azure Cognitive Service’s OpenAI instance.
  5. 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 Create an Azure OpenAI Resource and Model Deployment Using 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 =
    location            = azurerm_resource_group.example.location
    sku_name            = "S0"
    kind                = "OpenAI"

resource "azurerm_cognitive_deployment" "example" {
    name                 = "gpt4"
    cognitive_account_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:

  1. 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
  2. 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
  3. 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.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.