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

TerraformではじめるInfrastructure as Code

B1d4a2fa199a71b2f40485d99feca3cb?s=47 Yusuke Yasuo
October 18, 2018
650

TerraformではじめるInfrastructure as Code

「JAWS-UG 初心者支部#14」のLT資料です。

B1d4a2fa199a71b2f40485d99feca3cb?s=128

Yusuke Yasuo

October 18, 2018
Tweet

Transcript

  1. TERRAFORMͰ͸͡ΊΔ INFRASTRACTURE AS CODE yusukeyasuo@redish

  2. ର৅ • ඇΠϯϑϥΤϯδχΞͰɺΠϯϑϥͷߏஙɾӡ༻΋͠ͳ͖Ό͍ ͚ͳ͘ͳͬͨΤϯδχΞ • ·ͩInfrastructure as CodeΛ͍ͯ͠ͳ͍ΠϯϑϥΤϯδχΞ • தʙ্ڃऀ޲͚Ͱ͸ͳ͍Ͱ͢m(__)m

  3. AGENDA • ࣗݾ঺հ • Infrastructure as Codeͱ͸ • Terraformͱ͸ •

    ࣮ྫ • ·ͱΊ
  4. ࣗݾ঺հ • Yusuke Yasuo • ϦʔυΤϯδχΞ@redishגࣜձࣾ • NTT→ίϩϓϥ→ελʔτΞοϓΛ਺ࣾ • ελʔτΞοϓͰΤϯδχΞ1ʙ2ਓͷ࣌

    ظ͕͋ΓɺAWSΛ৮ΔΑ͏ʹͳͬͨ
  5. INFRASTRUCTURE AS CODEͱ͸ • ίʔυʹΑΔΠϯϑϥߏ੒؅ཧ

  6. ͳͥίʔυ؅ཧ͕ඞཁ͔ʁ • खಈͰ؅ཧ͢Δͱେม͔ͩΒ

  7. ๻͕ܦݧͨ͠खಈ؅ཧͷฐ֐ • υΩϡϝϯτɺखॱॻ͕ͳ͍ͷͰͲ͏΍ͬͯߏங͔ͨ͠୲౰ ऀʹฉ͔ͳ͍ͱ෼͔Βͳ͍ • ୲౰ऀʹฉ͍ͯ΋ߏங࣌ͷهԱ͕ͳͯ͘෼͔Βͳ͍ • ো֐͕ൃੜͨ͠ࡍʹ෮چͰ͖ͳ͍ • ప໷Ͱθϩ͔Βߏங͢Δ

    • ୀ৬ޙ΋ো֐͕ൃੜ͢Δͱݺͼग़͞ΕΔ
  8. ίʔυԽ͓͚ͯ͠͹ • Πϯϑϥͷઃఆ͕୭Ͱ΋෼͔ΔʢϒϥοΫϘοΫεԽ͠ ͳ͍ʣ • ো֐͕ൃੜͯ͠΋ίϚϯυҰͭͰ͙͢ʹ෮چ͕Մೳ • ࡞ۀϛε΋ى͜Βͳ͍ • ΠϯϑϥΤϯδχΞ͕͍ͳͯ͘΋؅ཧͰ͖Δ

  9. ओͳπʔϧ

  10. TERRAFORMͱ͸ • ΠϯϑϥετϥΫνϟఆٛπʔϧ • VagrantͳͲ։ൃ͍ͯ͠ΔHashiCorp͕ࣾ։ൃݩ • Πϯϑϥͷߏ੒ΛએݴతʹఆٛͰ͖Δ
 ※खଓ͖తʹॻ͔ͳͯ͘ྑ͍

  11. Πϯετʔϧ • ϏϧυࡁΈόΠφϦΛμ΢ϯϩʔυͯ͠ύεΛ௨͚ͩ͢

  12. ࣄલ४උ • IAMϢʔβʔͷ࡞੒ • AWS CLIΛར༻͢ΔͨΊͷIAMϢʔβʔΛ࡞੒͠ɺΞΫηεΩʔΛऔಘ͢Δ • AWS CLIͷηοτΞοϓ •

    $ aws configure Ͱೝূ৘ใΛηοτ͢Δ
 ※ ~/.aws/credentials ʹೝূ৘ใ͕อଘ͞Ε͍ͯΕ͹OK • terraformͷॳظԽ • $ terraform init
  13. RDSΛ࡞੒͢Δྫ

  14. ఆٛϑΝΠϧͷ࡞੒ provider "aws" { region = "ap-northeast-1" } resource "aws_db_instance"

    "default" { allocated_storage = 10 storage_type = "gp2" engine = "mysql" engine_version = "5.7" instance_class = "db.t2.micro" name = "mydb" username = "foo" password = "foobarbaz" parameter_group_name = "default.mysql5.7" } rds.tf
  15. ಺༰ͷνΣοΫ • $ terraform plan

  16. RDSͷ࡞੒ • $ terraform apply

  17. ࡞੒ͨ͠ΦϒδΣΫτͷ֬ೝ • $ terraform show

  18. ஫ҙ͢Δ͜ͱ • TerraformͰ࡞੒ͨ͠ΦϒδΣΫτΛखಈͰมߋ͠ͳ͍ • ෳ਺ਓͰ࡞ۀ͢Δ৔߹͸tfstateͷ؅ཧʹؾΛ͚ͭΑ͏

  19. ·ͱΊ • ϓϩμΫγϣϯ༻ͷΠϯϑϥ͸ඞͣίʔυԽ͠·͠ΐ͏ • ίʔυԽ͠ͳ͍΋ͷ͸ϦϦʔε͠ͳ͍ • redishͰҰॹʹInfrastructure as Code͠·͠ΐ͏w