$30 off During Our Annual Pro Sale. View Details »

msgraph: Terraform Provider for Microsoft Graph

msgraph: Terraform Provider for Microsoft Graph

YAEGASHI Takeshi

July 03, 2020
Tweet

More Decks by YAEGASHI Takeshi

Other Decks in Technology

Transcript

  1. msgraph: Terraform Provider for Microsoft Graph
    八重樫 剛史 Takeshi Yaegashi
    BANDAI NAMCO Studios Inc.

    View Slide

  2. 自己紹介
    八重樫 剛史 Takeshi Yaegashi
    株式会社バンダイナムコスタジオ BANDAI NAMCO Studios Inc. 所属
    Linux・Unix・OSS が好きなエンジニア 最近は Go 言語が好き
    組み込みシステム開発、ゲームサーバ開発、 CI/CD インフラ開発、
    開発環境のクラウドシフトなどの業務に従事
    活動場所
    ホームページ・ブログ https://l0w.dev
    GitHub https://github.com/yaegashi
    GitLab https://gitlab.com/yaegashi
    Twitter https://twitter.com/hogegashi

    View Slide

  3. msgraph: Introduction

    View Slide

  4. msgraph の紹介
    Terraform provider for Microsoft Graph とは?
    ▪ Terraform から Microsoft Graph を扱うための非公式のプロバイダです
    https://github.com/yaegashi/terraform-provider-msgraph
    ▪ 短く msgraph provider と呼んでいます
    Microsoft Graph とは?
    ▪ Microsoft 365 クラウドサービスのバックエンドとなる統一 API です
    https://developer.microsoft.com/ja-jp/graph
    ▪ アイデンティティ管理基盤の Azure Active Directory も包含しており、
    Azure クラウドサービスの利用とも深い関係があります!

    View Slide

  5. Official Terraform providers for Azure
    Terraform による Azure の対応状況は?
    ▪ HashiCorp が公式にメンテナンスするプロバイダが 2 つあります
    – azurerm: Azure Resource Manager
    https://github.com/terraform-providers/terraform-provider-azurerm
    – azuread: Azure Active Directory
    https://github.com/terraform-providers/terraform-provider-azuread

    View Slide

  6. azurerm vs. azuread
    プロバイダ azurerm azuread
    開発・保守 HashiCorp HashiCorp
    ライブラリ Azure SDK for Go Azure SDK for Go
    API Azure Resource Manager
    Azure Active Directory Graph
    2022/06 終了予定
    機能
    仮想マシン、ストレージ、
    マネージド DB や K8s など
    Azure のほとんどのサービス
    ユーザー、グループ、アプリケー
    ションなどの ID 管理

    View Slide

  7. azuread provider をとりまく状況
    API: Azure AD Graph の廃止と MS Graph 移行の要請
    ▪ Azure AD Graph は古い API - 2022 年 6 月 30 日で廃止のアナウンス
    ▪ MS Graph は新しい API - Azure AD Graph の機能も包含している
    ▪ すでに Azure AD Graph への新機能の追加は止まっている
    Library: azuread provider の Azure SDK for Go への依存
    ▪ Azure SDK は Azure AD Graph のみに対応しており MS Graph は使えない
    ▪ 公式の MS Graph SDK には Go 言語のサポートがない

    View Slide

  8. azuread provider issues
    Microsoft Graph でなければ対応できない案件が過半を占める

    View Slide

  9. 状況に一石を投じる msgraph.go
    msgraph.go とは?
    ▪ 非公式の Go 言語用 MS Graph ライブラリです
    https://github.com/yaegashi/msgraph.go
    ▪ 会社の Office 365 をいじるために Go 言語でツールを自作したのが始まり
    ▪ Go Conference 2019 Autumn で発表

    View Slide

  10. msgraph provider の誕生
    Terraform provider の開発
    ▪ terraform-plugin-sdk を使用する
    https://github.com/hashicorp/terraform-plugin-sdk
    ▪ msgraph.go のようなライブラリがあれば Terraform provider 開発は容易
    msgraph provider を開発する意義
    ▪ azuread provider の補完と代替
    ▪ Azure SDK for Go の代わりに msgraph.go を使用
    ▪ Azure AD Graph では実現できないことを MS Graph で実現する

    View Slide

  11. azuread vs. msgraph
    プロバイダ azuread msgraph
    開発・保守 HashiCorp コミュニティ
    ライブラリ
    Azure SDK for Go
    (Microsoft)
    msgraph.go
    (コミュニティ)
    API
    Azure Active Directory Graph
    2022/06 終了予定
    Microsoft Graph
    機能
    ユーザー、グループ、アプリケー
    ションなどの ID 管理
    ID 管理、ファイル、メール、カレン
    ダー、サイト、チームなどの
    Microsoft 365 サービスのリソー
    スすべて (予定)

    View Slide

  12. msgraph:
    Features and Performance

    View Slide

  13. azuread_user vs. msgraph_user
    CODE EDITOR
    resource "azuread_user" "azuread_user_1" {
    user_principal_name = "[email protected]"
    display_name = "AzureAD User 1"
    mail_nickname = "azureaduser1"
    password = "Secret123456!"
    }
    resource "msgraph_user" "msgraph_user_1" {
    user_principal_name = "[email protected]"
    display_name = "MSGraph User 1"
    mail_nickname = "msgraphuser1"
    password = "Secret123456!"
    account_enabled = true
    }

    View Slide

  14. azuread_group vs. msgraph_group
    CODE EDITOR
    resource "azuread_group" "azuread_group_1" {
    name = "AzureAD Group 1"
    // members = [azuread_user.azuread_user_1.id]
    }
    resource "azuread_group_member" "azuread_group_member_1" {
    group_object_id = azuread_group.azuread_group_1.id
    member_object_id = azuread_user.azuread_user_1.id
    }
    resource "msgraph_group" "msgraph_group_1" {
    display_name = "MSGraph Group 1"
    mail_nickname = "msgraphgroup1"
    }
    resource "msgraph_group_member" "msgraph_group_member_1" {
    group_id = msgraph_group.msgraph_group_1.id
    member_id = msgraph_user.msgraph_user_1.id
    }

    View Slide

  15. azuread_application vs. ...
    CODE EDITOR
    resource "azuread_application" "azuread_app" {
    name = "AzureAD App"
    homepage = "http://localhost:8080"
    reply_urls = ["http://localhost:8080"]
    required_resource_access {
    resource_app_id = "00000003-0000-0000-c000-000000000000" // MS Graph API
    resource_access {
    id = "df85f4d6-205c-4ac5-a5ea-6bf408dba283" // Files.Read.All
    type = "Scope"
    }
    }
    }
    resource "azuread_application_password" "azuread_app_password" {
    application_object_id = azuread_application.azuread_app.id
    description = "AzureAD App Password"
    value = "Secret123456!"
    end_date = "2100-01-01T00:00:00Z"
    }

    View Slide

  16. ... vs. msgraph_application
    CODE EDITOR
    resource "msgraph_application" "msgraph_app" {
    display_name = "MSGraph App"
    sign_in_audience = "AzureADMyOrg"
    redirect_uris = ["http://localhost:8080"]
    api {}
    required_resource_access {
    resource_app_id = "00000003-0000-0000-c000-000000000000" // MS Graph API
    resource_access {
    id = "df85f4d6-205c-4ac5-a5ea-6bf408dba283" // Files.Read.All
    type = "Scope"
    }
    }
    }
    resource "msgraph_application_password" "msgraph_app_password" {
    application_id = msgraph_application.msgraph_app.id // Object ID
    display_name = "MSGraph App Password"
    end_date_time = "2100-01-01T00:00:00Z"
    }

    View Slide

  17. ベンチマークテスト
    大量のユーザー・グループの作成・削除にかかる時間を比較
    ▪ 100 Users
    ▪ 10 Groups
    ▪ 100 User-in-Group memberships
    ▪ 9 Group-in-Group memberships

    View Slide

  18. msgraph_user×100, msgraph_group×10
    CODE EDITOR
    resource "msgraph_user" "bench_users" {
    count = 100
    user_principal_name = "benchuser${count.index}@l0wdev.onmicrosoft.com"
    display_name = "bench user ${count.index}"
    mail_nickname = "benchuser${count.index}"
    account_enabled = true
    }
    resource "msgraph_group" "bench_groups" {
    count = 10
    display_name = "bench group ${count.index}"
    mail_nickname = "benchgroup${count.index}"
    }

    View Slide

  19. msgraph_group_member×(100+9)
    CODE EDITOR
    resource "msgraph_group_member" "bench_group_user_members" {
    count = 100
    group_id = msgraph_group.bench_groups[count.index % 10].id
    member_id = msgraph_user.bench_users[count.index].id
    }
    resource "msgraph_group_member" "bench_group_group_members" {
    count = 9
    group_id = msgraph_group.bench_groups[count.index].id
    member_id = msgraph_group.bench_groups[count.index + 1].id
    }

    View Slide

  20. ベンチマークテスト結果
    100 users, 10 groups, 109 memberships (単位: 秒)
    Terraform
    azuread provider
    Terraform
    msgraph provider
    msgraph.go
    逐次処理プログラム
    並列度 作成 削除 作成 削除 作成 削除
    ×1 >1000? ? 103.473 107.952 82.119 42.548
    ×10
    (デフォルト)
    125.191 12.832 12.568 12.632
    ×100 30.266 10.745 7.550 7.943
    備考 遅すぎるため
    並列度 ×1 は未計測
    速い! シングルスレッドにつき
    並列度は ×1 のみ
    https://github.com/yaegashi/terraform-provider-msgraph/tree/master/tests/benchmark

    View Slide

  21. ベンチマークテスト考察
    msgraph は azuread に比べてとても速い
    ▪ MS Graph のサーバはとても高速で頑健
    ▪ Azure AD Graph のサーバはたまにリクエストが失敗するらしい?
    – azuread provider では対策としてリソース作成ごとに GET して確認しているようだ
    – msgraph provider では何もしていないがエラーらしいエラーは起きたことがない
    Terraform のワークフローエンジンの威力
    ▪ 宣言的なリソース定義のおかげで、作るのも壊すのも最速の手順で実行してくれる
    ▪ 命令的なプログラムや構成管理ツールに対する Terraform の優位点

    View Slide

  22. msgraph: Conclusion

    View Slide

  23. msgraph まとめ
    msgraph provider とその周辺の話題を紹介しました
    ▪ Terraform の Azure 対応状況について
    ▪ API について: Azure AD Graph と MS Graph
    ▪ ライブラリについて: Azure SDK for Go と msgraph.go
    ▪ azuread と msgraph の使用法の比較・ベンチマークテスト
    Azure を使っている方は msgraph をぜひ使ってみてください!

    View Slide

  24. msgraph これから
    正式リリースに向けた作業
    ▪ 利用者向けドキュメントの整備
    ▪ Terraform Registry への登録
    https://registry.terraform.io
    Better azuread alternative を目指す
    ▪ azuread provider が持つ機能はすべて実装したい
    ▪ OneDrive や Teams など Microsoft 365 リソースに対応したい

    View Slide

  25. Thank You!
    [email protected]
    learn.hashicorp.com
    discuss.hashicorp.com
    25

    View Slide

  26. [email protected]
    learn.hashicorp.com
    discuss.hashicorp.com
    26

    View Slide