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

TerraformとCloudFormationどちらを採用すべき?

 TerraformとCloudFormationどちらを採用すべき?

AKIBA.AWS ONLINE #03 -IaC を語りたい 編-
での登壇資料

Fukazawa Shun

May 19, 2021
Tweet

More Decks by Fukazawa Shun

Other Decks in Programming

Transcript

  1. 7 $MPVEGPSNBUJPOʹ͍ͭͯ • "84͕ఏڙ • :BNM͔KTPOͰهड़ • "84্Ͱ࣮ߦ • *".ϩʔϧΛ࢖༻ͨ͠ηΩϡΞͳೝূ

    Ec2Instance: Type: AWS::EC2::Instance Properties: ImageId: Fn::FindInMap: - "RegionMap" - Ref: "AWS::Region" - "AMI"
  2. 8 5FSSBGPSNʹ͍ͭͯ • )BTIJ$PSQ͕ఏڙ • )$-Ͱهड़ • ϩʔΧϧ1$౳ͷϚγϯ্Ͱ࣮ߦ • Ωʔͷ؅ཧΛݕ౼͢Δඞཁ͕͋Δ

    • &$౳ͷ"84αʔϏε্Ͱͷ࣮ߦ΍εΠονϩʔϧ౳ ͰηΩϡΞͳೝূ͕Մೳ resource "aws_instance" "web" { ami = data.aws_ami.ubuntu.id instance_type = "t3.micro" tags = { Name = "HelloWorld" } }
  3. 12 ҟͳΔϦʔδϣϯ΁ͷσϓϩΠ • ҟͳΔ1SPWJEFSΛ༻͍Δ IUUQTXXXUFSSBGPSNJPEPDTQSPWJEFSTJOEFYIUNM Region Region Region Provider A

    Provider B Provider C provider aws { region = "ap-northeast-1” } provider aws { region = "us-east-1" alias = "use1" } resource "aws_instance" "web" { 〜〜〜 } resource "aws_instance" "web_use1" { provider = aws.use1 〜〜〜 }
  4. 23 ϩδοΫ • $MPVEGPSNBUJPOͷ৔߹ • $POEJUJPOTηΫγϣϯΛ࢖༻͢Δ • ࢖༻Մೳͳؔ਺ • 'O"OE

    • 'O&RVBMT • 'O*G • 'O/PU • 'O0S Description: "Template.” Parameters: EnvType: Type: String AllowedValues: - prod - test Conditions: CreateProdResources: !Equals - !Ref EnvType - prod Resources: 〜〜〜 Outputs: 〜〜〜
  5. 24 ϩδοΫ • 5FSSBGPSNͷ৔߹ • ߏ଄ମΛ༻͍ͨ܁Γฦ͠ॲཧ • ࡾ߲ԋࢉࢠ • ૊ΈࠐΈؔ਺

    • ͍ΘΏΔϓϩάϥϜݴޠʹ ͍ۙهड़ • ෼ذॲཧ͸ͳ͍ dynamic "origin_group" { for_each = var.load_balancer_origin_groups content { name = origin_group.key dynamic "origin" { for_each = origin_group.value.origins content { hostname = origin.value.hostname } } } } variable "load_balancer_origin_groups" { type = map(object({ origins = set(object({ hostname = string })) })) }
  6. 28 ഉଞ੍ޚ • 5FSSBGPSNͷ৔߹ • 4UBUFΛͲ͜ʹஔ͘ͷ͔ʹΑͬͯҟͳΔ • IUUQTXXXUFSSBGPSNJPEPDTMBOHVBHFTFUUJOHTCBDLFOETJOEF YIUNM •

    %ZOBNP%#MPDLΛ༻͍Δ͜ͱ͕Ͱ͖Ε͹ഉଞ੍ޚՄೳ • IUUQTXXXUFSSBGPSNJPEPDTMBOHVBHFTUBUFMPDLJOHIUNM
  7. 32 όʔδϣϯ؅ཧ • 5FSSBGPSNͷ৔߹ • 5FSSBGPSNͦͷ΋ͷͱ1SPWJEFSͷόʔδϣϯΛ؅ཧ͢Δ • 5FSSBGPSNͷόʔδϣϯ͸UGFOWͰ؅ཧ • IUUQTHJUIVCDPNUGVUJMTUGFOW

    • 1SPWJEFS͸SFRVJSFE@QSPWJEFSTͰࢦఆ • ࠷ۙ͸UFSSBGPSNMPDLIDMͱ͍͏QSPWJEFSͷMPDLϑΝΠϧ΋ొ৔ • IUUQTXXXUFSSBGPSNJPEPDTMBOHVBHFQSPWJEFSTSFRVJSFNFOUTIUNM • ͍ΘΏΔϓϩάϥϛϯάݴޠͷόʔδϣϯ؅ཧʹ͍ۙ
  8. 35 ։ൃπʔϧ • $MPVEGPSNBUJPO • $GOMJOU • IUUQTBXTBNB[PODPNKQCMPHTOFXTHJUQSFDPNNJUWBMJEBUJPOPGBXT DMPVEGPSNBUJPOUFNQMBUFTXJUIDGOMJOU •

    ҎԼͷΑ͏ͳνΣοΫΛࣗಈͰͯ͘͠ΕΔ • ਖ਼͍͠ܗࣜʢ:BNM PS+TPOʣͰॻ͚͍ͯΔ͔ • όά͸ͳ͍͔ʢଘࡏ͠ͳ͍ม਺ࢀরɺฦΓ஋ͷظ଴ʣ • ଞͷ࣮૷ํ๏ͷఏҊʢϋʔυίʔυͷճආʣ • *%&ʢ74$PEFʣͷϓϥάΠϯ΋͋Δ • IUUQTHJUIVCDPNBXTTDSJQUJOHHVZDGPSN74$PEF
  9. 36 ։ൃπʔϧ • 5FSSBGPSN • ίϚϯυΦϓγϣϯʹࣗಈิਖ਼ػೳ͕͋Δ • IUUQTXXXUFSSBGPSNJPEPDTDMJDPNNBOETGNUIUNM • อଘ࣌ʹ͜ͷίϚϯυΛ࣮ߦ͢Ε͹ࣗಈͰߏจमਖ਼

    • -JOUFSπʔϧ΋ଘࡏ • IUUQTHJUIVCDPNUFSSBGPSNMJOUFSTUGMJOU • ίʔυ͕ηΩϡϦςΟతʹ໰୊ͳ͍͔ΛνΣοΫ͢Δπʔϧ΋ • ྫɿηΩϡϦςΟάϧʔϓ͕શ։Ͱઃఆ͞Ε͍ͯΔ • IUUQTHJUIVCDPNUGTFDUGTFD • *%&ͷϓϥάΠϯ΋͋Δ • 74$PEF 1Z$IBSN $ terraform fmt
  10. 38 ·ͱΊ • $MPVEGPSNBUJPO • ෳࡶͳॲཧͷهड़͸೉͍͠ • ͋·Γෳࡶʹͯ͠͠·͏ͱݟʹ͘͘ͳΔ͜ͱ΋ • "84ͱͷ਌࿨ੑ͕ߴ͘ɺؔ࿈αʔϏε΋ଟ͍

    • ҟͳΔϦʔδϣϯ΁ͷσϓϩΠɺ؀ڥͱͷဃ཭ݕग़౳ • 5FSSBGPSN • ಉ͡ߏจͰҧ͏*BB4ʹσϓϩΠͰ͖Δ • 1SPWJEFS͕੾Γସ͑ΒΕΔނͷϝϦοτ • ߏจ΍όʔδϣϯ؅ཧ͕ϓϩάϥϛϯάݴޠʹ͍ۙ • ϓϩάϥϜܦݧͷ͋Δํ͸ೃછΈ΍͍͔͢΋