Slide 1

Slide 1 text

set-terraform-matrix ͱ͍͏ Actions Λ࡞ͬͨ YuyaKoda 2022/08/19 KyotoLT Online ୈ27ճ

Slide 2

Slide 2 text

ࣗݾ঺հ !3FUUZ@KQͰΠϯϑϥΤϯδχΞΛ΍͍ͬͯ·͢ɻ޷͖ͳژ౎ͷ͓ళ͸ʮເॲړࢣΊ͠ࡶڕ΍ʯͰ͢ɻ ڕͱ೑͹͔Γࡌ͍ͤͯΔͷʹɺ࠷ۙͳ͔ͥ޷͖ϥϕϧʹʮ໺ࡊʯ͕ͭ͘Α͏ʹͳΓ·ͨ͠ɻ 5XJUUFS!QPOLJP@P

Slide 3

Slide 3 text

Terraform ࢖ͬͯ·͔͢ʁ

Slide 4

Slide 4 text

Terraform ͷ CI Ͳ͏ͯ͠·͔͢ʁ

Slide 5

Slide 5 text

Terraform ͷ CI ʹ͍ͭͯ NBJOͷΑ͏ͳEFGBVMUCSBODIΛઃ͚ͯɺ͔ͦ͜ΒϒϥϯνΛ੾ͬͯɺNBJOʹ޲͚ͯ13Λ࡞੒ͯ͠ terraform planΛ࣮ߦ͠ɺNBJOʹϚʔδͨ͠Βterraform apply͕࣮ߦ͞ΕΔύλʔϯ͕Ұൠత Automate Terraform with GitHub Actions - https://learn.hashicorp.com/tutorials/terraform/github-actions

Slide 6

Slide 6 text

GitHub Actions Λ࢖ͬͨ Terraform ͷ CI ͷ࣮૷ྫ

Slide 7

Slide 7 text

matrix job ͷ֓ཁ NBUSJYKPC͸ม਺ͷ૊Έ߹Θͤʹج͍ͮͯෳ਺ͷδϣϒΛੜ੒Ͱ͖ΔػೳͰɺෳ਺ͷόʔδϣϯ΍04Ͱ ςετͷύΠϓϥΠϯΛ૊ΈཱͯΔ࣌ͳΜ͔ʹศརͰ͢ɻ͜ͷδϣϒ͸ฒྻͰ࣮ߦ͞Ε·͢ɻ <ςετ͕࣮ߦ͞ΕΔ04ͱόʔδϣϯͷ૊Έ߹Θͤ> ɾVCVOUVMBUFTU WFSTJPO VCVOUVMBUFTU WFSTJPO VCVOUVMBUFTU WFSTJPO ɾXJOEPXTMBUFTU WFSTJPO XJOEPXTMBUFTU WFSTJPO XJOEPXTMBUFTU WFSTJPO #VJMENBUSJYͷઃఆྫ

Slide 8

Slide 8 text

೚ҙͷ஋Λ${{ matrix.hoge }}ʹೖΕΔ͜ͱ͕Ͱ͖ΔͷͰɺ͜͜ʹσΟϨΫτϦ໊ΛೖΕͯɺෳ਺ͷ σΟϨΫτϦͰterraformίϚϯυΛ࣮ߦ͢ΔΈ͍ͨͳ͜ͱ΋Ͱ͖·͢ɻ Լه͸ͦͷ࣮૷ྫͰɺXPSLEJSʹσΟϨΫτϦ໊ΛೖΕΔ͜ͱͰɺฒྻͰ֤σΟϨΫτϦʹରͯ͠ terraform plan ͕࣮ߦ͞Ε͍ͯΔ༷ࢠͰ͢ɻ matrix job Λར༻ͨ͠ Terraform ͷ࣮ߦ ෳ਺σΟϨΫτϦʹରͯ͠UFSSBGPSNQMBOΛ࣮ߦ͢Δྫ ฒྻͰ࣮ߦ͞Ε͍ͯΔ༷ࢠ

Slide 9

Slide 9 text

