Deploying Azure AI Hub, project and a model with terraform
Have you ever wanted to deploy an Azure AI model with Terraform? Here's how to do it. You'll end with an Azure AI Hub, Azure AI Project and a model deployed from Azure AI Studio
I've recently been working on a proof of concept which required using Azure OpenAI.
Last time I did this I clicked through the portal to create an Azure AI Hub. Inside of Azure AI studio I created a project and then deployed a model from the deployments page.
This time the solution I was working on was going to be deployed into production so I wanted it to be 100% configured with code, in order to be self documenting and repeatable.
I found it a lot harder than I expected to get it working.
This worked but it deploys the legacy resource type "Azure OpenAI", if you open the "Azure OpenAI studio" linked from the resource you are recommended to instead use the new approach with the AI Hub.
This blog post will make extensive use of the AzAPI provider due to:
You'll probably want to deploy with all the files up till now and then explore Azure AI Studio to see which model you want to use and see which version is available in your region, this document is good for OpenAI
Permissions:
You'll likely want to provide permissions to the resource so that it can be used, to provide permission to yourself you can do:
Deploy your new AI project
First you'll want to run terraform init
You should see output that ends with something like:
...
Terraform has been successfully initialized!
You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.
If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
Then run a plan to see what will be created:
terraform plan -out tfplan
Review the plan and if it looks good approve it:
terraform apply "tfplan"
Success
You should now have:
a Key Vault
an Application insights
an Azure AI Hub
an Azure AI Project
a model that you can test with Azure AI Studio
The resources should look something like this:
Here is a GitHub repository with all of this included: