Use Terraform to manage Microsoft Foundry resources
Use Terraform to automate the creation of Microsoft Foundry resources, projects, deployments, and connections. You can use either the Terraform AzAPI Provider or AzureRM Provider to manage Foundry resources. The AzAPI provider lets you access all Foundry control plane configurations including preview features. The AzureRM variant is limited to core management capabilities. The following table shows which actions each provider supports:| Action | AzAPI Provider | AzureRM Provider |
|---|---|---|
| Create a resource group | ✅ | ✅ |
| Create a Foundry resource | ✅ | ✅ |
| Configure deployments | ✅ | ✅ |
| Configure projects | ✅ | ✅ |
| Configure a connection to knowledge and tools | ✅ | - |
| Configure a capability host (for advanced tool configurations like Agent standard setup) | ✅ | - |
Prerequisites
An Azure account with an active subscription. If you don’t have one, create a free Azure account, which includes a free trial subscription.- Access to a role that allows you to create a Foundry resource, such as Azure Account AI Owner or Azure AI Owner on the subscription or resource group. For more information about permissions, see Role-based access control for Microsoft Foundry.
- Install and configure Terraform.
Create a basic Foundry configuration
- AzAPI Provider
- AzureRM Provider
- Create a directory to test and run the sample Terraform code. Make this directory your current directory.
-
Create a file named
providers.tfand add the following code. -
Create a file named
main.tfand add the following code. -
Create a file named
variables.tfand add the following code.
Initialize Terraform
Create a Terraform execution plan
Apply a Terraform execution plan
Verify your deployment
Runterraform state identities -json to display the deployed resources. The last part of the id shows the resource names.
Customize security and compliance
To meet security and compliance requirements, customize Foundry with security configurations and by bringing your own storage resources. For example, when using the Agent service, you can opt to bring your own Azure Cosmos DB database, Azure AI Search instance, and Azure Storage Account to store your threads and messages. For advanced setup samples, see the following repositories:- Foundry Samples repository contains example Terraform configurations for the most common enterprise security configurations.
- Terraform Azure Verified Module (Cognitive Services account) is a generic module set to manage the Azure resource type used by Foundry, Azure OpenAI, Azure Speech, Azure Language.
- Terraform Azure Verified Pattern Module (Foundry) is a reference implementation for Foundry.
- Terraform Azure Verified Pattern Module (Azure AI and ML Landing Zone) provides a reference for the set of resources typically created alongside Foundry for an end-to-end sample.