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
TonyTonyKun
August 16, 2021
Technology
0
380
Azure Bicep で始める Infrastructure as Code/ace0917
2021年9月17日に開催された Azure Council Experts 定例会のセッション資料です。
TonyTonyKun
August 16, 2021
Tweet
Share
More Decks by TonyTonyKun
See All by TonyTonyKun
サイクルガードサービス AlterLock の問い合わせ対応業務に Azure OpenAI Service を活用した話/jazug46
thara0402
0
560
Microsoft Ignite 2023 現地参加レポート/ignite2023
thara0402
0
89
Azure Container Apps で .NET 7 アプリを Blue-Green デプロイしてみよう!/jazug12
thara0402
0
1.4k
Azure Synapse Analytics 入門/jazug11
thara0402
0
600
Introduction to Azure Synapse Analytics/ace0416
thara0402
0
400
Azure Kubernetes Service を活用したマイクロサービス開発/clouddev
thara0402
0
370
Azure Kubernetes Service を活用したマイクロサービス開発/Ignite-osaka
thara0402
0
400
Azure Kubernetes Service を活用したマイクロサービス開発/Ignite-tokyo
thara0402
0
140
Azure アーキテクチャ センターを読んで LINE BOT を作ってみた話/kitaazu23
thara0402
0
1.3k
Other Decks in Technology
See All in Technology
The CloudCompare project by Dr. Daniel Girardeau-Montaut
kentaitakura
0
510
Cloud Native Java with Spring Boot (CNCF Aarhus, April 2024)
thomasvitale
1
120
DevOpsDays History and my DevOps story
kawaguti
PRO
8
1.6k
現代CSSフレームワークの内部実装とその仕組み
poteboy
2
760
NgRx Signal Store
rainerhahnekamp
0
120
Autonomous Database Cloud 技術詳細 / adb-s_technical_detail_jp
oracle4engineer
PRO
14
35k
開発生産性向上サービスを作るFindyが自分たちで開発生産性を爆上げした組織づくりの歩み / Findy's path to boosting its own development productivity 2024-04-17
ma3tk
3
340
最近たまに見かけるTiDBってなんだ? - Findy
pingcap0315
2
600
複雑な構成要素を持つUIとの向き合い方 〜新・支出グラフでの実例〜 / B43 TECH TALK
nakamuuu
0
100
「手動オペレーションに定評がある」と言われた私が心がけていること / phpcon_odawara2024
blue_goheimochi
2
320
「共通基盤」を超えよ! 今、Platform Engineeringに取り組むべき理由
jacopen
25
5.9k
Terraformあれやこれ/terraform-this-and-that
emiki
5
470
Featured
See All Featured
Code Reviewing Like a Champion
maltzj
513
39k
Designing for humans not robots
tammielis
247
25k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
24
2.3k
Put a Button on it: Removing Barriers to Going Fast.
kastner
58
3k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
20
1.6k
Typedesign – Prime Four
hannesfritz
36
2.1k
The Brand Is Dead. Long Live the Brand.
mthomps
48
28k
Building Better People: How to give real-time feedback that sticks.
wjessup
354
18k
Embracing the Ebb and Flow
colly
79
4.1k
RailsConf 2023
tenderlove
2
530
Raft: Consensus for Rubyists
vanstee
132
6.2k
The MySQL Ecosystem @ GitHub 2015
samlambert
242
12k
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.