Slide 1

Slide 1 text

tfnotify @b4b4r07 (Sep 11, 2018) / HashiCorp Meetup #3
 DevOps Λࢧ͑Δࠓ࿩୊ͷ HashiCorp πʔϧ܈ʹ͍ͭͯ Show Terraform execution plan beautifully on GitHub

Slide 2

Slide 2 text

BABAROT / @b4b4r07 Mercari, Inc.
 SRE, Microservices Platform Blog / tellme.tokyo

Slide 3

Slide 3 text

1. mercari/tfnotify 2. Why tfnotify? 3. Implementations Agenda

Slide 4

Slide 4 text

mercari/tfnotify

Slide 5

Slide 5 text

• Go ੡ CLI πʔϧ • Terraform ͷ࣮ߦ݁ՌΛύʔε͠ɺ
 ద੾ͳϑΥʔϚοτʹ͋ͯ͸Ίͯɺ
 ೚ҙͷ௨஌ઌ (GitHub ͷίϝϯτ౳)
 ΁௨஌͢Δ tfnotify ͱ͸

Slide 6

Slide 6 text

tfnotify Workflow DSFBUFE UFSSBGPSNQMBOcUGOPUJGZQMBO 1045DPN N FOU PVUQVU

Slide 7

Slide 7 text

tfnotify Workflow N FSHFE UFSSBGPSNBQQMZcUGOPUJGZBQQMZ 1045DPN N FOU PVUQVU

Slide 8

Slide 8 text

Example • fmt • plan • apply

Slide 9

Slide 9 text

Example {{.Title}} {{.Message}} {{.Result}} {{.Body}} ࣮ߦग़ྗ͢΂ͯ ࣮ߦ݁ՌͷαϚϦ --messageͰ౉ͤΔ ೚ҙͷλΠτϧ

Slide 10

Slide 10 text

Why tfnotify?

Slide 11

Slide 11 text

ͳͥඞཁͱͳͬͨͷ͔ • ϝϧΧϦͰ͸ Microservices ྖҬͰ Terraform Λར༻͍ͯ͠Δ • Ownership ͷ؍఺͔ΒΠϯϑϥ؅ཧʹ͓͍ͯ΋ϨϏϡʔɾϚʔδ͸ ֤ Micorservices νʔϜʹΑͬͯ͞ΕΔ΂͖ • ͱ͸͍ͬͯ΋ɺPlatform νʔϜʹϨϏϡʔ͞Ε͍ͨέʔε΋͋Δ

Slide 12

Slide 12 text

ͳͥඞཁͱͳͬͨͷ͔ • Platform νʔϜͱͯ͠΋ɺ֤ Microservices νʔϜͱͯ͠΋ɺ
 Infrastructure as Code ͷॏཁੑΛཧղ͠ Terraform ͰίʔυԽ͠ɺ ͦͷ࣮ߦܭըΛຖճݟΔ͜ͱΛश׳͚͍ͮͨ • ຖ೔ଟ͘ͷ P-R ͕͋ΔதɺCircle CI ʹݟʹ͍͘खؒΛল͖͍ͨ →ϨϏϡʔͷྲྀΕͰ GitHub ্ͰΫΠοΫʹ֬ೝ͍ͨ͠

Slide 13

Slide 13 text

ϝϧΧϦͰͷ HashiCorp πʔϧ

Slide 14

Slide 14 text

ϝϧΧϦͰͷ HashiCorp πʔϧ • ϝϧΧϦʹ͸ 70 Ҏ্ͷ Microservices ͕͋Δ
 (ࠓ೔ݱࡏɽ૿͑ଓ͚͍ͯΔ) • ͢΂ͯͷ Microservices ͱͦͷ Platform ͷ
 Πϯϑϥߏஙʹ͸ Terraform Λར༻͍ͯ͠Δ • Developers ʹ Infrastructure as Code Λ
 ࣮ફͯ͠΋Β͏

Slide 15

Slide 15 text

ϝϧΧϦͰͷ Terraform ར༻ࣄྫ

Slide 16

Slide 16 text

ϝϧΧϦͰͷ Terraform ར༻ࣄྫ

Slide 17

Slide 17 text

ϝϧΧϦͰͷ Terraform ར༻ࣄྫ

Slide 18

Slide 18 text

ϝϧΧϦͰͷ Terraform ར༻ࣄྫ

Slide 19

Slide 19 text

ϝϧΧϦͰͷ Terraform ར༻ࣄྫ • Insights • 110+ Contributors • 8 ~ 10 Pull Requests / week (5 days) • 140+ state files (70+ Microservices * 2 Env) • ͻͱͭͷதԝϦϙδτϦͰ͢΂ͯͷ Terraform ίʔυΛ؅ཧ͍ͯ͠Δ • CI pipeline ͷߏங͕Ұ౓ͰࡁΉ • Platform νʔϜ͕ϨϏϡʔʹೖΓ΍͍͢

