Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Terraform at Wantedly (Tech-Circle #12)
Search
Daisuke Fujita
January 29, 2016
Programming
2
760
Terraform at Wantedly (Tech-Circle #12)
Tech-Circle #12 Terraform Handson での LT 発表資料です
http://techcircle.connpass.com/event/25496/
Daisuke Fujita
January 29, 2016
Tweet
Share
More Decks by Daisuke Fujita
See All by Daisuke Fujita
SREcon19 Asia/Pacific Recap
dtan4
0
150
Our Practices of Delegating Ownership in Microservices World
dtan4
4
8.8k
Kubernetes Cluster Upgrade / Mercari Meetup for Microservices Platform
dtan4
3
4.5k
KubeCon EU 2018 Recap: Multi-Tenancy in Kubernetes: Best Practices Today, and Future Directions / Kubernetes Meetup Tokyo 11 #k8sjp
dtan4
1
1.8k
Wantedly から Chef を一掃した話 / #chibadan
dtan4
24
11k
さようなら Chef こんにちは Dockerfile / Web Tech Tokyo #1
dtan4
6
7k
Docker をフル活用したインフラの紹介と成長し続けるためのインフラ戦略 / #abejameetup
dtan4
19
3.9k
Docker Compose PaaS の作り方、そして社内に導入した話 / #yapc8oji
dtan4
1
8.2k
Writing Kubenetes tools in Go
dtan4
1
3.5k
Other Decks in Programming
See All in Programming
初めてDefinitelyTypedにPRを出した話
syumai
0
400
Webの技術スタックで マルチプラットフォームアプリ開発を可能にするElixirDesktopの紹介
thehaigo
2
1k
ヤプリ新卒SREの オンボーディング
masaki12
0
130
OSSで起業してもうすぐ10年 / Open Source Conference 2024 Shimane
furukawayasuto
0
100
C++でシェーダを書く
fadis
6
4.1k
タクシーアプリ『GO』のリアルタイムデータ分析基盤における機械学習サービスの活用
mot_techtalk
4
1.4k
Outline View in SwiftUI
1024jp
1
320
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
1
100
Ethereum_.pdf
nekomatu
0
460
Hotwire or React? ~アフタートーク・本編に含めなかった話~ / Hotwire or React? after talk
harunatsujita
1
120
CSC509 Lecture 12
javiergs
PRO
0
160
as(型アサーション)を書く前にできること
marokanatani
9
2.6k
Featured
See All Featured
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
250
21k
Designing on Purpose - Digital PM Summit 2013
jponch
115
7k
For a Future-Friendly Web
brad_frost
175
9.4k
Speed Design
sergeychernyshev
24
610
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
93
16k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
Become a Pro
speakerdeck
PRO
25
5k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
Teambox: Starting and Learning
jrom
133
8.8k
BBQ
matthewcrist
85
9.3k
Docker and Python
trallard
40
3.1k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
47
2.1k
Transcript
TERRAFORM at WANTEDLY 2016-01-29 Tech-Circle #12 Terraform Handson @dtan4
Daisuke Fujita @dtan4 Πϯλʔϯ @ΠϯϑϥνʔϜ
None
None
Terraform flow @ Wantedly since May 2015
Terraform Ͱཧ͍ͯ͠Δ 28 resource types aws_customer_gateway aws_db_instance aws_db_parameter_group aws_db_security_group aws_db_subnet_group
aws_elasticache_cluster aws_elasticache_subnet_group aws_elb aws_iam_group aws_iam_group_membership aws_iam_group_policy aws_iam_role aws_iam_role_policy aws_iam_user aws_iam_user_policy aws_instance aws_internet_gateway aws_network_acl aws_route_table aws_route_table_association aws_s3_bucket aws_security_group aws_subnet aws_vpc aws_vpn_connection aws_vpn_connection_route aws_vpn_gateway dnsimple_record
Terraform Ͱཧ͍ͯ͠Δ AWS 224 DNSimple 169 393 resources
Terraform ڥ GitHub wercker S3 remote backend Vagrant CoreOS Docker
quay.io/wantedly/terraform 3FNPUF -PDBM
Terraform flow Terraform ίʔυΛॻ͍ͯ Pull Request Λग़͢
Terraform flow Terraform ίʔυΛॻ͍ͯ Pull Request Λग़͢
Terraform flow CI Ͱςετ (terraform plan) ͕Δ
Terraform flow CI Ͱςετ (terraform plan) ͕Δ
Terraform flow ΠϯϑϥνʔϜ͕ϨϏϡʔͯ͠ Merge
Terraform flow CI Ͱ࣮ڥͷద༻ (terraform apply) ͕ߦΘΕΔ
e.g. DNS ϨίʔυՃ
e.g. IAM ϢʔβՃ ৽͍͠։ൃϝϯόʔͷ௨աّྱ
e.g. GitHub ্Ͱ֬ೝͰ͖ͯศར
Terraform ಋೖͷաఔ
ಋೖͨ͠ܦҢ • Management Console ϙνϙνۀ͔Βͷ٫ • ΠϯϑϥνʔϜͷ࡞ۀूத͔Βͷ٫ • ߏங࡞ۀͷཤྺΛ͍ͨ͠ •
ϦιʔεҰཡΛ ͩΕͰ؆୯ʹݟΒΕΔΑ͏ʹ͍ͨ͠ • ϦιʔεෳΛָʹ͍ͨ͠ • AWS ͱ DNSimple Ұॹʹѻ͑ͯศར
Ұ͔ΒΠϯϑϥߏஙϦϓϨʔεͰͳ͘ɺ ͍·ಈ͍͍ͯΔΠϯϑϥϦιʔε ΛίʔυԽ͍ͨ͠ resource "aws_instance" "app" { count = 4
ami = "ami-408c7f28" instance_type = "t1.micro" } resource "aws_instance" "app" { count = 4 ami = "ami-408c7f28" instance_type = "t1.micro" }
ݱߦڥͷ Terraform ಋೖ https://github.com/hashicorp/terraform/issues/581
ݱߦڥͷ Terraform ಋೖ https://github.com/hashicorp/terraform/issues/581 طଘϦιʔε͔Β Terraform ίʔυ Λੜ͢Δػೳ࣮͞Ε͍ͯͳ͍
ݱߦڥͷ Terraform ಋೖ ex: hoge ͱ͍͏ S3 bucket ͕͋ͬͨͱ͖ resource
"aws_s3_bucket" "hoge" { bucket = "hoge" acl = "private" } { "version": 1, "serial": 1, "modules": { "path": [ "root" ], "outputs": { }, "resources": { "aws_s3_bucket.hoge": { "type": "aws_s3_bucket", "primary": { "id": "hoge", "attributes": { "acl": "private", "bucket": "hoge", "id": "hoge" } } } } } } TUG UFSSBGPSNUGTUBUF
ݱߦڥͷ Terraform ಋೖ ex: hoge ͱ͍͏ S3 bucket ͕͋ͬͨͱ͖ resource
"aws_s3_bucket" "hoge" { bucket = "hoge" acl = "private" } { "version": 1, "serial": 1, "modules": { "path": [ "root" ], "outputs": { }, "resources": { "aws_s3_bucket.hoge": { "type": "aws_s3_bucket", "primary": { "id": "hoge", "attributes": { "acl": "private", "bucket": "hoge", "id": "hoge" } } } } } } TUG UFSSBGPSNUGTUBUF tfstate (JSON) ਓྗͰॻ͘ͷݫ͍͠
Export existing AWS resources to Terraform style (tf, tfstate) dtan4/terraforming
Terraforming • طଘͷ AWS / DNSimple Ϧιʔε͔Β Terraform ͷίʔυ (tf,
tfstate) Λੜ͢Δ ίϚϯυϥΠϯπʔϧ • 29छྨͷ AWS ϦιʔεʹରԠ • Wantedly ͷ Terraform ίʔυͷେΛੜ • Issue & Pull Request ͓·ͪͯ͠·͢ʂ dtan4/terraforming $ gem install terraforming # or $ docker pull quay.io/dtan4/terraforming
None
Terraforming • S3 buckets ͷ tf Λੜ • S3 buckets
ͷ tfstate Λੜ • S3 buckets ͷ tfstate Λੜ͠ɺ طଘͷ terraform.tfstate ͱϚʔδ $ terraforming s3 $ terraforming s3 --tfstate \ --merge=/path/to/terraform.tfstate $ terraforming s3 --tfstate dtan4/terraforming
http://qiita.com/dtan4/items/345c56281ab0e87d6646
ૺ۰ͨ͠
terraform plan ͕৴༻ग़དྷͳ͍ • HCL ͷγϯλοΫενΣοΫͱ Terraform ύϥϝʔλͷνΣοΫͷΈɺ API ͷ
dry-run ͠ͳ͍ • terraform plan ͕௨ͬͯɺύϥϝʔλ͕ AWS తʹෆਖ਼Ͱ terraform apply ʹࣦഊ͢Δ • CI Ͱʮςετʯ͍ͯ͠Δҙຯ͕…
terraform plan ͕৴༻ग़དྷͳ͍ • AWS ͷυΩϡϝϯτಡ·ͳ͍ͱ͍͚ͳ͍ • terraform apply ࣦഊͯ͠ϦΧόϦͰ͖Δ
ΈΛ࡞Δ • खݩͰ apply Ͱ͖Δڥ
ELB ԼͷΠϯελϯε͕ ҙਤͤͣஔ͖ΘΔ • Terraform ͷ ELB resource Δ͢ΠϯελϯεΛ໌ࣔతʹॻ͘ඞཁ͋Γ
• Wantedly ͰࣗલπʔϧͰ Πϯελϯεͷ૿ݮɺELB ͷΔ͠Λߦ͏ • Terraform ίʔυͱ࣮ࡍͷڥʹࠩҟ͕ग़Δ
ELB ԼͷΠϯελϯε͕ ҙਤͤͣஔ͖ΘΔ • සൟʹΠϯελϯε͕ஔ͖ΘΔ ELB Terraform Ͱཧ͠ͳ͍͜ͱʹͨ͠ •
֎෦Ͱಈతͳมߋ͕͋Γ͏ΔϦιʔε ͋͑ͯཧ͠ͳ͍ • Terraform v0.6.4 Ͱ ignore_changes ͕ಋೖ resource "aws_elb" "foo" { lifecycle { ignore_changes = ["instances"] } }
IAM ϢʔβআͰࣦഊ • IAM ϢʔβࣗମΛফ͢લʹΫϨσϯγϟϧ ϩάΠϯϓϩϑΝΠϧΛফ͢ඞཁ͕͋Δ • Terraform ͦΜͳͷ͓ߏ͍ͳ͠ʹ delete-user
͠Α͏ͱ͢Δ • खಈͰґଘϦιʔεΛফ্ͨ͠Ͱ apply http://docs.aws.amazon.com/ja_jp/IAM/latest/UserGuide/Using_DeletingUserFromAccount.html
·ͱΊ
·ͱΊ • Wantedly ͷΠϯϑϥ Terraform Ͱཧ͞Ε͍ͯ·͢ʂ • ݱߦΠϯϑϥΛ Terraform Ͱཧ͢ΔͨΊʹ
Terraforming ͱ͍͏πʔϧΛ։ൃ͠·ͨ͠ • ͯ͢Λ Terraform ʹ͖ͤͬΓʹ͠ͳ͍