SlideShare a Scribd company logo
AzureにおけるCI/CDについて
terraformを交えて話します
第32回 Tokyo Jazug Night (Online)
株式会社 bitFlyer
SRE部 遠地 等一
自己紹介 : 遠地 等一(とおち ともかず)
- 2021年4月bitFlyerにジョイン
- SREやってます
- 職歴 :
ゲーム業界でサーバ/フロント
不動産業界でSRE
金融業界でSRE(←今ココ)
- ※ Azure初心者
目次
bitFlyerのサービス・技術スタック
bitFlyerにおけるCI/CDの変遷
Azure DevOpsにおけるterraform
のCI/CD導入事例
気になる数値グラフ
https://covid19.mhlw.go.jp/en/
気になる数値グラフ
https://bitflyer.com/en-jp/bitcoin-chart
1. bitFlyerのサービスと技術スタック
販売所・取引所
暗号資産を売り買い・トレードできます
画像はHPより抜粋
miyabi
プライベートブロックチェーン
bitFlyer Blockchainが企画・開発・運用
主な技術スタック
Blockchain
Webサーバー バックエンド 永続化レイヤー
コード VCS/CI/CD
金融業界の特性
🏦高い信頼性とセキュリティを求められる
🏦開発・運用において変更の管理を求められる
意思決定
変更管理
監査
暗号資産界隈の事業背景
急激な市場変化
価格、ユーザ数、取引高、競合他社
事業の成長
エンジニア数
迅速な規制要件への対応
→アーキテクチャ整理よりも、機能追加を優先した
モノリシック構成
一つのリポジトリにいくつものプロダクトのプロジェ
クトを抱える、モノリシックな構成に
🤔一つのリポジトリにいくつものプロダクト
🤔DBも巨大に
🤔Pipelineもひとつのリポジトリに多数
2. bitFlyerにおけるCI/CDの変遷
最初期
🤔IDE(Visual Studio)から直デプロイ
CI/CDの導入
2019年
CI/CD環境としてTeamCity(オンプレ)を導入
検証環境のみデプロイで使えるように
CI/CDの導入
2019年
IDEからの直デプロイと併用していたが、
Cloud Serviceのデプロイで2回連続や2窓同時で、
Visual Studioがout of memoryで落ちる
→あまりに非効率的なので、本番デプロイできるよう
に
ソースコードもオンプレでした
ソースコードはオンプレのGitlabにあった
CI/CDのメリットとして高速にビルドできた
NuGetのキャッシュ(モノリポなので重要)
gitも差分取得(モノリポなので重要)
DevOpsへの移行
2020年
コロナ禍で在宅勤務
オンプレの面倒を見づらくなった
→ビルドのPipelineは使ってよいことになった
DevOpsへの移行
2020年
TeamCityのVMが突然死し、復旧もできなくなった
→デプロイに多少時間がかかってもいいという判断で
DevOpsに移行
ChatOps
一部のCI/CDをトリガなどをChatOpsで行っている
botの実体はFunction
3. Azure DevOpsにおける
terraformのCI/CD導入
要件 [Must]
環境の分離
検証・本番を分ける
アクセスの分離
検証・本番のアクセス権限を分ける
職務・職責の分離
開発担当とデプロイ担当を分ける
要件 [Must]
環境の分離
→ Azureのsubscriptionを分けることで対応
アクセスの分離
→ ActiveDirectoryで対応
職務・職責の分離
→ DevOpsのProjectを分けることで対応
要件 [Want]
検証・本番でインフラ環境をなるべく一致させたい
QAコストの削減
terraformをローカルで実行したい
開発の効率化
terraform plan結果をPRのコメント投稿したい
コードレビューの効率化
要件 [Want]
検証・本番でインフラ環境をなるべく一致させたい
→ terraform workspaceでDRYにしてみた
terraformをローカルで実行したい
→ 技術スタックをそろえた
terraform plan結果をPRのコメント投稿したい
→ 大変でした(後述)
検証・本番環境をなるべく一致させたい
workspace (CLI) を使うことでDRYにしてみた
terraform planをローカルで実行したい
目的
開発の効率化
terraform state職人
terraform planをローカルで実行したい
DevOps側に特有であるvariable groupsが増えるほど
ローカル実行の敷居が上がるため、使わないようにし
た
terraform planをローカルで実行したい
(逆に言えば、もしローカルでvariable groupの機能
を使えたらラクだった)
terraform planをローカルで実行したい
DevOpsのvariable groupからterraformのlocal valuesへ、
設定をオフロードした。機密情報はKey vaultから参照
terraform planをローカルで実行したい
Pipeline YAMLにおいて
TerraformInstaller@0
のタスクを使って特定のバージョンのterraformをイン
ストールできるが、
ローカルでは利用できない
terraform planをローカルで実行したい
tfenvで特定のterraformバージョンを利用するように
した。Pipelineとローカルとで同じ技術スタックを使
用するようにして再現性を担保
terraform planをローカルで実行したい
Pipeline YAMLあるある
terraformのbackend設定を書きがち
terraform planをローカルで実行したい
標準的なbackend設定方法を規定するため、
terragruntを導入。Pipelineとローカルとで同じ技術ス
タックを使用するようにして再現性を確保
terraform plan結果をPRのコメント投稿したい
PRの作成をトリガに、terraform planを実行して、結
果をコメント投稿したい
terraform plan結果をPRのコメント投稿したい
調査・実装に工数がかかりました
terraformを動かすためのService Principal認証
PRコメント投稿のためのDevOps APIコール認証
(tfnotifyがDevOps非対応)
Pull requestに含まれる変更ファイルリストの取得
terraform plan結果をPRのコメント投稿したい
TerraformTaskV1@0 そのままでは使えなかった
terraform planなどの標準出力を受け取れない
terraformでexternal data sourceを使った場合に認証
が通らない
terraform plan結果をPRのコメント投稿したい
まずterraform自体を動かすために
Service Principalの認証を通したい
terraformの要求するService Principalの認証情報
export ARM_CLIENT_ID="00000000-0000-0000-0000-000000000000"
export ARM_CLIENT_SECRET="00000000-0000-0000-0000-000000000000"
export ARM_SUBSCRIPTION_ID="00000000-0000-0000-0000-000000000000"
export ARM_TENANT_ID="00000000-0000-0000-0000-000000000000”
terraform plan結果をPRのコメント投稿したい
AzureCLI@2
タスクパラメータ
addSpnToEnvironment: true
環境変数経由で
servicePrincipalId, servicePrincipalKey, tenantId
を参照できるようになる
terraform plan結果をPRのコメント投稿したい
- task: AzureCLI@2
displayName: terraform plan
inputs:
addSpnToEnvironment: true
azureSubscription: ${{ parameters.serviceConnection }}
scriptLocation: inlineScript
scriptType: bash
inlineScript: |
export ARM_SUBSCRIPTION_ID=$(az account show --query id --out tsv)
export ARM_TENANT_ID=${tenantId}
export ARM_CLIENT_ID=${servicePrincipalId}
export ARM_CLIENT_SECRET=${servicePrincipalKey}
terragrunt init
terraform plan結果をPRのコメント投稿したい
コメント投稿にDevOps APIを使いたい
terraform plan結果をPRのコメント投稿したい
APIコール時の認証に使うHTTPヘッダは、
ローカルとPipelineとで使い分ける必要がある
ローカル
Authorization: Basic BASE64(Personal Access Token)
Pipeline
Authorization: Bearer $(System.AccessToken)
terraform plan結果をPRのコメント投稿したい
System.AccessTokenに必要な許可設定
Settings»Repos»Repositories»Security
Build ServiceにContribute to pull requestsを許
可
PATに必要な許可設定
Code (Read, write, & manage)
要件 [Want]
Pull requestに含まれるファイルのみterraform applyし
たい
CI/CD時短
ProjectをまたいでPipelineをトリガしたい
自動でproduction環境でterraform plan
Pull Requestに含まれるファイルのみterraform applyしたい
PullRequestIdからファイルリストを取得可能
🤔PR作成・更新時はPullRequestIdをとれるが、
PRがCompleteされたときにとれない
$(System.PullRequest.PullRequestId)
サポートに聞いたら仕様とのこと
ProjectをまたいでPipelineをトリガしたい
🤔異なるProjectのPipelineを、Branch policyでトリガ
できない(PRをトリガにできない=PullRequestIdを
とれない)
ProjectをまたいでPipelineをトリガしたい
repositories resourceでは実現できなかった
サポートに聞いたらDevOpsのリポジトリをトリガに
する使い方は想定されていなかったとのこと
resources:
repositories:
- repository: string # identifier (A-Z, a-z, 0-9, and underscore)
type: enum # see the following "Type" topic
name: string # repository name (format depends on `type`)
ツール群を作成
要件を実現するためのツール群を作成:
ツール名 説明
merged-pr-id PR IDをcommit hashから取得
pr-files PRに含まれるファイルリストを取得
pr-comment PRにコメント投稿
tf-dirs terraform対象ディレクトリを列挙
tf-workspaces terraform対象workspaceを列挙
UNIX哲学
UNIX哲学
一つのことを行い、またそれをうまくやるプログラム
を書け。
協調して動くプログラムを書け。
標準入出力(テキスト・ストリーム)を扱うプログラ
ムを書け。
toolchainの動き
完成
Pull requestコメントにterraform plan結果を投稿
GitHub (Actions)との比較
DevOps GitHub (Actions)
API認証(CI/CD) $(System.AccessToken)
ローカルとPipelineとでHTTPヘッダ
指定方法が異なる
secrets.GITHUB_TOKEN
Pull Requestイベント Branch policies»Build Validation追加 on: pull_request
Pull Request Idの取得 $(System.PullRequest.PullRequestId)
取れない時はDevOps APIでcommit
hashを含むPRを走査
github.event.pull_request.number
Pull Requestに含まれる
ファイルリストの取得
PRに含まれるすべてのコミットにつ
いて変更ファイルを取得
GET
/repos/{owner}/{repo}/pulls/{pull_n
umber}/files
コメント投稿 POST
/_apis/git/repositories/{repo}/pullRequ
ests/{pull_number}/threads
tfnotify使う
Thank you very much!
ご質問?
We’re hiring!
Azure DevOps CI/CD with terraform

