Skip to content

Commit b18d33f

Browse files
authored
AzureRM basic sample (#327)
* aoai template * azurerm basic sample * update one at a time
1 parent 41d9069 commit b18d33f

File tree

9 files changed

+201
-1
lines changed

9 files changed

+201
-1
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
---
2+
description: This set of templates demonstrates how to set up Azure AI Foundry in the basic configuration with public network setup and Microsoft-managed storage resources using AzureRM provider.
3+
page_type: sample
4+
products:
5+
- azure
6+
- azure-resource-manager
7+
urlFragment: foundry-basic
8+
languages:
9+
- hcl
10+
---
11+
12+
# Azure AI Foundry: Basic setup with public networking (AzureRM)
13+
14+
## Key Information
15+
16+
This infrastructure-as-code (IaC) solution deploys Azure AI Foundry with public networking and uses Microsoft-managed storage for file upload experience. It supports getting started scenarios, for typically non-enterprise scenarios. This variant shows AzureRM Terraform provider.
17+
18+
## Prerequisites
19+
20+
1. **Active Azure subscription(s) with appropriate permissions**
21+
It's recommended to deploy these templates through a deployment pipeline associated to a service principal or managed identity with sufficient permissions over the the workload subscription (such as Owner or Role Based Access Control Administrator and Contributor). If deployed manually, the permissions below should be sufficient.
22+
23+
- **Workload Subscription**
24+
- **Role Based Access Control Administrator**: Needed over the resource group to create the relevant role assignments
25+
- **Network Contributor**: Needed over the resource group to create virtual network and Private Endpoint resources
26+
- **Azure AI Account Owner**: Needed to create a cognitive services account and project
27+
- **Owner or Role Based Access Administrator**: Needed to assign RBAC to the required resources (Cosmos DB, Azure AI Search, Storage)
28+
- **Azure AI User**: Needed to create and edit agents
29+
30+
2. **Register Resource Providers**
31+
32+
```bash
33+
az provider register --namespace 'Microsoft.CognitiveServices'
34+
```
35+
36+
3. Sufficient quota for all resources in your target Azure region
37+
38+
4. Azure CLI installed and configured on your local workstation or deployment pipeline server
39+
40+
5. Terraform CLI version v1.11.4 or later on your local workstation or depoyment pipeline server. This template requires the usage of both the AzureRm and AzApi Terraform providers.
41+
42+
### Variables
43+
44+
The variables listed below [must be provided](https://developer.hashicorp.com/terraform/language/values/variables#variable-definition-precedence) when performing deploying the templates. The file example.tfvars provides a sample Terraform variables file that can be used.
45+
46+
- **location** - The Azure region the resources will be deployed to. This must be the same region where the pre-existing virtual network has been deployed to.
47+
48+
The variables listed below are optional and if not specified will use the defaults as included in the variables.tf file.
49+
50+
## Deploy the Terraform template
51+
52+
1. Fill in the required information for the variables listed in the example.tfvars file and rename the file to terraform.tfvars.
53+
54+
2. If performing the deployment interactively, log in to Az CLI with a user that has sufficient permissions to deploy the resources.
55+
56+
```bash
57+
az login
58+
```
59+
60+
3. Ensure the proper environmental variables are set for [AzApi](https://registry.terraform.io/providers/Azure/azapi/latest/docs) and [AzureRm](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs) providers. At a minimum, you must set the ARM_SUBSCRIPTION_ID environment variable to the subscription the resoruces will be deployed to. You can do this with the commands below:
61+
62+
Linux/MacOS
63+
```bash
64+
export ARM_SUBSCRIPTION_ID="YOUR_SUBSCRIPTION_ID"
65+
terraform apply
66+
```
67+
68+
Windows
69+
```cmd
70+
set ARM_SUBSCRIPTION_ID="YOUR_SUBSCRIPTION_ID"
71+
terraform apply
72+
```
73+
74+
4. Initialize Terraform
75+
76+
```bash
77+
terraform init
78+
```
79+
80+
5. Deploy the resources
81+
```bash
82+
terraform apply
83+
```
84+
85+
## Module Structure
86+
87+
```text
88+
code/
89+
├── data.tf # Creates data objects for active subscription being deployed to and deployment security context
90+
├── locals.tf # Creates local variables for project GUID
91+
├── main.tf # Main deployment file
92+
├── outputs.tf # Placeholder file for future outputs
93+
├── providers.tf # Terraform provider configuration
94+
├── example.tfvars # Sample tfvars file
95+
├── variables.tf # Terraform variables
96+
├── versions.tf # Configures minimum Terraform version and versions for providers
97+
```
98+
99+
100+
## References
101+
102+
- [Learn more about Azure AI Foundry architecture](https://learn.microsoft.com/en-us/azure/ai-foundry/concepts/architecture)
103+
- [Azure AI Foundry reference docs for Terraform](https://learn.microsoft.com/en-us/azure/ai-foundry/how-to/create-resource-terraform)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
location = "eastus"
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
## Create a random string
2+
##
3+
resource "random_string" "unique" {
4+
length = 5
5+
min_numeric = 5
6+
numeric = true
7+
special = false
8+
lower = true
9+
upper = false
10+
}
11+
12+
## Create a resource group for the resources to be stored in
13+
##
14+
resource "azurerm_resource_group" "rg" {
15+
name = "rg-aifoundry${random_string.unique.result}"
16+
location = var.location
17+
}
18+
19+
## Create an AI Foundry resource
20+
##
21+
22+
resource "azurerm_cognitive_account" "ai_foundry" {
23+
name = "aifoundry${random_string.unique.result}"
24+
location = var.location
25+
resource_group_name = azurerm_resource_group.rg.name
26+
kind = "AIServices"
27+
28+
identity {
29+
type = "SystemAssigned"
30+
}
31+
32+
sku_name = "S0"
33+
34+
# required for stateful development in Foundry including agent service
35+
custom_subdomain_name = "aifoundry${random_string.unique.result}"
36+
project_management_enabled = true
37+
38+
tags = {
39+
Acceptance = "Test"
40+
}
41+
}
42+
43+
## Create a deployment for OpenAI's GPT-4o in the AI Foundry resource
44+
##
45+
resource "azurerm_cognitive_deployment" "aifoundry_deployment_gpt_4o" {
46+
depends_on = [
47+
azurerm_cognitive_account.ai_foundry
48+
]
49+
50+
name = "gpt-4o"
51+
cognitive_account_id = azurerm_cognitive_account.ai_foundry.id
52+
53+
sku {
54+
name = "GlobalStandard"
55+
capacity = 1
56+
}
57+
58+
model {
59+
format = "OpenAI"
60+
name = "gpt-4o"
61+
version = "2024-11-20"
62+
}
63+
}

samples/microsoft/infrastructure-setup-terraform/00-basic-azurerm/code/outputs.tf

Whitespace-only changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Setup providers
2+
provider "azapi" {
3+
}
4+
5+
provider "azurerm" {
6+
features {}
7+
storage_use_azuread = true
8+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
variable "location" {
2+
description = "The name of the location to provision the resources to"
3+
type = string
4+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Configure the AzApi and AzureRM providers
2+
terraform {
3+
required_providers {
4+
azapi = {
5+
source = "azure/azapi"
6+
version = "~> 2.5"
7+
}
8+
azurerm = {
9+
source = "hashicorp/azurerm"
10+
version = "~> 4.37"
11+
}
12+
random = {
13+
source = "hashicorp/random"
14+
version = "~> 3.7"
15+
}
16+
}
17+
required_version = ">= 1.10.0, < 2.0.0"
18+
# Uncomment to store state in Azure Storage
19+
# backend "azurerm" {}
20+
}

samples/microsoft/infrastructure-setup-terraform/00-basic/code/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ resource "azurerm_resource_group" "rg" {
2424
resource "azapi_resource" "ai_foundry" {
2525
type = "Microsoft.CognitiveServices/accounts@2025-06-01"
2626
name = "aifoundry${random_string.unique.result}"
27-
parent_id = azurerm_resource_group.rg.id
27+
parent_id = azurerm_resource_group.rg.name
2828
location = var.location
2929
schema_validation_enabled = false
3030

0 commit comments

Comments
 (0)