ͨͩ͠ɺ͜ͷύλʔϯͩͱ഑ྻʹશ؀ڥͷσΟϨΫτϦ໊͕ೖ͍ͬͯΔͷͰɺຖճ͢΂ͯͷσΟϨΫτϦʹ ରͯ͠terraform plan terraform apply͕࣮ߦ͞Εͯ͠·͏ͱ͍͏໰୊͕͋Γ·͢ɻ ͦͯ͠5FSSBGPSNͰෳ਺ͷ؀ڥΛѻ͍ͬͯΔͱɺಛఆͷ؀ڥ͚ͩʹద༻͍ͨ͠έʔεʹΑ͘ૺ۰͠·͢ɻ ී௨ʹ matrix job Λར༻ͨ͠৔߹ͷ໰୊఺ w ઌʹ։ൃ؀ڥʹରͯ͠terraform applyͯ͠ಈ࡞֬ೝΛ͍ͨ͠έʔε w ಛఆͷ؀ڥͰͷΈ୅දͯ͠࡞੒͢ΔϦιʔε͕͋Δ৔߹ w ྫ͑͹QSPEͷεςʔτϑΝΠϧͰͷΈϦιʔεΛ࡞੒ͯ͠ɺ࡞੒ޙʹEBUBͰࢀর ͢ΔΑ͏ͳύλʔϯɻ͜ͷ৔߹͸ઌʹQSPE͚ͩઌʹBQQMZ͍ͨ͠ ͳΔ΂͘13ͰϨϏϡʔ͢Δϓϩηε͸อ͍ͪͨͷͰɺϩʔΧϧ࣮ߦ͸ආ͚͍ͨʜ

Slide 10

Slide 10 text

ͨͩ͠ɺ͜ͷύλʔϯͩͱ഑ྻʹશ؀ڥͷσΟϨΫτϦ໊͕ೖ͍ͬͯΔͷͰɺຖճ͢΂ͯͷσΟϨΫτϦʹ ରͯ͠terraform plan terraform apply͕࣮ߦ͞Εͯ͠·͏ͱ͍͏໰୊͕͋Γ·͢ɻ ͦͯ͠5FSSBGPSNͰෳ਺ͷ؀ڥΛѻ͍ͬͯΔͱɺಛఆͷ؀ڥ͚ͩʹద༻͍ͨ͠έʔεʹΑ͘ૺ۰͠·͢ɻ ී௨ʹ matrix job Λར༻ͨ͠৔߹ͷ໰୊఺ w ઌʹ։ൃ؀ڥʹରͯ͠terraform applyͯ͠ಈ࡞֬ೝΛ͍ͨ͠έʔε w ಛఆͷ؀ڥͰͷΈ୅දͯ͠࡞੒͢ΔϦιʔε͕͋Δ৔߹ w ྫ͑͹QSPEͷεςʔτϑΝΠϧͰͷΈϦιʔεΛ࡞੒ͯ͠ɺ࡞੒ޙʹEBUBͰࢀর͢ ΔΑ͏ͳύλʔϯɻ͜ͷ৔߹͸ઌʹQSPE͚ͩઌʹBQQMZ͍ͨ͠ ͳΔ΂͘13ϕʔεͰϨϏϡʔ͢Δϓϩηε͸อͬͨ··ɺϩʔΧϧ࣮ߦͱ͔͸ආ͚͍ͨʜ

Slide 11

Slide 11 text

matrix job ͷԠ༻తͳ࢖͍ํ

Slide 12

Slide 12 text

࣮͸͘͢͝؆୯Ͱɺ഑ྻΛ૊ΈཱͯͯPVUQVUͨ͠΋ͷΛ࢖͍͍ͨଆͷKPCͰfromJson()ͰNBUSJYʹ ηοτ͢Δ͜ͱͰɺಈతʹNBUSJYKPCΛ૊ΈཱͯΔ͜ͱ͕Ͱ͖·͢ɻ ಈతʹ matrix Λ૊ΈཱͯΔ

Slide 13

Slide 13 text

ponkio-o/set-terraform-matrix

Slide 14

Slide 14 text