More Related Content

PDF
RDBMS with Node.js
PDF
Docker Use Cases on Raspberry Pi
PDF
【Unite Tokyo 2019】Unity映像制作パイプライン完全マスター
PDF
Cocos最新情報(2015/4/27)
PDF
CodeStarではじめるRailsアプリのCodeDeploy化
PDF
Docker For Dummies
PDF
World Wide Web with Virtual Reality #sa_study
PDF
Continuous Delivery - FIT VUT
RDBMS with Node.js
Docker Use Cases on Raspberry Pi
【Unite Tokyo 2019】Unity映像制作パイプライン完全マスター
Cocos最新情報(2015/4/27)
CodeStarではじめるRailsアプリのCodeDeploy化
Docker For Dummies
World Wide Web with Virtual Reality #sa_study
Continuous Delivery - FIT VUT

Similar to Azure DevOps CI/CD with terraform (18)

PDF
Zebra 2.0 in Hybrid Cloud Era
PDF
Hacking for Salone: Drone Races - Di Saverio; Lippolis - Codemotion Milan 2016
PDF
NoSQL/SQLデュアルインターフェースを備えた IoT向けデータベースGridDB ~ GridDB CE 4.6のテーブルパーティショニングを 使っ...
PDF
容器化後,持續交付不可缺的敲門磚 - Helm
PPTX
Hacking for salone: drone races
PPTX
Understanding blockchain
PDF
Traefik on google kubernetes engine
PDF
20210809 story book_driven_new_system_development_nuxtjs
PDF
Droids, java script and web connected hardware
PDF
Cloud Computing Is Not Cotton Candy ... Or Is It?
PDF
39346062 cloud-computing-is-not-cotton-candy-or-is-it
PDF
ISC HPCW talks
PDF
Remote monitoring widget setup and customization
PDF
Fargateを使いこなす!creatiaのインフラを支える技術について
PPTX
Virtual Reality & Sim Racing in Assetto Corsa - Romagnoli
PDF
Flutter Vikings 2022 - Full Stack Dart
PDF
PEW PEW PEW: Designing Secure Boot Securely
PDF
PEW PEW PEW: Designing Secure Boot Securely
Zebra 2.0 in Hybrid Cloud Era
Hacking for Salone: Drone Races - Di Saverio; Lippolis - Codemotion Milan 2016
NoSQL/SQLデュアルインターフェースを備えた IoT向けデータベースGridDB ~ GridDB CE 4.6のテーブルパーティショニングを 使っ...
容器化後,持續交付不可缺的敲門磚 - Helm
Hacking for salone: drone races
Understanding blockchain
Traefik on google kubernetes engine
20210809 story book_driven_new_system_development_nuxtjs
Droids, java script and web connected hardware
Cloud Computing Is Not Cotton Candy ... Or Is It?
39346062 cloud-computing-is-not-cotton-candy-or-is-it
ISC HPCW talks
Remote monitoring widget setup and customization
Fargateを使いこなす!creatiaのインフラを支える技術について
Virtual Reality & Sim Racing in Assetto Corsa - Romagnoli
Flutter Vikings 2022 - Full Stack Dart
PEW PEW PEW: Designing Secure Boot Securely
PEW PEW PEW: Designing Secure Boot Securely
Ad

Recently uploaded (20)

PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPTX
Artificial Intelligence
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
DOCX
573137875-Attendance-Management-System-original
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PPT
Mechanical Engineering MATERIALS Selection
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPTX
additive manufacturing of ss316l using mig welding
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPT
Project quality management in manufacturing
PPTX
CH1 Production IntroductoryConcepts.pptx
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
Embodied AI: Ushering in the Next Era of Intelligent Systems
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
R24 SURVEYING LAB MANUAL for civil enggi
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Artificial Intelligence
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
573137875-Attendance-Management-System-original
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
Mechanical Engineering MATERIALS Selection
bas. eng. economics group 4 presentation 1.pptx
additive manufacturing of ss316l using mig welding
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
Project quality management in manufacturing
CH1 Production IntroductoryConcepts.pptx
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
Ad

Azure DevOps CI/CD with terraform