Skip to content

Instantly share code, notes, and snippets.

@timmyreilly
Created May 8, 2024 21:04
Show Gist options
  • Save timmyreilly/b273bcc5ab7bb1f13d4e210a16bd74bb to your computer and use it in GitHub Desktop.
Save timmyreilly/b273bcc5ab7bb1f13d4e210a16bd74bb to your computer and use it in GitHub Desktop.
Creating azure openai instance with model deployment
terraform init

terraform plan 

terraform apply --auto-approve 

provide a prefix to keep your resources unique

look for relevant output once the apply is finished

azure_ml_resource_group = "prefixresources"
azure_ml_subscription_id = "your-subscription-id-"
azure_ml_workspace_name = "example-ml-workspace"
openai_api_version = "2023-12-01-preview"
openai_azure_endpoint = "https://southcentralus.api.cognitive.microsoft.com/"
openai_deployment_model = "gpt-35-turbo"
openai_text_embedding_model = "text-curie-001"

and find the api key in the Azure OpenAI > "keys and endpoint"

tear it down

terraform destroy --auto-approve
provider "azurerm" {
features {
resource_group {
prevent_deletion_if_contains_resources = false
}
}
}
variable "prefix" {
description = "Prefix for the resources (rock1)"
}
data "azurerm_client_config" "current" {}
# Resource Group
resource "azurerm_resource_group" "ai_rg" {
name = "${var.prefix}ai-resources"
location = "South Central US"
}
# Azure Machine Learning Workspace
resource "azurerm_machine_learning_workspace" "example" {
name = "example-ml-workspace"
location = azurerm_resource_group.ai_rg.location
resource_group_name = azurerm_resource_group.ai_rg.name
application_insights_id = azurerm_application_insights.example.id
key_vault_id = azurerm_key_vault.example.id
storage_account_id = azurerm_storage_account.example.id
identity {
type = "SystemAssigned"
}
}
# Application Insights for the ML Workspace
resource "azurerm_application_insights" "example" {
name = "example-app-insights"
location = azurerm_resource_group.ai_rg.location
resource_group_name = azurerm_resource_group.ai_rg.name
application_type = "web"
}
# Key Vault for the ML Workspace
resource "azurerm_key_vault" "example" {
name = "${var.prefix}-dev1-kv"
location = azurerm_resource_group.ai_rg.location
resource_group_name = azurerm_resource_group.ai_rg.name
sku_name = "standard"
tenant_id = data.azurerm_client_config.current.tenant_id
purge_protection_enabled = true
}
# Storage Account for the ML Workspace
resource "azurerm_storage_account" "example" {
name = "${var.prefix}mlstudiostorage"
resource_group_name = azurerm_resource_group.ai_rg.name
location = azurerm_resource_group.ai_rg.location
account_tier = "Standard"
account_replication_type = "LRS"
}
# Azure Cognitive Services Account for OpenAI
resource "azurerm_cognitive_account" "example" {
name = "${var.prefix}-ca-ai"
location = azurerm_resource_group.ai_rg.location
resource_group_name = azurerm_resource_group.ai_rg.name
kind = "OpenAI"
sku_name = "S0"
}
# # Cognitive Service Deployment for OpenAI
resource "azurerm_cognitive_deployment" "embedding" {
name = "embedding-curie"
cognitive_account_id = azurerm_cognitive_account.example.id
model {
format = "OpenAI"
name = "text-curie-001"
version = "1"
}
scale {
type = "Standard"
}
}
# Cognitive Service Deployment for OpenAI
resource "azurerm_cognitive_deployment" "text" {
name = "text-gpt-3"
cognitive_account_id = azurerm_cognitive_account.example.id
model {
format = "OpenAI"
name = "gpt-35-turbo"
version = "0125"
}
scale {
type = "Standard"
}
}
# Output Azure ML Subscription ID
output "azure_ml_subscription_id" {
value = data.azurerm_client_config.current.subscription_id
}
# Output Azure ML Resource Group
output "azure_ml_resource_group" {
value = azurerm_resource_group.ai_rg.name
}
# Output Azure ML Workspace Name
output "azure_ml_workspace_name" {
value = azurerm_machine_learning_workspace.example.name
}
output "openai_azure_endpoint" {
value = azurerm_cognitive_account.example.endpoint
}
# Output OpenAI API Version (example setting, adjust as needed)
output "openai_api_version" {
value = "2023-12-01-preview" # Placeholder, replace with actual versioning schema if available
}
# Output OpenAI Deployment Model
output "openai_deployment_model" {
value = azurerm_cognitive_deployment.text.model[0].name
}
# Output OpenAI Text Embedding Model
output "openai_text_embedding_model" {
value = azurerm_cognitive_deployment.embedding.model[0].name
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment