Skip to content

Commit c08e733

Browse files
committed
Fixes
1 parent c40b313 commit c08e733

File tree

5 files changed

+37
-44
lines changed

5 files changed

+37
-44
lines changed

scenarios/AksOpenAiTerraform/README.md

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,50 +11,39 @@ ms.custom: innovation-engine, linux-related-content
1111
## Provision Resources
1212
Run terraform to provision all the required Azure resources
1313
```bash
14-
# DELETE
15-
export EMAIL="ariaamini@microsoft.com"
16-
export SUBSCRIPTION_ID="b7684763-6bf2-4be5-8fdd-f9fadb0f27a1"
14+
# Terraform parses TF_VAR_* (Ex: TF_VAR_xname -> xname)
15+
export TF_VAR_location="westus3"
16+
export TF_VAR_kubernetes_version="1.30.7"
17+
export TF_VAR_model_name="gpt-4o-mini"
18+
export TF_VAR_model_version="2024-07-18"
1719

18-
# Define input vars
19-
export LOCATION="westus3"
20-
export KUBERNETES_VERSION="1.30.7"
21-
export AZURE_OPENAI_MODEL="gpt-4o-mini"
22-
export AZURE_OPENAI_VERSION="2024-07-18"
23-
24-
# Run Terraform
25-
export TF_VAR_location=$LOCATION # $TF_VAR_example_name will be read as var example_name by terraform.
26-
export TF_VAR_kubernetes_version=$KUBERNETES_VERSION
27-
export TF_VAR_model_name=$AZURE_OPENAI_MODEL
28-
export TF_VAR_model_version=$AZURE_OPENAI_VERSION
29-
export ARM_SUBSCRIPTION_ID=$SUBSCRIPTION_ID # Used by terraform to find sub.
3020
terraform -chdir=infra init
31-
terraform -chdir=infra apply
32-
33-
# Save outputs
34-
export RESOURCE_GROUP=$(terraform -chdir=infra output -raw resource_group_name)
35-
export WORKLOAD_IDENTITY_CLIENT_ID=$(terraform -chdir=infra output -raw workload_identity_client_id)
36-
export AZURE_OPENAI_ENDPOINT=$(terraform -chdir=infra output -raw openai_endpoint)
37-
export ACR_LOGIN_URL=$(terraform -chdir=infra output -raw acr_login_url)
38-
export IMAGE="$ACR_LOGIN_URL/magic8ball:v1"
21+
terraform -chdir=infra apply -auto-approve
3922
```
4023

41-
# Login to AKS
24+
## Login to Cluster
4225
```bash
26+
RESOURCE_GROUP=$(terraform -chdir=infra output -raw resource_group_name)
4327
az aks get-credentials --admin --name AksCluster --resource-group $RESOURCE_GROUP --subscription $SUBSCRIPTION_ID
4428
```
4529

46-
## Build Dockerfile
30+
## Deploy
4731
```bash
32+
## Build Dockerfile
33+
ACR_LOGIN_URL=$(terraform -chdir=infra output -raw acr_login_url)
34+
IMAGE="$ACR_LOGIN_URL/magic8ball:v1"
4835
az acr login --name $ACR_LOGIN_URL
4936
docker build -t $IMAGE ./magic8ball --push
50-
```
5137

52-
# Deploy App
53-
```bash
54-
envsubst < quickstart-app.yml | kubectl apply -f -
38+
# Apply Manifest File
39+
export IMAGE
40+
export WORKLOAD_IDENTITY_CLIENT_ID=$(terraform -chdir=infra output -raw workload_identity_client_id)
41+
export AZURE_OPENAI_DEPLOYMENT=$(terraform -chdir=infra output -raw openai_deployment)
42+
export AZURE_OPENAI_ENDPOINT=$(terraform -chdir=infra output -raw openai_endpoint)
43+
envsubst < quickstart-app.yml | kubectl apply -f -```
5544
```
5645

57-
# Wait for public IP
46+
## Wait for public IP
5847
```bash
5948
kubectl wait --for=jsonpath="{.status.loadBalancer.ingress[0].ip}" service/magic8ball-service
6049
PUBLIC_IP=$(kubectl get service/magic8ball-service -o=jsonpath="{.status.loadBalancer.ingress[0].ip}")

