// Why this matters
Azure ai foundry terraform automation matters because AI workloads go wrong in a particular way: they start as an experiment on a personal subscription with a key pasted into a notebook, and they become production because nobody paused to move them. By the time security notices, data has been uploaded to a resource nobody governs and a model deployment has consumed a quota nobody planned.
The alternative is not to forbid experiments; it is to make the governed path the fast one. If a team can get a private, correctly permissioned workspace in the time it would take to create an unmanaged one, most will take it. That is a platform engineering problem more than an AI one: templates, identity, quota and policy, delivered as code.
A hub-and-project model maps neatly to that. Shared concerns (network, storage, key vault, monitoring, content safety defaults) are paid for and secured once; each team gets an isolated project with its own identity, connections and deployments.
// The problem
Foundry resources have many moving parts: the hub, projects, the underlying storage account and key vault, optional search and application insights, model deployments with capacity, connections between them and the network plumbing so none of it is public. Wiring these by hand in the portal yields subtly different results every time, and the differences are where data exposure hides.
Identity is the second difficulty. Projects use managed identities to reach storage and other services; if the role assignments are wrong, the symptoms are opaque authorisation errors inside notebooks. If they are too broad, a project can read every other team's data.
Quota is the third. Model capacity is a finite regional pool; unreviewed deployments exhaust it for everyone. And cost: GPU-backed or provisioned throughput deployments can silently dominate a bill without a budget attached to the owning team.
// The solution
The platform repository has a hub module and a project module. The hub module is applied once per environment: a resource group, the hub resource, a storage account and key vault with private endpoints, a Log Analytics workspace and diagnostic settings. The project module is applied per team record: it creates the project under the hub, its managed identity role assignments, the connections the team asked for, the model deployments and a budget. Where the azurerm provider does not yet cover a Foundry resource, the azapi provider fills the gap with the ARM resource types directly.
Teams are described in a small YAML file: name, owner group, region, model deployments (model, version, SKU, capacity) and whether a vector search connection is needed. A pull request that adds the file runs validation (schema, naming, total requested capacity against a ceiling) and a plan. The apply is bound to a protected environment so a platform reviewer approves capacity and access, exactly the model used in From Form to Running Cluster: Self-Service Team Onboarding and Subscription Factory: Customer Onboarding That Starts by Minting Subscriptions.
Access is by group. The team's owner group receives a project-scoped role (a data scientist or developer role, not owner); the project managed identity receives data-plane roles on the hub storage container created for that project, restricted by path or container. No team member receives roles at the hub scope, which is what stops lateral reads.
Governance is policy, not documentation: Azure Policy at the resource group or management group denies public network access on these resource types, restricts model deployments to an allowed list and regions, and requires diagnostic settings. Alternatives we rejected were a Foundry hub per team (high fixed cost and N copies of the plumbing), shared projects with per-user ACLs (no real isolation) and portal-created workspaces blessed after the fact (drift and no audit trail). The identity patterns come from The App Registration Factory That Cannot Hold a Secret and One Config, Two Clouds: Group and Role Management as Code.
- Team recordname, owners, models, capacity, region
- Validateschema, quota ceiling, naming
- PlanTerraform plan for the project module
- Gate: approval gateplatform reviewer for capacity and access
- ProjectFoundry project under the shared hub
- Identityproject managed identity and group role assignments
- Connectionsstorage, key vault and search via private endpoints
- Deploymentsmodel deployments with capacity caps
- Budgetcost alert on the project resource group
// Before you start
- An Azure subscription with quota for the models you plan to deploy in your chosen regions.
- Terraform 1.6+,
azurerm4.x andazapi2.x providers, and remote state. - A virtual network with a subnet for private endpoints and linked private DNS zones for the services used.
- Entra ID groups for team owners (see the group automation posts).
- A pipeline identity with Contributor on the target resource groups and User Access Administrator where it assigns roles.
- Agreement on a capacity ceiling per team and per environment.
// Step-by-step implementation
01 Define the team record and validate it
A single data file per team is the interface. Keep it small and typed; everything optional has a default in the module. The most important fields are the owner group and the model list, because those drive access and quota.
Validate in CI with a JSON schema and a capacity check, so a mistake is a failed check rather than a failed apply.
02 Build the shared hub with private networking
The hub is applied once. Its storage account and key vault have public access disabled and are reachable only through private endpoints, which is the reason the module is not optional: the safest default has to be the only default.
Foundry hubs and projects are
Microsoft.MachineLearningServices/workspaceswith akindofHuborProject. If your provider version lacks a dedicated resource, useazapi_resource.03 Create a project and its identity per team
The project module takes the team record. It creates a project linked to the hub and a container in hub storage for that project's data. The project's managed identity will be granted access to only that container.
Teams never receive hub-scope roles; the project is the unit of isolation.
04 Assign roles to groups and to the project identity
Two assignments carry the whole security model: the team's owner group gets a project-scoped role, and the project managed identity gets data-plane access on its own container only. Scope the storage role to the container, not the account.
Prefer built-in roles; custom roles are warranted only when a built-in role includes permissions you cannot accept.
05 Declare model deployments with capacity caps
Deployments are loops over the team record. Capacity is an explicit number, so quota consumption is visible in the plan and in the review. Attach a content filter policy by default so teams start with the platform's baseline.
Deployments are regional and share a pool; the validation ceiling from step one is what keeps one team from taking all of it.
06 Add budgets and enforce governance with policy
Attach a budget to each team's resource group so spend alerts reach the owners, and assign a policy definition at the platform scope that denies public access and out-of-list models. Policy is the backstop for anything that bypasses the module.
Start with
Auditeffect, read the compliance report, then switch toDeny.07 Wire the pipeline so a pull request is the interface
Run validation and plan on pull request; apply on merge, in a protected environment. Loop over team files with a matrix or a single root using
for_eachoverfileset. A single root is simpler and keeps one state per environment.Post the plan summary back to the pull request so the reviewer approves capacity with the numbers in front of them.
// How to verify it works
az ml workspace show -n proj-team-a -g <rg> --query kindreturnsProjectandpublicNetworkAccessisDisabled.- A member of the owner group can open the project; a user outside the group gets an authorisation error.
az role assignment list --scope <hub-storage-id>shows the project identity only at its container scope.az cognitiveservices account deployment listshows each declared deployment with the declared capacity.- From outside the network, the storage account and key vault are unreachable; from a peered subnet they resolve to private addresses.
// Design decisions and trade-offs
- One shared hub per environment owns networking, storage and key vault; each team gets a project beneath it.
- Teams get roles on their project only; the platform keeps hub-level and policy permissions.
- Model deployments are declared in the team record with capacity limits, so quota is a reviewed decision.
- Public network access is disabled by default and private endpoints are part of the module, not an add-on.
- Governance (allowed models, regions, content filters) is enforced with Azure Policy rather than convention.
// Pitfalls and lessons learned
- Foundry resource types are still evolving; pin
azapiAPI versions and read release notes before bumping. - Model quota and availability vary by region and SKU; a plan that validates can still fail at apply when the pool is exhausted. Check quota before approving.
- Disabling shared key access on storage breaks tools that default to account keys; ensure notebooks and SDKs use Entra authentication.
- Private endpoint DNS is the classic failure: without linked private zones, names resolve to public addresses and calls time out.
- Granting roles at the hub scope "to simplify" silently gives every team read access to every other team's data.
- Managed network outbound rules for package installs and model downloads need to be declared, or notebook environments cannot build.
- Deleting a project does not always delete its deployments or soft-deleted Cognitive Services accounts; purge deliberately during offboarding.
// Frequently asked questions
How do I deploy Azure AI Foundry with Terraform?
Create a hub (a workspace of kind Hub) with its storage and key vault, then projects of kind Project that reference it; use azapi where azurerm lacks a resource.
Hub per team or one shared hub?
One shared hub per environment with a project per team keeps cost and plumbing low while still isolating identity and data.
How do I stop one team consuming all model quota?
Put capacity in the reviewed team record and enforce a per-team ceiling in CI.
How do I keep Foundry traffic off the public internet?
Disable public network access on the hub, project, storage and key vault, add private endpoints and link private DNS zones.
Can I control which models teams may deploy?
Yes, with an allow-list in validation and an Azure Policy assignment as a backstop.
// The outcome
Data scientists get a working, governed workspace within one reviewed change and without waiting for infrastructure, while the platform team keeps one place where networking, identity, quota and policy are defined. Access and spend follow the team record.
// Where to take it next
- Add a shared evaluation project with content safety baselines the platform owns.
- Connect storage and orchestration for data work with ML Data Storage and Orchestration: DVC on Azure Blob and Astronomer Airflow with Terraform.
- Serve self-hosted models alongside managed ones; see Private GKE Cluster with Self-Hosted Chat on Operators for a comparable private-serving design.
- Add cost reports per cost centre using the budgets and tags created here.