TFUUFSSBGPSNNBUSJY͸ɺ13ʹ෇༩͞ΕͨϥϕϧʹԠͯ͡NBUSJYͷ഑ྻΛฦ͢ࡶͳ"DUJPOTͰ͢ɻ ༧ΊίϚϯυΛ࣮ߦ͍ͨ͠σΟϨΫτϦͱର৅ͷϥϕϧΛؔ࿈෇͚ͯɺͦͷϥϕϧΛ෇༩͢Δ͜ͱͰ೚ҙͷ σΟϨΫτϦʹରͯ͠terraform plan terraform apply ͳͲΛ࣮ߦͰ͖·͢ɻ ผͷίϚϯυ΋Մೳ ponkio-o/set-terraform-matrix Set matrix job workdir - https://github.com/marketplace/actions/set-matrix-job-workdir

Slide 15

Slide 15 text

·ͣ͸࣮ߦ͢ΔσΟϨΫτϦͱ؀ڥ໊ΛϚοϐϯάͨ͠ઃఆϑΝΠϧΛ࡞੒͠·͢ɻ 
 ݱࡏ͸EFWFMPQTUBHJOHQSPEVDUJPOͷ؀ڥͷΈαϙʔτ͍ͯ͠·͢ɻແ͍؀ڥ͸লུՄೳ ponkio-o/set-terraform-matrix ͷ࢖͍ํ EFQMPZ@UBSHFUKTPOͷྫ

Slide 16

Slide 16 text

TFUUFSSBGPSNNBUSJYͷPVUQVUΛNBUSJYͱͯ͠࢖༻͢ΔKPCΛఆٛ͠·͢ɻ ponkio-o/set-terraform-matrix ͷ࢖͍ํ

Slide 17

Slide 17 text

13࡞੒࣌ʹterraform ίϚϯυΛ࣮ߦ͍ͨ͠؀ڥͷʮλʔήοτϥϕϧʯΛબ୒͠·͢ɻ 
 ྫ͑͹UBSHFUEFWFMPQUBSHFUTUBHJOHΛ͚ͭͨ৔߹ʹ͸ɺࣄલʹఆٛͨ͠EFWFMPQTUBHJOHʹ ର͢ΔσΟϨΫτϦͷ഑ྻ͕ฦ͞Ε·͢ɻ ponkio-o/set-terraform-matrix ͷ࢖͍ํ

Slide 18

Slide 18 text

