Skip to content

Commit 2f1efb2

Browse files
committed
terraform template
1 parent ba5c570 commit 2f1efb2

8 files changed

Lines changed: 240 additions & 6 deletions

File tree

.gitignore

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Local .terraform directories
2-
.terraform/
2+
*.terraform**
33

44
# .tfstate files
55
*.tfstate
@@ -13,7 +13,6 @@ crash.*.log
1313
# password, private keys, and other secrets. These should not be part of version
1414
# control as they are data points which are potentially sensitive and subject
1515
# to change depending on the environment.
16-
*.tfvars
1716
*.tfvars.json
1817

1918
# Ignore override files as they are usually used to override resources locally and so
@@ -25,7 +24,7 @@ override.tf.json
2524

2625
# Ignore transient lock info files created by terraform apply
2726
.terraform.tfstate.lock.info
28-
27+
.terraform.lock.hcl
2928
# Include override files you do wish to add to version control using negated pattern
3029
# !example_override.tf
3130

@@ -34,4 +33,4 @@ override.tf.json
3433

3534
# Ignore CLI configuration files
3635
.terraformrc
37-
terraform.rc
36+
terraform.rc

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Azure Text Embedding Model Recommendations - Overview
1+
# Azure Text Embedding Model - Overview
22

33
Costa Rica
44

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# RAG (Retrieval-Augmented Generation) pattern - Overview
1+
# Azure AI Search - Overview
22

33
Costa Rica
44

