Skip to content

Commit f5ea6c2

Browse files
committed
Fixes
1 parent 69124bd commit f5ea6c2

File tree

6 files changed

+55
-62
lines changed

6 files changed

+55
-62
lines changed

scenarios/AksOpenAiTerraform/README.md

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,41 @@ ms.author: ariaamini
88
ms.custom: innovation-engine, linux-related-content
99
---
1010

11-
## Provision Resources (~10 minutes)
12-
Run terraform to provision all the required Azure resources
11+
## Provision Resources with Terraform (~8 minutes)
12+
Run terraform to provision all the Azure resources required to setup your new OpenAI website.
1313
```bash
14-
# Terraform parses TF_VAR_* (Ex: TF_VAR_xname -> xname)
14+
# Terraform parses TF_VAR_* as vars (Ex: TF_VAR_name -> name)
1515
export TF_VAR_location="westus3"
1616
export TF_VAR_kubernetes_version="1.30.7"
1717
export TF_VAR_model_name="gpt-4o-mini"
1818
export TF_VAR_model_version="2024-07-18"
19-
20-
terraform -chdir=infra init
21-
terraform -chdir=infra apply -auto-approve
19+
# Terraform consumes sub id as $ARM_SUBSCRIPTION_ID
20+
export ARM_SUBSCRIPTION_ID=$SUBSCRIPTION_ID
21+
# Run Terraform
22+
terraform -chdir=terraform init
23+
terraform -chdir=terraform apply -auto-approve
2224
```
2325

2426
## Login to Cluster
27+
In order to use the kubectl to run commands on the newly created cluster, you must first login.
2528
```bash
26-
RESOURCE_GROUP=$(terraform -chdir=infra output -raw resource_group_name)
29+
RESOURCE_GROUP=$(terraform -chdir=terraform output -raw resource_group_name)
2730
az aks get-credentials --admin --name AksCluster --resource-group $RESOURCE_GROUP --subscription $SUBSCRIPTION_ID
2831
```
2932

3033
## Deploy
34+
Apply/Deploy Manifest File
3135
```bash
32-
## Build Dockerfile
33-
ACR_LOGIN_URL=$(terraform -chdir=infra output -raw acr_login_url)
34-
IMAGE="$ACR_LOGIN_URL/magic8ball:v1"
35-
az acr login --name $ACR_LOGIN_URL
36-
docker build -t $IMAGE ./magic8ball --push
37-
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 -```
36+
export IMAGE="aamini8/magic8ball:v1"
37+
export WORKLOAD_IDENTITY_CLIENT_ID=$(terraform -chdir=terraform output -raw workload_identity_client_id)
38+
export AZURE_OPENAI_DEPLOYMENT=$(terraform -chdir=terraform output -raw openai_deployment)
39+
export AZURE_OPENAI_ENDPOINT=$(terraform -chdir=terraform output -raw openai_endpoint)
40+
envsubst < quickstart-app.yml | kubectl apply -f -
4441
```
4542

4643
## Wait for public IP
4744
```bash
48-
kubectl wait --for=jsonpath="{.status.loadBalancer.ingress[0].ip}" service/magic8ball-service
49-
PUBLIC_IP=$(kubectl get service/magic8ball-service -o=jsonpath="{.status.loadBalancer.ingress[0].ip}")
45+
kubectl wait --for=jsonpath="{.status.loadBalancer.ingress[0].ip}" service/magic8ball
46+
PUBLIC_IP=$(kubectl get service/magic8ball -o=jsonpath="{.status.loadBalancer.ingress[0].ip}")
5047
echo "Connect to app: $PUBLIC_IP"
5148
```

scenarios/AksOpenAiTerraform/magic8ball/app.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,25 @@
33
import os
44
from openai import AzureOpenAI
55
import streamlit as st
6-
from azure.identity import DefaultAzureCredential, get_bearer_token_provider
6+
from azure.identity import WorkloadIdentityCredential, get_bearer_token_provider
77

88
azure_deployment = os.getenv("AZURE_OPENAI_DEPLOYMENT")
99
azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT")
10+
workload_identity_client_id = os.getenv("WORKLOAD_IDENTITY_CLIENT_ID")
1011

1112
client = AzureOpenAI(
1213
api_version="2024-10-21",
1314
azure_endpoint=azure_endpoint,
1415
azure_ad_token_provider=get_bearer_token_provider(
15-
DefaultAzureCredential(), "https://cognitiveservices.azure.com/.default"
16+
WorkloadIdentityCredential(client_id=workload_identity_client_id),
17+
"https://cognitiveservices.azure.com/.default",
1618
),
1719
)
1820

1921

2022
def call_api(messages):
2123
completion = client.chat.completions.create(
22-
messages=messages,
23-
model=azure_deployment
24+
messages=messages, model=azure_deployment
2425
)
2526
return completion.choices[0].message.content
2627

scenarios/AksOpenAiTerraform/quickstart-app.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ metadata:
55
data:
66
AZURE_OPENAI_ENDPOINT: $AZURE_OPENAI_ENDPOINT
77
AZURE_OPENAI_DEPLOYMENT: $AZURE_OPENAI_DEPLOYMENT
8+
WORKLOAD_IDENTITY_CLIENT_ID: $WORKLOAD_IDENTITY_CLIENT_ID
89
---
910
apiVersion: apps/v1
1011
kind: Deployment

scenarios/AksOpenAiTerraform/terraform/.terraform.lock.hcl

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scenarios/AksOpenAiTerraform/terraform/main.tf

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
###############################################################################
2+
# Plugin setup
3+
###############################################################################
4+
terraform {
5+
required_providers {
6+
azurerm = {
7+
source = "hashicorp/azurerm"
8+
version = "~> 4.20.0"
9+
}
10+
}
11+
}
12+
13+
provider "azurerm" {
14+
features {}
15+
}
16+
###############################################################################
17+
118
data "azurerm_client_config" "current" {
219
}
320

@@ -161,15 +178,4 @@ resource "azurerm_bastion_host" "this" {
161178
subnet_id = azurerm_subnet.this.id
162179
public_ip_address_id = azurerm_public_ip.this.id
163180
}
164-
}
165-
166-
###############################################################################
167-
# Container Registry
168-
###############################################################################
169-
resource "azurerm_container_registry" "this" {
170-
name = "acr${local.random_id}"
171-
resource_group_name = azurerm_resource_group.main.name
172-
location = var.location
173-
sku = "Premium"
174-
anonymous_pull_enabled = true
175181
}

scenarios/AksOpenAiTerraform/terraform/provider.tf

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)