Slide 1

Slide 1 text

~CircleCIͰTerraformϦϦʔεͷαʔόʔϨεԽ~ ϥϯαʔζגࣜձࣾ ։ൃ෦/ٕज़ج൫ SRE ҆ୡ ྋ ʲࣗಈԽԿͰ΋LTେձฤʳCircleCI ίϛϡχςΟϛʔτΞοϓ 2021/11/24 ΠϯϑϥͷಠࣗϦϦʔεΛܧଓతϦϦʔε΁

Slide 2

Slide 2 text

ΞδΣϯμ • ࣗݾ঺հ • ฐࣾࠓ·ͰͷTerraform؅ཧํ๏ • DeployαʔόʔͰͷ՝୊ͱվળ • Terraform։ൃ؀ڥʹ͍ͭͯ • CircleCIͰͷϦϦʔεϑϩʔ(Ҏલ) • CircleCIͰͷϦϦʔεϑϩʔ(ݱࡏ) • ·ͱΊ ʲࣗಈԽԿͰ΋LTେձฤʳCircleCI ίϛϡχςΟϛʔτΞοϓ 2021/11/24

Slide 3

Slide 3 text

ࣗݾ঺հ ʲࣗಈԽԿͰ΋LTେձฤʳCircleCI ίϛϡχςΟϛʔτΞοϓ 2021/11/24

Slide 4

Slide 4 text

ࣗݾ঺հ • ҆ୡ ྋ(adachin) • Lancers/SRE 
 2018/5~ • @adachin0817 • RVIRUS0817 • blog.adachin.me • wiki.adachin.me • ઈࢍݸਓαʔϏε։ൃத ʲࣗಈԽԿͰ΋LTେձฤʳCircleCI ίϛϡχςΟϛʔτΞοϓ 2021/11/24

Slide 5

Slide 5 text

ฐࣾαʔϏε ʹ͍ͭͯ ʲࣗಈԽԿͰ΋LTେձฤʳCircleCI ίϛϡχςΟϛʔτΞοϓ 2021/11/24

Slide 6

Slide 6 text

ฐࣾαʔϏεʹ͍ͭͯ ʲࣗಈԽԿͰ΋LTେձฤʳCircleCI ίϛϡχςΟϛʔτΞοϓ 2021/11/24 (Ұ෦)

Slide 7

Slide 7 text

ͪͳΈʹ ʲࣗಈԽԿͰ΋LTେձฤʳCircleCI ίϛϡχςΟϛʔτΞοϓ 2021/11/24

Slide 8

Slide 8 text

ݸਓͰCircleCIѪ༻͍ͯ͠·͢🙌 • ݸਓͷϙʔτϑΥϦΦ(adachin.me) 
 ɾࣗಈσϓϩΠ 
 ɹɾSSH release • ݸਓϒϩά(blog.adachin.me) 
 ɾTerraform CI x CD • ຖ݄ͷίετ௨஌ 
 ɾTrigger 
 ɹ ʲࣗಈԽԿͰ΋LTେձฤʳCircleCI ίϛϡχςΟϛʔτΞοϓ 2021/11/24

Slide 9

Slide 9 text

ฐࣾࠓ·Ͱͷ Terraform؅ཧํ๏ ʲࣗಈԽԿͰ΋LTେձฤʳCircleCI ίϛϡχςΟϛʔτΞοϓ 2021/11/24

Slide 10

Slide 10 text

ฐࣾࠓ·ͰͷTerraform؅ཧํ๏ • Deployαʔόʔ 
 ɾ֤αʔόʔଆͷσϓϩΠ(Ansible/Terraform) 
 ɾΞϓϦέʔγϣϯͷσϓϩΠͱ༷ʑͳ༻్ͱͯ͠ར༻ • Terraform CI 
 ɾpush͢Δ౓ʹvalidate,plan͕૸ΔΑ͏ʹ 
 ɾTerraform Cloud͸ར༻͍ͯ͠ͳ͍ • Lancers 
 ɾAmazon Linux 2 (Arm)ʹҠߦޙ 
 ɾੑೳධՁΛECS/Fargate(Arm)ͱൺ΂ͯҠߦ 
 ɾDeployαʔόʔ͸ഇࢭ͢Δ༧ఆ 
 ʲࣗಈԽԿͰ΋LTେձฤʳCircleCI ίϛϡχςΟϛʔτΞοϓ 2021/11/24

Slide 11