Slide 20

Slide 20 text

ϦϙδτϦߏ੒ • ֤ Microservice ͝ͱʹ
 σΟϨΫτϦΛ෼͚Δ • Service ͝ͱʹ tfstate Λ෼͚Δ • ӨڹΛଞ΁೾ٴͤ͞ͳ͍ • Resource ͝ͱʹ file Λ෼͚Δ • Ϧιʔεఆٛ৔ॴΛ໌֬Խ • CODEOWNERS Ͱݖݶҕৡ

Slide 21

Slide 21 text

ϦϙδτϦߏ੒ • ֤ Microservice ͝ͱʹ
 σΟϨΫτϦΛ෼͚Δ • Service ͝ͱʹ tfstate Λ෼͚Δ • ӨڹΛଞ΁೾ٴͤ͞ͳ͍ • Resource ͝ͱʹ file Λ෼͚Δ • Ϧιʔεఆٛ৔ॴΛ໌֬Խ • CODEOWNERS Ͱݖݶҕৡ தԝूݖ ཱࣗ෼ࢄ

Slide 22

Slide 22 text

ݖݶҕৡ IUUQTCMPHHJUIVCDPNJOUSPEVDJOHDPEFPXOFST • GitHub ͷػೳ • CODEOWNERS ʹهࡌ͞Ε ͨਓ͔Β Approve ͞ΕΔ
 ·ͰϚʔδͰ͖ͳ͍Α͏ʹ Ͱ͖Δ • ͜ΕʹΑΓݖݶҕৡΛ࣮ݱ • (উखʹมߋͰ͖ͳ͍)

Slide 23

Slide 23 text

ݖݶҕৡ IUUQTIFMQHJUIVCDPNBSUJDMFTBCPVUDPEFPXOFST

Slide 24

Slide 24 text

Ϟδϡʔϧ • microservices-starter-kit (Terraform Ϟδϡʔϧ) • Template Provider Λ࢖͍σΟϨΫτϦ࡞੒ɺϑΝΠϧు͖ग़͠ • Microservices ͷ্ཱͪ͛ʹඞཁͳϦιʔεΛ Bootstrap ͢Δ • GCP Project, Service account ͳͲ • PagerDuty, DataDog, Kubernetes (Namespace, Secret) ͳͲ • GitHub Teams (CODEOWNERS ͷݖݶҕৡʹ࢖͏) IUUQTTQFBLFSEFDLDPNCCSUFSSBGPSNPQTGPSNJDSPTFSWJDFT

Slide 25

Slide 25 text

Implementations

Slide 26

Slide 26 text

࣮૷ • io.TeeReader Λ࢖͍ͬͯΔ • GitHub ʹ POST ͢Δ͚ͩͰ͸ ͳ͘ CI ͷ Console ʹ΋ग़ྗ • Terraform ͷ࣮ߦ݁Ռ͸ࣗલͷ ύʔαͰߏ଄Խ͢Δ (regexp) • POST ͢Δϝοηʔδ͸ Go ͷ
 ςϯϓϨʔτͰॻ͘͜ͱ͕Ͱ͖Δ • ઃఆ͸ YAML Ͱ࣋ͭ

Slide 27

Slide 27 text

࣮૷ • ॏෳͨ͠಺༰͕͋Δ৔߹ɺ
 ݹ͍΋ͷ͕࡟আ͞ΕΔ • ࣮ߦ݁Ռ͸௕͍ͷͰ Details λά ͰғͬͯંΓͨͨΈɺҰṮʹඞཁ ͳ৘ใ͚͕ͩݟ΍͘͢දࣔ͞ΕΔ
 {{.Title}}, {{.Message}} ͷॏෳΛݟΔ

Slide 28

Slide 28 text

Conclusion

Slide 29

Slide 29 text

·ͱΊ • ϝϧΧϦͰ͸ Microservices ྖҬͰ Terraform Λར༻͍ͯ͠Δ • ूݖͱ෼ࢄͷόϥϯεͰ Terraform ϦϙδτϦΛӡ༻͍ͯ͠Δ • ͨ͘͞Μͷ P-R Λޮ཰Α͘ϨϏϡʔ͢ΔͨΊ tfnotify Λॻ͍ͨ • Terraform ͷ࣮ߦ݁ՌΛखܰʹ֬ೝ͍ͨ͠ • Infrastructure as Code ͷจԽΛࠜ෇͔ͤΔ • ຖճ plan, apply ݁ՌΛݟΔश׳Λ΋ͭ / ΋ͬͯ΋Β͏ • ઌߦ࣮૷͕ͳ͍ͨΊ OSS ʹͨ͠

Slide 30

Slide 30 text

Thanks