Skip to content

Commit 0faa355

Browse files
authored
Merge pull request #2 from MicrosoftCloudEssentials-LearningHub/terraform-sample
terraform template
2 parents ba5c570 + b8f9f4d commit 0faa355

10 files changed

Lines changed: 263 additions & 35 deletions

File tree

.github/workflows/use-visitor-counter.yml

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ jobs:
2121
uses: actions/checkout@v4
2222
with:
2323
fetch-depth: 0
24+
ref: ${{ github.head_ref || github.ref_name }}
2425

2526
- name: Shallow clone visitor counter logic
2627
run: git clone --depth=1 https://github.com/brown9804/github-visitor-counter.git
@@ -57,30 +58,23 @@ jobs:
5758
git config --global user.name "github-actions[bot]"
5859
git config --global user.email "github-actions[bot]@users.noreply.github.com"
5960
60-
# Commit and push logic for PR events (merge, not rebase)
61-
- name: Commit and push changes (PR)
62-
if: github.event_name == 'pull_request'
61+
- name: Commit and merge changes
6362
env:
64-
TOKEN: ${{ secrets.GITHUB_TOKEN }}
63+
PR_BRANCH: ${{ github.head_ref || github.ref_name }}
64+
GIT_AUTHOR_NAME: github-actions[bot]
65+
GIT_AUTHOR_EMAIL: github-actions[bot]@users.noreply.github.com
66+
GIT_COMMITTER_NAME: github-actions[bot]
67+
GIT_COMMITTER_EMAIL: github-actions[bot]@users.noreply.github.com
6568
run: |
66-
git fetch origin
67-
git checkout ${{ github.head_ref }}
68-
git pull origin ${{ github.head_ref }} || echo "No merge needed"
69+
# Ensure we're on the correct branch
70+
git switch -c "$PR_BRANCH" || git switch "$PR_BRANCH"
71+
72+
# Stage and commit changes if any
6973
git add -A
70-
git commit -m "Update visitor count" || echo "No changes to commit"
71-
git remote set-url origin https://x-access-token:${TOKEN}@github.com/${{ github.repository }}
72-
git push origin HEAD:${{ github.head_ref }}
73-
74-
# Commit and push logic for non-PR events (merge, not rebase)
75-
- name: Commit and push changes (non-PR)
76-
if: github.event_name != 'pull_request'
77-
env:
78-
TOKEN: ${{ secrets.GITHUB_TOKEN }}
79-
run: |
80-
git fetch origin
81-
git checkout ${{ github.ref_name }} || git checkout -b ${{ github.ref_name }} origin/${{ github.ref_name }}
82-
git pull origin ${{ github.ref_name }} || echo "No merge needed"
83-
git add -A
84-
git commit -m "Update visitor count" || echo "No changes to commit"
85-
git remote set-url origin https://x-access-token:${TOKEN}@github.com/${{ github.repository }}
86-
git push origin HEAD:${{ github.ref_name }}
74+
git diff --staged --quiet || git commit -m "Update visitor count"
75+
76+
# Pull and merge existing changes
77+
git pull origin "$PR_BRANCH" --no-rebase
78+
79+
# Push all changes
80+
git push origin "$PR_BRANCH"

.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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# Azure Text Embedding Model Recommendations - Overview
1+
# Azure Text Embedding Model - Overview
22

33
Costa Rica
44

55
[![GitHub](https://badgen.net/badge/icon/github?icon=github&label)](https://github.com)
66
[![GitHub](https://img.shields.io/badge/--181717?logo=github&logoColor=ffffff)](https://github.com/)
77
[brown9804](https://github.com/brown9804)
88

9-
Last updated: 2025-08-20
9+
Last updated: 2025-08-27
1010

1111
-----------------------------
1212

@@ -161,7 +161,7 @@ Last updated: 2025-08-20
161161

162162
<!-- START BADGE -->
163163
<div align="center">
164-
<img src="https://img.shields.io/badge/Total%20views-24-limegreen" alt="Total views">
164+
<img src="https://img.shields.io/badge/Total%20views-1304-limegreen" alt="Total views">
165165
<p>Refresh Date: 2025-08-27</p>
166166
</div>
167167
<!-- END BADGE -->
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# RAG (Retrieval-Augmented Generation) pattern - Overview
1+
# Azure AI Search - Overview
22

33
Costa Rica
44

55
[![GitHub](https://badgen.net/badge/icon/github?icon=github&label)](https://github.com)
66
[![GitHub](https://img.shields.io/badge/--181717?logo=github&logoColor=ffffff)](https://github.com/)
77
[brown9804](https://github.com/brown9804)
88

9-
Last updated: 2025-07-17
9+
Last updated: 2025-08-27
1010

1111
----------
1212

@@ -376,7 +376,7 @@ Click [here](https://github.com/brown9804/MicrosoftCloudEssentialsHub/tree/main/
376376

377377
<!-- START BADGE -->
378378
<div align="center">
379-
<img src="https://img.shields.io/badge/Total%20views-24-limegreen" alt="Total views">
379+
<img src="https://img.shields.io/badge/Total%20views-1304-limegreen" alt="Total views">
380380
<p>Refresh Date: 2025-08-27</p>
381381
</div>
382382
<!-- END BADGE -->

terraform-infrastructure/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ graph TD;
133133

134134
<!-- START BADGE -->
135135
<div align="center">
136-
<img src="https://img.shields.io/badge/Total%20views-24-limegreen" alt="Total views">
136+
<img src="https://img.shields.io/badge/Total%20views-1304-limegreen" alt="Total views">
137137
<p>Refresh Date: 2025-08-27</p>
138138
</div>
139139
<!-- END BADGE -->

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)