Slide 11 text

ʲࣗಈԽԿͰ΋LTେձฤʳCircleCI ίϛϡχςΟϛʔτΞοϓ 2021/11/24 https://blog.adachin.me/archives/11698

Slide 12

Slide 12 text

DeployαʔόͰͷ ՝୊ͱվળ ʲࣗಈԽԿͰ΋LTେձฤʳCircleCI ίϛϡχςΟϛʔτΞοϓ 2021/11/24

Slide 13

Slide 13 text

DeployαʔόʔͰͷ՝୊ͱվળ • ϒϥϯνͷ੾Γସ͑Λ๨ΕͯଞͷϦϦʔεʹӨڹ͕ग़Δ • 1ਓ͕ґଘͯ͠͠·͏͜ͱͰෳ਺ਓͰͷTerraform։ൃεϐʔυ͕஗ΕΔ • TerraformͷόʔδϣϯΞοϓରԠத 
 ɾٸʹґཔ͕དྷͯɺόʔδϣϯͷ੾Γସ͑Λ͠ͳ͚Ε͹ͳΒͳ͍ • ECS Scheduled Taskසൟʹ։ൃϝϯόʔ͔ΒͷϨϏϡʔ 
 ɾϦϦʔεͷࡍSREνʔϜͷ޻਺͕͔͔Γద༻࿙Ε͕ଟൃ • TerraformΛϩʔΧϧͰద༻͍ͨ͠ͱࢥͬͯ΋.. 
 ɾΫϨσϯγϟϧͷݖݶ͕ڧա͗ΔͷͰ؅ཧͨ͘͠ͳ͍(࿙ӮͷڪΕ) 
 ʲࣗಈԽԿͰ΋LTେձฤʳCircleCI ίϛϡχςΟϛʔτΞοϓ 2021/11/24 Terraformઐ༻ͷ։ൃ؀ڥΛߏஙɺCircleCIͰܧଓతʹϦϦʔε

Slide 14

Slide 14 text

Terraform ։ൃ؀ڥʹ͍ͭͯ ʲࣗಈԽԿͰ΋LTେձฤʳCircleCI ίϛϡχςΟϛʔτΞοϓ 2021/11/24

Slide 15

Slide 15 text

Terraform։ൃ؀ڥʹ͍ͭͯ(partᶃ) • ֤ϓϩδΣΫτʹ։ൃ؀ڥΛ༻ҙ • ΫϨσϯγϟϧͷ؅ཧํ๏ 
 ɾAWS KMS 
 ɹ1. KMSઐ༻ͷΫϨσϯγϟϧ 
 ɹ2. ҉߸Խ͞ΕͨkeyΛίϐʔ 
 ɹ3. ίϯςφ಺ʹΫϨσϯγϟϧΛ্ॻ͖Ͱ෮߸͢Δ • ηΩϡϦςΟϨϕϧ͕ೋॏʹ 
 ɾdocker-compose downʹΑΓ࡟আ͞ΕΔ 
 ɾ࿙ӮϦεΫ͸Լ͕Δ 
 ʲࣗಈԽԿͰ΋LTେձฤʳCircleCI ίϛϡχςΟϛʔτΞοϓ 2021/11/24

Slide 16

Slide 16 text

Terraform։ൃ؀ڥʹ͍ͭͯ(partᶄ) ʲࣗಈԽԿͰ΋LTେձฤʳCircleCI ίϛϡχςΟϛʔτΞοϓ 2021/11/24

Slide 17

Slide 17 text

CircleCIͰͷ 
 ϦϦʔεϑϩʔ(Ҏલ) ʲࣗಈԽԿͰ΋LTେձฤʳCircleCI ίϛϡχςΟϛʔτΞοϓ 2021/11/24

Slide 18

Slide 18 text

CircleCIͰͷϦϦʔεϑϩʔ(Ҏલ) • masterϚʔδͰterraform applyΛ࣮ࢪ͍͕ͯͨ͠... • SREνʔϜ 
 ɾTerraformͰσόοάͯͦ͠ͷ··apply • ։ൃνʔϜ 
 ɾଞͷϓϧϦΫΛϚʔδ • AWSଆ͸ݩʹ໭Δˠة͏͘ΠϯγσϯτʹͳΓಘΔ • CircleCIͷAPIΛར༻ͯ͠γΣϧͰϦϦʔεΛ࣮૷͕ͨ͠.. 
 ɾݖݶతʹ։ൃϝϯόʔ͕શһϦϦʔεग़དྷͯ͠·͏ͱ͍͏՝୊͕… 
 ɾApprovalͷঝೝͰͷϑϩʔͰӡ༻ͯ͠Έ͕ͨϑϩʔ͕૿͑ͯՙ͕ॏ͍.. 
 
 ʲࣗಈԽԿͰ΋LTେձฤʳCircleCI ίϛϡχςΟϛʔτΞοϓ 2021/11/24

