最終確認: 2026年5月
AZ-204 試験の対象となる AWS サービスを、プレーンな Terraform を使用して構築します。1 ブロックずつ、それぞれ試験ドメインに関連付けられています。同じコードが OpenTofu でも動作します。
このラボの終了時には、プレーンなTerraformを使用して、正規のAzure PaaSウェブアプリをプロビジョニングできます。これには、マネージドID付きのApp Serviceプラン + Linuxウェブアプリ、状態管理用のCosmos DBアカウント、テレメトリ用のApplication Insightsワークスペース、およびアプリがBLOB/ファイル作業に使用できるストレージアカウントが含まれます。5つのブロックで構成され、AZ-204の参照アーキテクチャです。
これらのスニペットを単一の main.tf に配置し、terraform init を実行してから、terraform apply をステップバイステップで実行してください。
>= 1.5 または OpenTofu >= 1.6。az login)。az webapp deploy)。このラボではインフラストラクチャシェルをプロビジョニングします — コードのデプロイはAZ-204の Implement DevOps ドメインであり、Terraformの範囲外です。スタック全体がB1プランでアイドル状態の場合、約13ドル/月かかります。無料テストのためにF1に切り替えるか(ステップ3でマネージドIDを削除)、またはすぐに破棄してください。
標準的なAzureの開始方法。App Serviceのウェブアプリ名はグローバルに一意である必要があります(<name>.azurewebsites.net としてDNS公開されます) — random_id は競合を回避します。
terraform {
required_version = ">= 1.5"
required_providers {
azurerm = { source = "hashicorp/azurerm", version = "~> 4.0" }
random = { source = "hashicorp/random", version = "~> 3.6" }
}
}
provider "azurerm" {
features {}
}
resource "random_id" "suffix" {
byte_length = 3
}
locals {
tags = {
Project = "certlabpro-az-204"
ManagedBy = "terraform"
}
}
resource "azurerm_resource_group" "main" {
name = "certlabpro-az-204-rg"
location = "eastus"
tags = local.tags
}AZ-204では、質問に single-digit-millisecond at scale (大規模な一桁ミリ秒)、globally distributed (グローバル分散)、または NoSQL with SQL-like querying (SQLのようなクエリを持つNoSQL) とある場合、Cosmos DBを使用することが期待されます。サーバーレス容量モードはコスト最適化のデフォルトであり、RUごとの支払い、アイドル時は0ドル、低ボリューム/開発環境に最適な選択肢として試験で問われます。
ここでは、アカウント、その下に1つのデータベース、そしてパーティションキーを持つ1つのコンテナーを作成します。パーティションキーの選択(ここでは /userId)は、AZ-204のCosmosに関する最も頻繁に問われる質問です — 不適切なパーティションキーはホットパーティションを引き起こし、適切なパーティションキーは負荷を均等に分散します。試験では、カーディナリティのシナリオでこのパターンが問われます。
resource "azurerm_cosmosdb_account" "main" {
name = "certlabpro-az-204-${random_id.suffix.hex}"
resource_group_name = azurerm_resource_group.main.name
location = azurerm_resource_group.main.location
offer_type = "Standard"
kind = "GlobalDocumentDB"
capabilities {
name = "EnableServerless"
}
consistency_policy {
consistency_level = "Session"
}
geo_location {
location = azurerm_resource_group.main.location
failover_priority = 0
}
tags = local.tags
}
resource "azurerm_cosmosdb_sql_database" "app" {
name = "appdb"
resource_group_name = azurerm_resource_group.main.name
account_name = azurerm_cosmosdb_account.main.name
}
resource "azurerm_cosmosdb_sql_container" "users" {
name = "users"
resource_group_name = azurerm_resource_group.main.name
account_name = azurerm_cosmosdb_account.main.name
database_name = azurerm_cosmosdb_sql_database.app.name
partition_key_paths = ["/userId"]
}AZ-204の Implement Azure Security と Monitor, Troubleshoot, and Optimize ドメインはどちらもApplication Insightsに依存しています — これは分散トレース、依存関係追跡、例外捕捉、ライブメトリクスを実現するAPMサービスです。最新のApplication Insightsインスタンスは、データバックエンドとしてLog Analyticsワークスペースを必要とします(ワークスペースベース モード; クラシックモードは非推奨です)。
ここでは両方を作成し、計測キーと接続文字列がApplication Insightsの属性として出力されます — ステップ4でアプリ設定を介してApp Serviceに接続されます。
resource "azurerm_log_analytics_workspace" "main" {
name = "certlabpro-az-204-logs"
resource_group_name = azurerm_resource_group.main.name
location = azurerm_resource_group.main.location
sku = "PerGB2018"
retention_in_days = 30
tags = local.tags
}
resource "azurerm_application_insights" "main" {
name = "certlabpro-az-204-appi"
resource_group_name = azurerm_resource_group.main.name
location = azurerm_resource_group.main.location
workspace_id = azurerm_log_analytics_workspace.main.id
application_type = "web"
tags = local.tags
}App ServiceはAZ-204で選択されるPaaSウェブホストです。App Serviceプランはコンピューティングコンテナであり(抽象化されたEC2 と考えてください)、その中のウェブアプリはプランのコンピューティングを共有します。ここではLinux B1プランと、Node.js 20ランタイムを使用する単一のウェブアプリを使用します — スタックに合わせて python、dotnet、java、または php に切り替えてください。
システム割り当てマネージドID は、アプリが他のAzureサービス(Key Vault、Storage、Cosmos DB)にアクセスするためのAZ-204のパスワード不要な資格情報の回答です。これらのリソースにRBACロールが付与されると、App ServiceはEntra発行のトークンでそれらを呼び出します — アプリ設定に接続文字列は必要ありません。
app_settings ブロックは環境変数を注入します:App Insightsの接続文字列、Cosmosエンドポイント、およびフラグです。ウェブアプリは空のシェルとして開始されます — コードは別途デプロイされます。このラボはインフラストラクチャを正しく構築することに焦点を当てています。
resource "azurerm_service_plan" "main" {
name = "certlabpro-az-204-plan"
resource_group_name = azurerm_resource_group.main.name
location = azurerm_resource_group.main.location
os_type = "Linux"
sku_name = "B1"
tags = local.tags
}
resource "azurerm_linux_web_app" "main" {
name = "certlabpro-az-204-${random_id.suffix.hex}"
resource_group_name = azurerm_resource_group.main.name
location = azurerm_service_plan.main.location
service_plan_id = azurerm_service_plan.main.id
https_only = true
site_config {
always_on = true
application_stack {
node_version = "20-lts"
}
}
identity {
type = "SystemAssigned"
}
app_settings = {
APPLICATIONINSIGHTS_CONNECTION_STRING = azurerm_application_insights.main.connection_string
COSMOS_ENDPOINT = azurerm_cosmosdb_account.main.endpoint
WEBSITES_ENABLE_APP_SERVICE_STORAGE = "false"
}
tags = local.tags
}
# Grant the web app's managed identity Cosmos DB data-plane access
# (Cosmos DB Built-in Data Contributor — the AZ-204 password-less pattern).
resource "azurerm_cosmosdb_sql_role_assignment" "webapp" {
resource_group_name = azurerm_resource_group.main.name
account_name = azurerm_cosmosdb_account.main.name
role_definition_id = "${azurerm_cosmosdb_account.main.id}/sqlRoleDefinitions/00000000-0000-0000-0000-000000000002"
principal_id = azurerm_linux_web_app.main.identity[0].principal_id
scope = azurerm_cosmosdb_account.main.id
}すべてのAzure PaaSウェブアプリは最終的にBLOB/ファイルストレージを必要とします — アップロードされたファイル、ユーザーのアバター、生成されたPDF、処理された画像などです。ここでは、標準のセキュアなデフォルト設定でアカウントをプロビジョニングし、アプリのマネージドIDに Storage Blob Data Contributor ロールを付与することで、アプリが接続文字列なしでBLOBの読み書きをできるようにします。
これにより、AZ-204の Develop Azure Compute Solutions のループが閉じられます:アプリ + 状態(Cosmos)+ テレメトリ(App Insights)+ BLOBストレージが、シークレットではなくマネージドIDを介してすべて連携されます。追加のAZ-204パターン(Service Busキュー、Event Gridトピック、Key Vaultシークレット、Logic App統合)もすべて同じ方法でアタッチされます — マネージドIDに適切なスコープで適切なロールを付与します。
resource "azurerm_storage_account" "app_blobs" {
name = "az204app${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_role_assignment" "webapp_blobs" {
scope = azurerm_storage_account.app_blobs.id
role_definition_name = "Storage Blob Data Contributor"
principal_id = azurerm_linux_web_app.main.identity[0].principal_id
}terraform destroy はすべてを破棄します。App Service Plan B1 は24時間365日課金される項目です(約13ドル/月)。ウェブアプリが削除されても、スケールインを誤るとプランはリソースグループに残りますが — terraform destroy は両方を削除します。Cosmos DBサーバーレスとApplication Insightsは、破棄後すぐに課金が停止します。
AZ-204では、このラボではカバーしきれないさらに多くの開発者サービスを扱います — Azure Functions (イベント駆動型サーバーレス)、Container Apps、AKS、Service Bus、Event Grid、Event Hubs、Logic Apps、Durable Functions、API Management、Front Door、CDN、Notification Hubs、SignalR、およびシークレットストレージ用のAzure Key Vault(マネージドID後の一般的なAZ-204のフォローアップ)などです。
試験で最も頻繁にテストされるPaaSウェブアプリの形であるため、App Service + Cosmos + App Insights + Storage のベースラインに限定します — そして他のすべてのAZ-204パターン(Functions、Service Bus、Key Vault)は、マネージドID + RBACを介してこのベースにアタッチされます。
上記のサービスについては、この認定ページにある 閲覧、プレイブック、および Editorial のセクションを参照してください。