This post is a follow up to a write up a few months back where I used PowerShell to deploy a ChatGPT service:
Deploy a ChatGPT service with Azure OpenAI Service in 6 minutes with PowerShell
While PowerShell can certainly deploy and configure Azure resources, it’s an imperative way that cannot be executed more than once. The obvious better choice is to use a declarative method where we define the state of the deployment rather than creating the deployment through a series of steps. My choice of tool has and still is Terraform, and I have created a set of files that can be found at my GitHub repo:Â https://github.com/terenceluk/terraform-az-openai-container-app-chatbot
The following is a diagram of the resources deployed:
The purpose of the Terraform code is to demonstrate the following:
- Deploy and configure an App Registration
- Deploy and configure OpenAI with the Terraform Registry OpenAI module (https://registry.terraform.io/modules/Azure/openai/azurerm/latest)
- Deploy and configure a Container App Environment
- Deploy and configure a Container App
- Use an external GitHub repo container image for the Chatbot UI
- Use azapi to configure the Authentication of the Container App as the current azurerm does not provide this functionality
- Deploy and configure Log Analytics for the Container App and Azure OpenAI
Simply clone the repo and run :
terraform init
Then the following plan to review the resources that will be deployed and configured:
terraform plan -var-file=”openai.tfvars”
Then run the following to deploy (-auto-approve will bypass the confirmation):
terraform apply -var-file=”openai.tfvars” -auto-approve
The following outputs will be provided in the console and any sensitive values can be displayed in the console with:
terraform output -raw openai_primary_key
To tear down, execute the following:
terraform apply -var-file=”openai.tfvars” -destroy -auto-approve
I’ve timed the deployment and the deployment consistently runs between 1 minute and 47 minutes and 2 minutes. The tear down takes around 5 minutes.
Note that this deployment does not leverage any virtual networks or private endpoints so I’ll be following up with another post that provides the additional resources.
Hope this helps anyone who may be looking for a set of Terraform code that will deploy a Chatbot from start to finish through a declarative method in less than 10 minutes.