terraform-infrastructure/main.tf

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
// Retrieve client config – helpful for role assignments.
2+
data "azurerm_client_config" "example" {}
3+
4+
// Optionally, retrieve your own Azure AD user info.
5+
data "azuread_user" "current" {
6+
object_id = data.azurerm_client_config.example.object_id
7+
}
8+
9+
// Resource Group
10+
resource "azurerm_resource_group" "rg" {
11+
name = var.resource_group_name
12+
location = var.location
13+
tags = {
14+
Project = "AI Agents"
15+
}
16+
}
17+
18+
// Key Vault
19+
resource "azurerm_key_vault" "example" {
20+
name = var.keyvault_name
21+
location = azurerm_resource_group.rg.location
22+
resource_group_name = azurerm_resource_group.rg.name
23+
tenant_id = data.azurerm_client_config.example.tenant_id
24+
25+
sku_name = "standard"
26+
purge_protection_enabled = true
27+
}
28+
29+
// Key Vault Policies
30+
resource "azurerm_key_vault_access_policy" "example" {
31+
key_vault_id = azurerm_key_vault.example.id
32+
tenant_id = data.azurerm_client_config.example.tenant_id
33+
object_id = data.azurerm_client_config.example.object_id
34+
35+
key_permissions = [
36+
"Create",
37+
"Get",
38+
"Delete",
39+
"Purge",
40+
"GetRotationPolicy",
41+
]
42+
}
43+
44+
// Storage Account
45+
resource "azurerm_storage_account" "example" {
46+
name = var.storage_account_name
47+
location = azurerm_resource_group.rg.location
48+
resource_group_name = azurerm_resource_group.rg.name
49+
account_tier = "Standard"
50+
account_replication_type = "LRS"
51+
}
52+
53+
// AI Services Account
54+
resource "azurerm_ai_services" "aiserviceaccount" {
55+
name = var.aiservices_name
56+
location = azurerm_resource_group.rg.location
57+
resource_group_name = azurerm_resource_group.rg.name
58+
sku_name = "S0"
59+
}
60+
61+
// AI Foundry
62+
resource "azurerm_ai_foundry" "aifoundry" {
63+
name = var.aifoundry_name
64+
location = azurerm_ai_services.aiserviceaccount.location
65+
resource_group_name = azurerm_ai_services.aiserviceaccount.resource_group_name
66+
storage_account_id = azurerm_storage_account.example.id
67+
key_vault_id = azurerm_key_vault.example.id
68+
69+
identity {
70+
type = "SystemAssigned"
71+
}
72+
73+
}
74+
75+
// AI Foundry Project
76+
resource "azurerm_ai_foundry_project" "aiproject" {
77+
name = var.aifoundryproject_name
78+
location = azurerm_ai_foundry.aifoundry.location
79+
ai_services_hub_id = azurerm_ai_foundry.aifoundry.id
80+
81+
identity {
82+
type = "SystemAssigned"
83+
}
84+
}
85+
86+
87+
// Azure Open AI (Cognitive Services) Account
88+
resource "azurerm_cognitive_account" "openai" {
89+
name = var.openai_account_name
90+
location = azurerm_resource_group.rg.location
91+
resource_group_name = azurerm_resource_group.rg.name
92+
sku_name = "S0"
93+
kind = "OpenAI"
94+
tags = {
95+
Project = "AI Agents"
96+
}
97+
}
98+
99+
// Azure Cognitive Search Service
100+
resource "azurerm_search_service" "search" {
101+
name = var.search_service_name
102+
location = azurerm_resource_group.rg.location
103+
resource_group_name = azurerm_resource_group.rg.name
104+
sku = "standard"
105+
partition_count = 1
106+
replica_count = 1
107+
tags = {
108+
Project = "AI Agents"
109+
}
110+
}
111+
112+
113+
// Role Assignments for Permissions
114+
resource "azurerm_role_assignment" "ai_developer" {
115+
principal_id = var.developer_principal_id # or object_id
116+
scope = azurerm_resource_group.rg.id
117+
role_definition_name = "Azure AI Developer"
118+
}
119+
120+
resource "azurerm_role_assignment" "openai_user" {
121+
principal_id = var.openai_user_object_id # or we can use object_id
122+
scope = azurerm_resource_group.rg.id
123+
role_definition_name = "Cognitive Services OpenAI User"
124+
}
125+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
output "resource_group_id" {
2+
value = azurerm_resource_group.rg.id
3+
}
4+
5+
output "openai_account_id" {
6+
value = azurerm_cognitive_account.openai.id
7+
}
8+
9+
output "search_service_name" {
10+
value = azurerm_search_service.search.name
11+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# provider.tf
2+
# This file configures the Azure provider to interact with Azure resources.
3+
# It specifies the required provider and its version, along with provider-specific configurations.
4+
5+
terraform {
6+
required_version = ">= 1.8, < 2.0"
7+
# Specify the required provider and its version
8+
required_providers {
9+
azurerm = {
10+
source = "hashicorp/azurerm" # Source of the AzureRM provider
11+
version = "~> 4.30.0" # Version of the AzureRM provider
12+
}
13+
azuread = {
14+
source = "hashicorp/azuread"
15+
version = "~> 2.38.0"
16+
}
17+
}
18+
}
19+
20+
provider "azurerm" {
21+
features {} # Enable all features for the AzureRM provider
22+
subscription_id = var.subscription_id # Add your subscription ID here
23+
}
24+
25+
provider "azuread" {
26+
# Defaults are usually sufficient.
27+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
subscription_id = "<your_subscription_id>"
2+
resource_group_name = "RG-Embedding-Btest"
3+
location = "East US"
4+
storage_account_name = "aiembeddingbx1"
5+
aiservices_name = "aiservicesbx1"
6+
keyvault_name = "aiembeddingkvbx1"
7+
aifoundry_name = "aifoundrytestbx1"
8+
aifoundryproject_name = "projectnametestbx1"
9+
openai_account_name = "aoaibx1test"
10+
search_service_name = "aisearchbx1test"
11+
developer_principal_id = "<your_developer_principal_id>"
12+
openai_user_object_id = "<your_openai_user_object_id>"
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
variable "subscription_id" {
2+
description = "Azure subscription ID"
3+
type = string
4+
}
5+
6+
variable "location" {
7+
description = "Azure region"
8+
type = string
9+
default = "East US"
10+
}
11+
12+
variable "resource_group_name" {
13+
description = "Name of the resource group for the AI Foundry Project"
14+
type = string
15+
}
16+
17+
variable "keyvault_name" {
18+
description = "The name of the key vault"
19+
type = string
20+
}
21+
22+
variable "aiservices_name" {
23+
description = "The name of the AI services account"
24+
type = string
25+
}
26+
27+
variable "aifoundry_name" {
28+
description = "The name of the AI Foundry Hub"
29+
type = string
30+
}
31+
32+
variable "aifoundryproject_name" {
33+
description = "The name of the AI Foundry Project"
34+
type = string
35+
}
36+
37+
variable "storage_account_name" {
38+
description = "The name of the storage account"
39+
type = string
40+
}
41+
42+
variable "openai_account_name" {
43+
description = "Name of the Azure OpenAI (Cognitive Services) account"
44+
type = string
45+
}
46+
47+
variable "search_service_name" {
48+
description = "Name of the Azure Cognitive Search service"
49+
type = string
50+
}
51+
52+
variable "developer_principal_id" {
53+
description = "Principal ID for the Azure AI Developer (assigned at the resource group level)"
54+
type = string
55+
}
56+
57+
variable "openai_user_object_id" {
58+
description = "Object ID for the Cognitive Services Open AI User (assigned at the resource group level)"
59+
type = string
60+
}

0 commit comments

Comments
 (0)