Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Azure Bicep で始める Infrastructure as Code/ace0917
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
TonyTonyKun
August 16, 2021
Technology
610
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Azure Bicep で始める Infrastructure as Code/ace0917
2021年9月17日に開催された Azure Council Experts 定例会のセッション資料です。
TonyTonyKun
August 16, 2021
More Decks by TonyTonyKun
See All by TonyTonyKun
Azure Durable Functions で作った NL2SQL Agent の精度向上に取り組んだ話/aidevday2026
thara0402
0
400
Azure Static Web Apps の自動ビルドがタイムアウトしやすくなった状況に対応した件/global-azure2026
thara0402
0
850
Azure Durable Functions で作った NL2SQL Agent の精度向上に取り組んだ話/jat08
thara0402
0
440
これでバッチリ!Azure マルチテナントアーキテクチャ設計のコツ/jat06
thara0402
0
780
Azure Load Testing を使って Azure Functions Flex Consumption の HTTP Trigger のパフォーマンスとコストを最適化してみよう/global-azure2025
thara0402
0
370
Prompty を使って生成 AI アプリケーション開発のプロンプトを管理する/jat03
thara0402
0
97
Azure OpenAI Service で意図せず PTU モデルをデプロイして高額請求されてしまった件/jat04
thara0402
0
110
「Durable Task Scheduler」をチョイ見せ!/jat05
thara0402
0
76
Azure App Service on Linux の Sidecar に Phi-3 を配置してインテリジェントなアプリケーションを作ってみよう/jazug-anniv14
thara0402
0
1.5k
Other Decks in Technology
See All in Technology
KAEN Company Deck
kaen
PRO
0
290
DGX Sparkを2台使って いろいろ動かす話
sonoda_mj
1
120
プロダクト思考 × 基盤思考を AIで実現する Compound Engineering
tkc66buzz
1
240
Driving AI Adoption Using In-House GPUs to Serve Qwen
po3rin
2
430
APIセキュリティを組織で実現するには~注力する点と設計・実装に入れたい対策~
riiimparm
3
930
データエンジニアの困りごとをDevinと一緒に解消する
10xinc
2
790
20260906 「AWS運用入門」著者が教える、運用業務への生成AI活用入門
masaruogura
0
220
When Does a Local Qwen Start to Break
morshoto
0
160
Nav2、Nav3 ... はたまた自作?〜 作って理解する Nav3 の設計意図 〜 / Nav2, Nav3 ... or Build Your Own? — Understanding Nav3's design intent by building it from scratch
yanzm
0
200
When Token Pruning is Worse than Random: Understanding Visual Token Information in VLLMs
sansantech
PRO
0
250
[RSJ26] Building a VLA Model Based on Self-Distilled Classification
keio_smilab
PRO
0
190
Bet AI Day 2026丨バクラク Autopilot、業務システムの再設計
layerx
PRO
2
1.1k
Featured
See All Featured
Unsuck your backbone
ammeep
672
58k
[SF Ruby Conf 2025] Rails X
palkan
2
1.3k
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
GitHub's CSS Performance
jonrohan
1033
470k
YesSQL, Process and Tooling at Scale
rocio
174
15k
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
6.1k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
The Mindset for Success: Future Career Progression
greggifford
PRO
0
490
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
680
Exploring anti-patterns in Rails
aemeredith
3
490
What's in a price? How to price your products and services
michaelherold
247
13k
Transcript
Azure Bicep で始める Infrastructure as Code 2021.9.17 Azure Council Experts
定例会
自己紹介 原 敏之(Toshiyuki Hara) 株式会社ネクストスケープ Microsoft Azure の導入支援やクラウドネイティブなアプリケー ション開発をしています。 https://www.nextscape.net/
Microsoft MVP for Microsoft Azure 2017 〜 ROMANCE DAWN for the new world https://gooner.hateblo.jp/ Japan Azure User Group(JAZUG) Microsoft Azure のゆるふわなコミュニティ https://jazug.connpass.com/ 2 Copyright© 2021, JAZUG All Rights Reserved.
Goal 従来の ARM テンプレートが抱える課題を解決できる Bicep の 良さを知ることで、使ってみようと感じてもらえること Bicep を使って Infrastructure
as Code をどのように実現するの かのイメージを掴んでもらうこと 3 Copyright© 2021, JAZUG All Rights Reserved.
Infrastructure as Code Microsoft Azure における Infrastructure as Code 4
Copyright© 2021, JAZUG All Rights Reserved.
Infrastructure as Code のおさらい Infrastructure as Code (IaC) は、インフラの構築作業をコード で実施する考え方のこと
5 Copyright© 2021, JAZUG All Rights Reserved. • 構築コストの増大 • 人為的なミスの発生 • 暗黙的なノウハウの発生 手順書や人手による構築 で発生する課題 • 素早く、確実に環境を再現できる • コードの再利用により、横展開が容易 • 部品化による再利用もできる • インフラ構成を標準化でき、統制が取りやすい • 都度レビューするよりも確実に統制できる • セキュリティポリシーの適用もできる インフラをコードで管理 することによるメリット Infrastructure as Code
ARM テンプレートのおさらい Azure Resource Manger (ARM) テンプレートは、Azure ポータル 上から手作業で実施しているリソース構築を自動化する仕組み Azure
のリソースを JSON で定義する テンプレートとパラメータの JSON ファイルから構成される Azure CLI / PowerShell / Azure ポータルを使ってテンプレートを実行 6 Copyright© 2021, JAZUG All Rights Reserved.
ARM テンプレートが抱える課題 ARM テンプレートの課題は、3つに分類できる 1. Azure リソースを JSON で表現するため冗長で煩雑になりやすい 2.
テンプレートファイルの部品化による再利用が難しい 3. Azure Resource Manger API の仕様が分かりにくい 7 Copyright© 2021, JAZUG All Rights Reserved. Bicep は、この2つの課題解決に取り組むプロジェクトです。
What is a Bicep Project? Bicep とは? 8 Copyright© 2021,
JAZUG All Rights Reserved.
Bicep とは Bicep は、ARM テンプレートの DSL (Domain Specific Language) 9
Copyright© 2021, JAZUG All Rights Reserved. JSON よりもシンプルな構文で書ける モジュール化とコード再利用性のサ ポートが向上 すべての Azure リソースと API バー ジョンを Day 0 サポート 現在のバージョンは v0.4 だが、 Microsoft 公式サポートの対象 Azure Resource Manager Bicep Language Compute Storage Network … az deployment create az bicep build az bicep decompile +250 RPs ARM Templates
Bicep を使い始めるには 開発環境 Bicep ファイルを作成するためのエディターが必要。 • Visual Studio Code •
Visual Studio Code 向けの Bicep 拡張機能 デプロイ環境 Bicep ファイルをデプロイするためのコマンドが必要。 • Azure CLI • Ver.2.20.0 以降で、Bicep が Azure CLI 統合されているので追加インストール不要 • PowerShell • Bicep が自動インストールされないので、手動でインストールする 10 Copyright© 2021, JAZUG All Rights Reserved.
Bicep ファイルを作成する 空の main.bicep ファイルを作成し、リソースを定義する 11 Copyright© 2021, JAZUG All
Rights Reserved. resource stg 'Microsoft.Storage/storageAccounts@2019-06-01' = { name: 'uniquestorage001' location: 'japaneast' kind: 'Storage' sku: { name: 'Standard_LRS' } }
Bicep ファイルを作成する パラメータを追加する 12 Copyright© 2021, JAZUG All Rights Reserved.
param location string = 'japaneast’ @minLength(3) @maxLength(24) param storageAccountName string = 'uniquestorage001' resource stg 'Microsoft.Storage/storageAccounts@2019-06-01' = { name: storageAccountName location: location kind: 'Storage' sku: { name: 'Standard_LRS' } }
Bicep ファイルを作成する 変数と出力を追加する 13 Copyright© 2021, JAZUG All Rights Reserved.
param location string = 'japaneast’ @minLength(3) @maxLength(24) param storageAccountName string = 'uniquestorage001' var storageSku = 'Standard_LRS' resource stg 'Microsoft.Storage/storageAccounts@2019-06-01' = { name: storageAccountName location: location kind: 'Storage' sku: { name: storageSku } } output storageId string = stg.id
Bicep ファイルをデプロイする Bicep ファイルをリソースグループにデプロイする リソースグループの以外のデプロイ スコープ サブスクリプション 管理グループ テナント 14
Copyright© 2021, JAZUG All Rights Reserved. $ az group create -n <ResourceGroup Name> -l japaneast $ az deployment group create -f ./main.bicep -g <ResourceGroup Name>
Bicep ファイルをデプロイする パラメータを使用してデプロイする コマンドラインでパラメータを渡す パラメータの JSON ファイルを使用する • ARM テンプレートと同じパラメータ
JSON ファイルを使用できる 15 Copyright© 2021, JAZUG All Rights Reserved. $ az deployment group create -f ./main.bicep -g <ResourceGroup Name> --parameters location= japaneast storageAccountName=uniquelogstorage001 $ az deployment group create -f ./main.bicep -g <ResourceGroup Name> --parameters ./parameters.json
What unique benefits do you get with Bicep? Bicep の良いところ
16 Copyright© 2021, JAZUG All Rights Reserved.
JSON よりもシンプルな構文で書ける パラメータと変数の参照 パラメータの定義 17 Copyright© 2021, JAZUG All Rights
Reserved. "parameters": { "name": { "type": "string", "defaultValue": "myName" } }, param name string = 'myName' "name": "[variables('name')]", "location": "[parameters('location')]", name: name location: location ARM テンプレート Bicep ARM テンプレート Bicep
JSON よりもシンプルな構文で書ける パラメータの修飾 18 Copyright© 2021, JAZUG All Rights Reserved.
"parameters": { "name": { "type": "string", "defaultValue": "myName", "allowed": [ "myName", "myOtherName" ], "minLength": 3, "maxLength": 24 } }, @allowed([ 'myName' 'myOtherName' ]) @minLength(3) @maxLength(24) param name string = 'myName' ARM テンプレート Bicep
JSON よりもシンプルな構文で書ける 変数の定義 アウトプットの定義 19 Copyright© 2021, JAZUG All Rights
Reserved. "variables": { "location": “japaneast" } var location = ‘japaneast' "outputs": { "myOutput": { "type": "string", "value": "my output value" } } output myOutput string = 'my output value' ARM テンプレート Bicep ARM テンプレート Bicep
JSON よりもシンプルな構文で書ける 文字列の連結 リソース ID の取得 論理演算子 20 Copyright© 2021,
JAZUG All Rights Reserved. concat('John', ' ', parameters('lastName')) 'John ${lastName}' resourceId('microsoft.network/virtualNetworks') res.id and(parameter('isMonday'), parameter('isNovember')) isMonday && isNovember ARM テンプレート Bicep ARM テンプレート Bicep ARM テンプレート Bicep
モジュール化とコード再利用性のサポー トが向上 module を使用して、別の .bicep ファイルを参照できる すべての .bicep ファイルをモジュールとして、相対パスで参照できる。 ARM
テンプレートでは、リンクしたい JSON ファイルをインターネット に公開する必要があった。 21 Copyright© 2021, JAZUG All Rights Reserved. module stg './storage.bicep' = { name: 'storageDeploy' params: { storageAccountName: '<YOURUNIQUESTORAGENAME>' } } output storageName array = stg.outputs.containerProps . ├── main.bicep └── storage.bicep .bicep ファイルの配置 main.bicep ファイル
モジュール化とコード再利用性のサポー トが向上 暗黙的なリソースの依存関係 22 Copyright© 2021, JAZUG All Rights Reserved.
resource appServicePlan 'Microsoft.Web/serverfarms@2021-01-15' = { name: appServicePlanName location: location sku: { name: sku } } resource appService 'Microsoft.Web/sites@2021-01-15' = { name: appServicenName location: location properties:{ serverFarmId: appServicePlan.id } } ✓ あるリソース名が別のリソース定義内で参照されると、 暗黙的なリソースの依存関係が作成される。 ✓ ARM テンプレートでは、”dependsOn” で明示的に宣 言する必要があった。
Conclusion まとめ 23 Copyright© 2021, JAZUG All Rights Reserved.
まとめ いま Azure で IaC を実現するなら、推しは Bicep です。 ARM テンプレートの
JSON よりもシンプルな構文で書くことができ、 モジュール化とコードの再利用性のサポートが向上しています。 手順書や人手によるインフラ構築から脱却しましょう。 既に Terraform などのツールを導入しているなら、無理に Bicep を導入 する必要はないと思います。 24 Copyright© 2021, JAZUG All Rights Reserved.
参考資料 Azure Bicep の公式ドキュメント https://docs.microsoft.com/ja-jp/azure/azure-resource-manager/bicep/ Bicep を使用して Azure でリソースをデプロイして管理する https://docs.microsoft.com/ja-jp/learn/paths/bicep-deploy/
Project Bicep - Tutorial https://github.com/Azure/bicep/tree/main/docs/tutorial Project Bicep - Spec https://github.com/Azure/bicep/tree/main/docs/spec 25 Copyright© 2021, JAZUG All Rights Reserved.