最終確認: 2026年5月
AI-102 試験の対象となる AWS サービスを、プレーンな Terraform を使用して構築します。1 ブロックずつ、それぞれ試験ドメインに関連付けられています。同じコードが OpenTofu でも動作します。
このラボの終了までに、シンプルなTerraformを使って、RAGスタイルのAzure AIアプリケーションの基盤をプロビジョニングします。具体的には、Claude / GPTクラスのチャットモデルをデプロイしたAzure OpenAIアカウント、検索インデックス用のAzure AI Searchサービス、ソースドキュメント用のストレージアカウント、APIキーを保持するKey Vaultを構築します。AI-102の参照アーキテクチャを構成する5つのブロックです。
これらのスニペットを単一の main.tf ファイルにまとめて、terraform init を実行し、その後 terraform apply をステップバイステップで実行してください。
>= 1.5 または OpenTofu >= 1.6。az login)。azurerm_cognitive_account の初回作成時に一度必要となります)。Azure AI Search Basicが主な費用で、月額$75です。コストに敏感な場合はFreeティア(sku = "free")に切り替えてください。それでもラボのアーキテクチャは実演できます。
標準的なAzureの開始部分です。AI-102では、最新のAzure OpenAIモデルが利用可能な eastus または westus を使用することが期待されています — 古いリージョンではGPT-4ファミリーがすぐに利用可能になりません。
terraform {
required_version = ">= 1.5"
required_providers {
azurerm = { source = "hashicorp/azurerm", version = "~> 4.0" }
random = { source = "hashicorp/random", version = "~> 3.6" }
}
}
provider "azurerm" {
features {
key_vault {
purge_soft_delete_on_destroy = true
}
}
}
resource "random_id" "suffix" {
byte_length = 3
}
data "azurerm_client_config" "current" {}
locals {
tags = {
Project = "certlabpro-ai-102"
ManagedBy = "terraform"
}
}
resource "azurerm_resource_group" "main" {
name = "certlabpro-ai-102-rg"
location = "eastus"
tags = local.tags
}Azure OpenAIは、AI-102における本番環境のGenAIエンジンです。アカウント(kind = "OpenAI")を作成し、チャットモデルとして gpt-4o-mini をデプロイします。これは執筆時点で最も安価なGPT-4クラスのモデルであり、AI-102ラボの推奨デフォルトです。デプロイとは、特定のモデルバージョンをクォータ割り当てに名前付きでバインドするものであり、アプリケーションコードからその名前で呼び出します。
model.version = "2024-07-18" はgpt-4o-miniのリリース日です — AI-102では、モデルバージョンの安定性(特定のバージョンへのロックと自動アップグレードの比較)が繰り返し懸念される点としてテストされます。試験では、本番環境の信頼性のために明示的なピン留めが推奨されます。
resource "azurerm_cognitive_account" "openai" {
name = "openai-ai102-${random_id.suffix.hex}"
resource_group_name = azurerm_resource_group.main.name
location = azurerm_resource_group.main.location
kind = "OpenAI"
sku_name = "S0"
custom_subdomain_name = "openai-ai102-${random_id.suffix.hex}"
identity {
type = "SystemAssigned"
}
tags = local.tags
}
resource "azurerm_cognitive_deployment" "chat" {
name = "gpt-4o-mini"
cognitive_account_id = azurerm_cognitive_account.openai.id
model {
format = "OpenAI"
name = "gpt-4o-mini"
version = "2024-07-18"
}
sku {
name = "Standard"
capacity = 10 # TPM in thousands; 10 = 10K tokens-per-minute quota
}
}Azure AI Search(ブランド変更されたCognitive Search)は、RAGパターンのAI-102検索エンジンです。Basicティアのサービスをプロビジョニングします — これはシステム割り当てマネージドIDをサポートしており、AI Searchが統合されたベクトル化機能(インデックス作成中にAI Searchがユーザーの代わりに埋め込みモデルを呼び出す機能)のためにAzure OpenAIを安全に呼び出すために必要です。
local_authentication_enabled = false の設定は、AI-102の本番環境におけるベストプラクティスです — Entra ID認証を強制し、管理キーが飛び交うのを防ぎます。システム割り当てマネージドIDは、次のステップでAzure OpenAIへのアクセス権を付与されます。
resource "azurerm_search_service" "main" {
name = "search-ai102-${random_id.suffix.hex}"
resource_group_name = azurerm_resource_group.main.name
location = azurerm_resource_group.main.location
sku = "basic"
replica_count = 1
partition_count = 1
local_authentication_enabled = false # Entra auth only
public_network_access_enabled = true
identity {
type = "SystemAssigned"
}
tags = local.tags
}
# Grant AI Search's managed identity Cognitive Services OpenAI User on the
// account — required for integrated vectorization (AI Search → OpenAI embeddings).
resource "azurerm_role_assignment" "search_to_openai" {
scope = azurerm_cognitive_account.openai.id
role_definition_name = "Cognitive Services OpenAI User"
principal_id = azurerm_search_service.main.identity[0].principal_id
}RAG用のソースドキュメントはAzure Storageに保存されます。AI SearchインデクサーはBlobコンテナーからデータを取得し、OpenAI埋め込みモデルでベクトル化処理を行い、検索インデックスを構築します。ストレージアカウントに対してAI SearchのマネージドIDに Storage Blob Data Reader ロールを付与することは、AI-102のパスワードレス検索パターンです。
Storage + AI Search + OpenAIがすべてマネージドID経由で接続されることで、RAG基盤が整います。アプリケーション層(ユーザーのクエリを受け取り、AI Searchを呼び出し、取得したコンテキストでOpenAIを呼び出すチャットオーケストレーター)は、ユーザーが記述するコードです — Terraformはそこをサポートするものではなく、インフラストラクチャを正しく構築するものです。
resource "azurerm_storage_account" "docs" {
name = "ai102docs${random_id.suffix.hex}"
resource_group_name = azurerm_resource_group.main.name
location = azurerm_resource_group.main.location
account_tier = "Standard"
account_replication_type = "LRS"
account_kind = "StorageV2"
https_traffic_only_enabled = true
min_tls_version = "TLS1_2"
allow_nested_items_to_be_public = false
tags = local.tags
}
resource "azurerm_storage_container" "source" {
name = "source"
storage_account_id = azurerm_storage_account.docs.id
container_access_type = "private"
}
resource "azurerm_role_assignment" "search_to_storage" {
scope = azurerm_storage_account.docs.id
role_definition_name = "Storage Blob Data Reader"
principal_id = azurerm_search_service.main.identity[0].principal_id
}AI-102では、本番アプリケーションはエンドポイントとキーを環境変数や設定ファイルからではなく、Key Vaultから読み取ることを想定しています。Key Vaultをプロビジョニングし、OpenAIエンドポイント、デプロイ名、およびAI Searchエンドポイントをシークレットとして保存します。本番環境では、アプリケーションのマネージドIDがこのKey Vaultに対する「Key Vault Secrets User」ロールを持ち、起動時にそれらを読み取ることになります。
これにより、AI-102の実装と統合のループが完結します。すべてのエンドポイント、すべてのキー、すべてのサービスURLがKey Vaultを介することで、シークレットローテーションの一元化、監査の一元化が実現されます。追加のAI-102パターン(Document Intelligence、Translator、Custom Vision、Speech)もすべて同じ方法で接続されます。
resource "azurerm_key_vault" "main" {
name = "kv-ai102-${random_id.suffix.hex}"
resource_group_name = azurerm_resource_group.main.name
location = azurerm_resource_group.main.location
tenant_id = data.azurerm_client_config.current.tenant_id
sku_name = "standard"
enable_rbac_authorization = true
soft_delete_retention_days = 7
tags = local.tags
}
resource "azurerm_role_assignment" "kv_admin_self" {
scope = azurerm_key_vault.main.id
role_definition_name = "Key Vault Administrator"
principal_id = data.azurerm_client_config.current.object_id
}
resource "azurerm_key_vault_secret" "openai_endpoint" {
name = "openai-endpoint"
value = azurerm_cognitive_account.openai.endpoint
key_vault_id = azurerm_key_vault.main.id
depends_on = [azurerm_role_assignment.kv_admin_self]
}
resource "azurerm_key_vault_secret" "openai_deployment" {
name = "openai-deployment"
value = azurerm_cognitive_deployment.chat.name
key_vault_id = azurerm_key_vault.main.id
depends_on = [azurerm_role_assignment.kv_admin_self]
}
resource "azurerm_key_vault_secret" "search_endpoint" {
name = "search-endpoint"
value = "https://${azurerm_search_service.main.name}.search.windows.net"
key_vault_id = azurerm_key_vault.main.id
depends_on = [azurerm_role_assignment.kv_admin_self]
}terraform destroy ですべてが削除されます。注意点:
purge_soft_delete_on_destroy = true を設定すると、destroy 実行時に実際に削除が行われます。AI-102は、このラボではカバーしきれない多くのサービスを対象としています — Azure AI Document Intelligence(フォーム認識、カスタム抽出モデル)、Azure AI Vision(カスタム画像分類+オブジェクト検出)、Azure AI Language(CLU + カスタムQnA)、Azure AI Speech(カスタム音声、ニューラル音声、音声翻訳)、Azure AI Bot Service、Azure AI Content Safety、そしてAzure AI Studioのプロンプトフローデザインサーフェス全体です。
ここでは、最もテストされているAI-102アーキテクチャであり、他のすべてのAI-102パターンがその上に構成されるAzure OpenAI + AI Search + Storage + Key Vault RAG基盤に限定します。Document IntelligenceはRAGにフィードし、Visionは画像からコンテンツを抽出し、それらがRAGに埋め込まれます。Bot Serviceはこのスタックのフロントエンドです。
上記のサービスについては、この認定ページの閲覧およびEditorialセクションを参照してください。