UBSHFUEFWFMPQUBSHFUTUBHJOHϥϕϧΛ෇༩ͯ͠ɺର৅ͷσΟϨΫτϦͰͷΈ࣮ߦ͞Ε͍ͯΔ༷ࢠͰ͢ɻ ͪͳΈʹQMBOͷίϝϯτʹ͸TV[VLJTIVOTVLFUGDNUΛ࢖͍ͬͯ·͢ɻ͍ͭ΋͓ੈ࿩ʹͳ͍ͬͯ·͢ɻ ponkio-o/set-terraform-matrix ͷ࣮ߦྫ EFWFMPQTUBHJOHͰQMBO͕࣮ߦ͞Ε༷ͨࢠ

Slide 19

Slide 19 text

ϥϕϧʹରͯ͠σϑΥϧτ஋Λઃ͚͍ͯͳ͍ͷͰɺϥϕϧΛબ୒͠ͳ͔ͬͨ৔߹ʹ͸$*Λམͱ͢Α͏ʹ ͍ͯ͠·͢ɻͦͷࡍʹ͸Լهͷ༷ͳΨΠυϝοηʔδ͕දࣔ͞Ε·͢ɻ ͪͳΈʹ13ίϝϯτͷQPTUʹ͸TV[VLJTIVOTVLFHJUIVCDPNNFOUΛར༻͍ͯ͠·͢ɻ ϥϕϧͷ෇༩͕͞Ε͍ͯͳ͍࣌ ϥϕϧ͕બ୒͞Εͣʹ13͕PQFO͞Εͨ࣌ʹ౤ߘ͞ΕΔϝοηʔδ

Slide 20

Slide 20 text

ϥϕϧͷબ୒Λ๨Εͨ࣌ʹ͸໨తͷϥϕϧΛ෇༩͔ͯ͠Β$*ΛSFSVOͤ͞Δඞཁ͕͋Γ·͕͢ɺ"DUJPOT ͷը໘ͰSFSVOͨ͠৔߹ͩͱʮͦͷ࣌఺ͷ13ͷঢ়ଶʯͰSFSVO͠·͢ɻ ͜ͷ໰୊ʹؔͯ͠͸SFSVOͱίϝϯτ͢Δ͜ͱͰ֘౰13ʹFNQUZDPNNJU͕ੵ·ΕͯɺͦΕΛτϦΨʔ ʹͯ͠$*Λ࠶౓૸ΒͤΔΑ͏ʹ͍ͯ͠·͢ɻ ˞ SFSVOʹ͍ͭͯ͸TFUUFSSBGPSNNBUSJYͷػೳͰ͸ͳ͘ɺผͰXPSLGMPXΛઃ͚͍ͯΔ ࠶࣮ߦ͍ͨ࣌͠ SFSVOίϚϯυͰ$*ΛτϦΨʔ͍ͯ͠Δ༷ࢠ ˞POQVMM@SFRVFTUUZQFTͰϥϕϧͷ෇༩ΛτϦΨʔʹؚΊΔ͜ͱ΋Ͱ͖·͕͢ɺUGDNUͷUPLFOͰ1"5΍(JU)VC"QQTΛར༻͍ͯ͠Δ৔߹ʹ͸ɺUGDNUͷϥϕϧ෇༩Ͱແݶʹ $*͕τϦΨʔ͞ΕΔͨΊ͜͏͍ͯ͠·͢ɻUGDNUͷϥϕϧΛແޮԽͨ͠ΓɺຒΊࠐΈͷ(*5)6#@50,&/ SBUFMJNJU͖͍͚ͭͲ Λ࢖͑͹MBCMFE΋࢖͑·͢ɻ

Slide 21

Slide 21 text

ྫ͑͹ઌʹEFWFMPQ͚ͩʹద༻ͯ͠ɺNBJOͱಉ͡಺༰ͷ΋ͷͰ ϑΝΠϧͷมߋͳ͠ʹ ࠶౓ผͷ؀ڥʹ ରͯ͠terraform plan terraform applyΛ࣮ߦ͍ͨ͠έʔεɻ ͜Εʹؔͯ͠͸FNQUZDPNNJU͚ͩΛੵΜͰ৽ن13Λ࡞੒͢ΔXPSLGMPXΛ࡞ͬͯରԠ͍ͯ͠·͢ɻ 13࡞੒ޙͷྲྀΕ͸࠷ॳͱಉ͡ͰɺϥϕϧΛબ୒ͯ͠3FBEZGPSSFWJFXʹ͠·͢ɻ Terraform ͷ࣮ߦͷΈΛߦ͍͍ͨ৔߹ PR Λ࡞Δ actions ࣗಈੜ੒͞Εͨ PR

Slide 22

Slide 22 text

·ͱΊ w (JU)VC"DUJPOTͷNBUSJY͸ಈతʹ૊ΈཱͯΔ͜ͱ͕Մೳ w ྫ͑͹มߋ͞ΕͨϑΝΠϧͷσΟϨΫτϦΛݕ஌ͯͦ͠ͷσΟϨΫτϦͰͷΈίϚϯυ࣮ߦͳͲ΋ Մೳ w TFUUFSSBGPSNNBUSJYΛ࢖͏ͱɺ෇༩͢ΔϥϕϧʹԠͯ͡೚ҙͷσΟϨΫτϦʹίϚϯυΛ࣮ߦՄೳ w ʮಛఆͷσΟϨΫτϦʹର͚࣮ͯͩ͠ߦ͍ͨ͠ʯ͕࣮ݱͰ͖Δ w ໊લʹUFSSBGPSNͱೖ͍ͬͯ·͕͢ɺ഑ྻΛฦ͚ͩ͢ͳͷͰผͷίϚϯυ΋࣮ߦՄೳ

Slide 23

Slide 23 text

͓͠·͍