scenarios/AksOpenAiTerraform/infra/main.tf

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,11 @@ resource "azurerm_user_assigned_identity" "workload" {
7979
}
8080

8181
resource "azurerm_federated_identity_credential" "this" {
82-
name = "FederatedIdentity"
83-
resource_group_name = azurerm_resource_group.main.name
84-
82+
name = azurerm_user_assigned_identity.workload.name
83+
resource_group_name = azurerm_user_assigned_identity.workload.resource_group_name
84+
parent_id = azurerm_user_assigned_identity.workload.id
8585
audience = ["api://AzureADTokenExchange"]
8686
issuer = azurerm_kubernetes_cluster.main.oidc_issuer_url
87-
parent_id = azurerm_user_assigned_identity.workload.id
8887
subject = "system:serviceaccount:default:magic8ball-sa"
8988
}
9089

@@ -99,11 +98,6 @@ resource "azurerm_cognitive_account" "openai" {
9998
kind = "OpenAI"
10099
custom_subdomain_name = "magic8ball-${local.random_id}"
101100
sku_name = "S0"
102-
public_network_access_enabled = true
103-
104-
identity {
105-
type = "SystemAssigned"
106-
}
107101
}
108102

109103
resource "azurerm_cognitive_deployment" "deployment" {
@@ -121,6 +115,15 @@ resource "azurerm_cognitive_deployment" "deployment" {
121115
}
122116
}
123117

118+
resource "azurerm_role_assignment" "cognitive_services_user" {
119+
scope = azurerm_cognitive_account.openai.id
120+
role_definition_name = "Cognitive Services OpenAI Contributor"
121+
principal_id = azurerm_user_assigned_identity.workload.principal_id
122+
principal_type = "ServicePrincipal"
123+
124+
skip_service_principal_aad_check = true
125+
}
126+
124127
###############################################################################
125128
# Networking
126129
###############################################################################

scenarios/AksOpenAiTerraform/infra/outputs.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,8 @@ output "acr_login_url" {
1212

1313
output "openai_endpoint" {
1414
value = azurerm_cognitive_account.openai.endpoint
15+
}
16+
17+
output "openai_deployment" {
18+
value = azurerm_cognitive_deployment.deployment.name
1519
}

scenarios/AksOpenAiTerraform/magic8ball/app.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66
from azure.identity import DefaultAzureCredential, get_bearer_token_provider
77

88
deployment = os.getenv("AZURE_OPENAI_DEPLOYMENT")
9-
api_version = os.environ.get("AZURE_OPENAI_VERSION")
109
azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT")
1110

1211
client = AzureOpenAI(
13-
api_version=api_version,
12+
api_version="2024-10-21",
1413
azure_endpoint=azure_endpoint,
1514
azure_ad_token_provider=get_bearer_token_provider(
1615
DefaultAzureCredential(), "https://cognitiveservices.azure.com/.default"

scenarios/AksOpenAiTerraform/quickstart-app.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ metadata:
44
name: magic8ball-configmap
55
data:
66
AZURE_OPENAI_ENDPOINT: $AZURE_OPENAI_ENDPOINT
7-
AZURE_OPENAI_MODEL: $AZURE_OPENAI_MODEL
8-
AZURE_OPENAI_DEPLOYMENT: $AZURE_OPENAI_MODEL
9-
AZURE_OPENAI_VERSION: $AZURE_OPENAI_VERSION
7+
AZURE_OPENAI_DEPLOYMENT: $AZURE_OPENAI_DEPLOYMENT
108
---
119
apiVersion: apps/v1
1210
kind: Deployment

0 commit comments

Comments
 (0)