Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Terraform Provider開発のノウハウ

Terraform Provider開発のノウハウ

Kanji Yomoda

August 25, 2022
Tweet

More Decks by Kanji Yomoda

Other Decks in Technology

Transcript

  1. Agenda - Terraform Providerͷ໾ׂ - TerraformϓϩόΠμʔͷॳظߏங - खݩͰProviderΛಈ͔͢ - Ϧιʔεͷཻ౓ͷܾΊํ

    - ෳ਺Ϧιʔεͷڝ߹ճආ - σόοάϩάΛຒΊࠐΉ - ࡟আ࿙Εςετ༻ϦιʔεͷରԠ
  2. TerraformϓϩόΠμʔͷॳظߏங - ެࣜυΩϡϝϯτ͕ͱͯ΋ॆ࣮͍ͯ͠Δ - Terraform Provider༻SDK - terraform-plugin-sdkͰ͸ͳ͘terraform-plugin-frameworkΛ࢖͏ - Template

    - ϘΠϥϓϨʔτɺCI(Test,Release)ɺυΩϡϝϯτੜ੒ɺ౳ʑશ෦ೖΓ https://github.com/hashicorp/terraform-provider-scaffolding-framework
  3. खݩͰProviderΛಈ͔͢ - Terraform ProviderͷΠϯετʔϧͷྲྀΕ - tfϑΝΠϧΛಡΈඞཁͳProviderɺVersionΛ֬ೝ - Ωϟογϡʹ͋Ε͹ΩϟογϡΛ࢖͏ - CLIͷConfigϑΝΠϧͷઃఆ(Mac

    OSͷ৔߹͸~/.terraformrc)ΛಡΈΠϯετʔϧઌΛ֬ೝ - ໌ࣔ͞Ε͍ͯͳ͚Ε͹҉໧తʹԼهͷॱͰΠϯετʔϧ(Mac OSͷ৔߹) - $HOME/.terraform.d/plugins/ - ~/Library/Application Support/io.terraform/plugins - /Library/Application Support/io.terraform/plugins - ./terraform.d/plugins - ֎෦ϨδετϦ https://www.terraform.io/cli/config/config-file
  4. खݩͰProviderΛಈ͔͢ - Terraform ProviderͷΠϯετʔϧͷྲྀΕ - tfϑΝΠϧΛಡΈඞཁͳProviderɺVersionΛ֬ೝ - Ωϟογϡʹ͋Ε͹ΩϟογϡΛ࢖͏ - CLIͷConfigϑΝΠϧͷઃఆ(Mac

    OSͷ৔߹͸~/.terraformrc)ΛಡΈΠϯετʔϧઌΛ֬ೝ - ໌ࣔ͞Ε͍ͯͳ͚Ε͹҉໧తʹԼهͷॱͰΠϯετʔϧ(Mac OSͷ৔߹) - $HOME/.terraform.d/plugins/ - ~/Library/Application Support/io.terraform/plugins - /Library/Application Support/io.terraform/plugins - ./terraform.d/plugins - ֎෦ϨδετϦ https://www.terraform.io/cli/config/config-file
  5. खݩͰProviderΛಈ͔͢ - ԼهͷConfigϑΝΠϧͷઃఆͰ։ൃ༻ʹ࢖༻͢ΔProviderΛ೚ҙͷσΟϨΫτϦͷύεʹ্ॻ͖͕Մೳ - Windows: %APPDATA%ͷ௚Լͷterraform.rc - ͦΕҎ֎: ~/.terraformrc -

    Version΍Checksumͷݕূ͕εΩοϓ͞ΕΔ (= ศར but ҙਤ͠ͳ্͍ॻ͖ʹ஫ҙ) https://www.terraform.io/cli/config/config-file#development-overrides-for-provider-developers ※ dev_overrides͸v0.14Ҏ߱ͷΈ࢖༻Մೳ
  6. Ϧιʔεͷཻ౓ͷܾΊํ Ұ౓ʹෳ਺ૢ࡞͍ͨ͠έʔε͕͋Δ(e.g. ݖݶɺϗϫΠτϦετ౳) - 1ͭͷϦιʔεʹ഑ྻorϒϩοΫͰఆٛ͢Δ - Or Ϣʔβʔʹෳ਺Ϧιʔε࡞ͬͯ΋Β͏ ߟྀϙΠϯτ -

    Ϣʔεέʔε => ݸผ and/or ҰׅͰઃఆ͍ͨ͠έʔε͕͋Δ͔൱͔ - ઃఆ͞Ε͏Δྔ => ଟ͍৔߹͸ݸผͷϦιʔεͩͱplan/applyʹ͕͔͔࣌ؒΔ - API => Ұׅૢ࡞͢ΔAPI͕ఏڙ͞Ε͍ͯΔ͔ - Quota / Rate limit => େྔͷAPIίʔϧͰQuota / rate limitͷ্ݶʹୡ͠ͳ͍͔
  7. Ϧιʔεͷཻ౓ͷܾΊํ - ྨࣅޠΛొ࿥͢ΔAPI༻ͷϦιʔεఆٛ - 1ͭͷindex(≒table)ʹର͠ɺෳ਺ͷྨࣅޠͷϖΞΛొ࿥Ͱ͖Δ(e.g. ϙςν<=>ϙςτνοϓε) ߟྀϙΠϯτ => ݁ՌɺindexຖʹҰׅૢ࡞͢ΔsynonymsϦιʔεΛఆٛ -

    Ϣʔεέʔε => ҰׅͰઃఆ͢Δέʔε͕େ൒ - ઃఆ͞Ε͏Δྔ => ~100k - API => Ұׅૢ࡞͢ΔAPI͋Γ - Quota / Rate limit => ্ݶ͸௿Ί(ແྉϓϥϯ͕ཧ༝ͳՄೳੑ΋) Algolia Providerͷྫ
  8. σόοάϩάΛຒΊࠐΉ - HttpϦΫΤετɺϨεϙϯεͷϩάΛऔΕΔΑ ͏ʹ͓ͯ͘͠ - httputil.DumpRequestOut, httputil.DumpResponse͕ͱͯ΋ศར - http.TransportΛϥοϓͯ͠req/resͷμϯϓ Λϩάʹॻ͖ग़͢

    - terraform-plugin-sdkʹ͸ؙͬͱ΍ͬͯ͘ΕΔ ϔϧύʔؔ਺ logging.NewLoggingHTTPTransport()͕͋Δ ͕ɺterraform-plugin-frameworkʹ͸ͳ͍ https://www.terraform.io/plugin/debugging
  9. ·ͱΊ - Terraform Providerͷ໾ׂ => TerraformͷStateͱAPIͷreq/resͷڮ౉͠ - TerraformϓϩόΠμʔͷॳظߏங => terraform-plugin-framework

    & templateΛ࢖͏ - खݩͰProviderΛಈ͔͢ => ~/.terraformrcͷઃఆ or ॴఆͷύεʹόΠφϦΛஔ͘ - σόοάϩάΛຒΊࠐΉ => ࠷௿ݶHttpϦΫΤετɺϨεϙϯεͷϩάΛऔ͓ͬͯ͘ͱศར - Ϧιʔεͷཻ౓ͷܾΊํ => ϢʔεέʔεͱAPIͷ࢓༷͔ΒέʔεόΠέʔεͰߟ͑Δ - ෳ਺Ϧιʔεͷڝ߹ճආ => ΦϯϝϞϦͷLockΛऔΔ - ࡟আ࿙Εςετ༻APIϦιʔεͷରԠ => Ϧιʔε໊ʹprefixΛ͚ͭͯҰׅ࡟আ