Slide 19

Slide 19 text

CircleCIͰͷ 
 ϦϦʔεϑϩʔ(ݱࡏ) ʲࣗಈԽԿͰ΋LTେձฤʳCircleCI ίϛϡχςΟϛʔτΞοϓ 2021/11/24

Slide 20

Slide 20 text

CircleCIͰͷϦϦʔεϑϩʔ(ݱࡏ) • Orbs 
 ɾpath- fi ltering(ਖ਼نදݱ) • masterϚʔδ 
 ɾterraformσΟϨΫτϦ഑Լ 
 ɾmasterͱͷࠩ෼͕͋Ε͹terraform apply • setup: true ͕ඞਢ 
 ɾෳ਺ͷwork fl ow͕ແޮԽʹͳΔ 
 ɾsingle work fl owʹͯ͠෼ׂ͢Δ͜ͱ 
 ʲࣗಈԽԿͰ΋LTେձฤʳCircleCI ίϛϡχςΟϛʔτΞοϓ 2021/11/24

Slide 21

Slide 21 text

CircleCIͰͷϦϦʔεϑϩʔ(ݱࡏ) • check_terraform_difference • ࠩ෼͕ͳ͍ͱ͖ʹmappingʹݕ஌❌ 
 ɾશͯͷύϥϝʔλ͸defaultͷfalse͕ฦΔ 
 ɾechoͰtrueΛฦ͢Α͏ʹ࡞Δඞཁ͕͋Δ • terraformσΟϨΫτϦʹࠩ෼͕ͳ͚Ε͹ 
 ɾcheck_terraform_difference͕ಈ࡞ 
 ɾࠩ෼͕͋Ε͹terraform apply • CircleCI͞ΜվળΛ!!🙏 ʲࣗಈԽԿͰ΋LTେձฤʳCircleCI ίϛϡχςΟϛʔτΞοϓ 2021/11/24

Slide 22

Slide 22 text

·ͱΊ ʲࣗಈԽԿͰ΋LTେձฤʳCircleCI ίϛϡχςΟϛʔτΞοϓ 2021/11/24

Slide 23

Slide 23 text

·ͱΊ • Deployαʔόʔ͔Βͷ؅ཧΛ୤٫͢Δ͜ͱ͕Ͱ͖ͨ • ։ൃ؀ڥͰTerraformͷσόοά͕͠΍͘͢ͳͬͨ • TerraformͷϦϦʔεΛ҆શʹαʔόʔϨεͰͷ࣮ݱ͕Ͱ͖ͨ • Lancersຊମ΋׬શTerraformԽ͢ΔͨΊͷ४උ΋੔͏͜ͱ͕Ͱ͖ͨ • path- fi ltering 
 ϞϊϨϙͰ΋ύε୯ҐͰࣗಈϦϦʔε͢Δ͜ͱ͕Ͱ͖Δ 
 LambdaͳͲʹ΋Ԡ༻ • Terraform OrbsʹҠߦ͍ͨ͠ 
 
 ʲࣗಈԽԿͰ΋LTେձฤʳCircleCI ίϛϡχςΟϛʔτΞοϓ 2021/11/24

Slide 24

Slide 24 text

ʲࣗಈԽԿͰ΋LTେձฤʳCircleCI ίϛϡχςΟϛʔτΞοϓ 2021/11/24 https://engineer.blog.lancers.jp/sre/terraform_circleci/

Slide 25

Slide 25 text

ʲࣗಈԽԿͰ΋LTେձฤʳCircleCI ίϛϡχςΟϛʔτΞοϓ 2021/11/24 https://engineer.blog.lancers.jp/engineer-recruit/

Slide 26

Slide 26 text

͝ਗ਼ௌ͋Γ͕ͱ͏ ͍͟͝·ͨ͠ʂ ʲࣗಈԽԿͰ΋LTେձฤʳCircleCI ίϛϡχςΟϛʔτΞοϓ 2021/11/24