Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Ntau tus neeg paub thiab siv Terraform hauv lawv txoj haujlwm niaj hnub, tab sis kev coj ua zoo tshaj plaws rau nws tseem tsis tau tsim. Txhua pab pawg yuav tsum tau tsim nws tus kheej txoj hauv kev thiab cov txheej txheem.

Koj qhov kev tsim kho vaj tse yuav luag pib yooj yim: ob peb cov peev txheej + ob peb tus tsim tawm. Nyob rau tib lub sijhawm, nws loj hlob nyob rau hauv txhua hom kev qhia. Koj puas pom txoj hauv kev los pab pawg cov peev txheej rau hauv Terraform modules, teeb tsa cov cai rau hauv folders, thiab dab tsi ntxiv tuaj yeem ua yuam kev? (npe lus kawg)

Lub sij hawm dhau mus thiab koj xav tias zoo li koj lub vaj tse yog koj tus tsiaj tshiab, tab sis vim li cas? Koj txhawj xeeb txog kev hloov pauv tsis txaus ntseeg hauv kev tsim kho vaj tse, koj ntshai kov cov txheej txheem thiab cov cai - vim li ntawd, koj ncua kev ua haujlwm tshiab lossis txo qhov zoo ...

Tom qab peb xyoos ntawm kev tswj hwm kev sau ntawm Terraform zej zog modules rau AWS ntawm Github thiab kev saib xyuas mus sij hawm ntev ntawm Terraform hauv kev tsim khoom, Anton Babenko tau npaj los qhia nws cov kev paub: yuav ua li cas sau TF modules kom tsis txhob mob yav tom ntej.

Thaum kawg ntawm kev sib tham, cov neeg tuaj koom yuav paub ntau ntxiv txog kev tswj hwm cov txheej txheem hauv Terraform, cov kev coj ua zoo tshaj plaws cuam tshuam nrog cov qauv hauv Terraform, thiab qee qhov kev sib koom ua ke txuas ntxiv cuam tshuam nrog kev tswj hwm vaj tse.

Disclaimer: Kuv nco ntsoov tias daim ntawv tshaj tawm no yog hnub tim Kaum Ib Hlis 2018-2 xyoo dhau los lawm. Lub version ntawm Terraform 0.11 tau tham hauv tsab ntawv ceeb toom tsis tau txais kev txhawb nqa lawm. Hauv 2 xyoo dhau los, 2 qhov kev tshaj tawm tshiab tau tshaj tawm, uas muaj ntau yam kev tsim kho tshiab, kev txhim kho thiab kev hloov pauv. Thov xyuam xim rau qhov no thiab xyuas cov ntaub ntawv.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Links:

Kuv lub npe yog Anton Babenko. Ib txhia ntawm koj tej zaum siv cov cai kuv sau. Tam sim no kuv yuav hais txog qhov no nrog kev ntseeg siab ntau dua li yav dhau los, vim kuv muaj kev nkag mus rau kev txheeb cais.

Kuv ua haujlwm ntawm Terraform thiab tau yog ib tus neeg koom tes thiab pab txhawb rau ntau qhov qhib qhov project ntsig txog Terraform thiab Amazon txij li xyoo 2015.

Txij thaum ntawd los kuv tau sau cov lej txaus los tso rau hauv txoj kev nthuav dav. Thiab kuv yuav sim qhia koj txog qhov no tam sim no.

Kuv yuav tham txog cov intricacies thiab tshwj xeeb ntawm kev ua hauj lwm nrog Terraform. Tab sis qhov ntawd tsis yog qhov tseem ceeb ntawm HighLoad. Thiab tam sim no koj yuav to taub yog vim li cas.

Thaum lub sij hawm, kuv pib sau Terraform modules. Cov neeg siv sau cov lus nug, Kuv rov sau lawv dua. Tom qab ntawd kuv tau sau ntau yam khoom siv los tsim cov lej siv kev sib txuas ua ntej, thiab lwm yam.

Muaj ntau yam haujlwm nthuav. Kuv nyiam cov cim cim vim tias kuv nyiam lub computer ua haujlwm ntau dua rau kuv thiab tus programmer, yog li tam sim no kuv tab tom ua haujlwm ntawm Terraform code generator los ntawm cov duab kos duab. Tej zaum nej ib txhia twb pom lawm. Cov no yog cov thawv zoo nkauj nrog cov xub. Thiab kuv xav tias nws zoo heev yog tias koj tuaj yeem nyem lub pob "Export" thiab tau txais tag nrho raws li cov cai.

Kuv tuaj ntawm Ukraine. Kuv tau nyob hauv Norway tau ntau xyoo.

Tsis tas li ntawd, cov ntaub ntawv rau daim ntawv tshaj tawm no tau sau los ntawm cov neeg uas paub kuv lub npe thiab nrhiav kuv hauv social networks. Kuv yuav luag ib txwm muaj tib lub npe menyuam yaus.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

https://github.com/terraform-aws-modules
https://registry.terraform.io/namespaces/terraform-aws-modules

Raws li kuv tau hais, Kuv yog tus tswj hwm tseem ceeb ntawm Terraform AWS modules, uas yog ib qho ntawm cov chaw khaws khoom loj tshaj plaws ntawm GitHub qhov twg peb tuav cov modules rau feem ntau cov dej num: VPC, Autoscaling, RDS.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Thiab qhov koj tau hnov ​​tam sim no yog qhov yooj yim tshaj plaws. Yog tias koj tsis ntseeg tias koj nkag siab tias Terraform yog dab tsi, ces nws yog qhov zoo dua los siv koj lub sijhawm rau lwm qhov. Yuav muaj ntau cov ntsiab lus technical ntawm no. Thiab kuv tsis tau ua siab deb tshaj tawm cov theem ntawm tsab ntawv ceeb toom kom siab tshaj. Qhov no txhais tau hais tias kuv tuaj yeem tham siv tag nrho cov ntsiab lus tau yam tsis muaj kev piav qhia ntau.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Terraform tau tshwm sim hauv xyoo 2014 ua qhov khoom siv uas tso cai rau koj sau, npaj thiab tswj cov txheej txheem raws li cov cai. Lub tswv yim tseem ceeb ntawm no yog "infrastructure li code."

Tag nrho cov ntaub ntawv, raws li kuv hais, yog sau rau hauv terraform.io. Kuv vam tias cov neeg feem coob paub txog qhov chaw no thiab tau nyeem cov ntaub ntawv. Yog hais tias yog, ces koj nyob rau hauv qhov chaw.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Qhov no yog dab tsi ib txwm Terraform configuration file zoo li, qhov twg peb thawj zaug txhais qee qhov sib txawv.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Hauv qhov no peb txhais "aws_region".

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Tom qab ntawd peb piav qhia txog cov peev txheej uas peb xav tsim.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Peb khiav qee cov lus txib, tshwj xeeb "terraform init" txhawm rau txhawm rau thauj khoom thiab cov chaw muab kev pabcuam.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Thiab peb khiav "terraform thov" hais kom ua txhawm rau txheeb xyuas seb qhov kev teeb tsa tau teev tseg puas phim cov peev txheej uas peb tsim. Txij li thaum peb tsis tau tsim ib yam dab tsi ua ntej, Terraform qhia peb los tsim cov peev txheej no.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Peb lees paub qhov no. Yog li peb tsim ib lub thoob hu ua seasnail.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Kuj tseem muaj ntau yam khoom siv zoo sib xws. Ntau tus ntawm koj uas siv Amazon paub AWS CloudFormation lossis Google Cloud Deployment Manager lossis Azure Resource Manager. Txhua tus ntawm lawv muaj nws tus kheej siv qee yam rau kev tswj cov peev txheej hauv txhua tus neeg muab kev pabcuam huab cua. Terraform muaj txiaj ntsig tshwj xeeb vim nws tso cai rau koj los tswj ntau dua 100 tus kws kho mob. (Ntau yam ntxiv S, SΡ“S,)

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Cov hom phiaj uas Terraform tau caum los ntawm qhov pib:

  • Terraform muab ib qho kev pom ntawm cov peev txheej.
  • Tso cai rau koj los txhawb txhua lub platform niaj hnub.
  • Thiab Terraform tau tsim los ntawm qhov pib ua qhov kev siv hluav taws xob uas tso cai rau koj los hloov cov txheej txheem kev nyab xeeb thiab kwv yees.

Nyob rau hauv 2014, lo lus "predictable" sounded heev txawv txawv nyob rau hauv cov ntsiab lus no.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Terraform yog ib qho khoom siv universal. Yog tias koj muaj API, koj tuaj yeem tswj tau txhua yam:

  • Koj tuaj yeem siv ntau dua 120 tus kws kho mob los tswj txhua yam koj xav tau.
  • Piv txwv li, koj tuaj yeem siv Terraform los piav txog kev nkag mus rau GitHub repositories.
  • Koj tuaj yeem tsim thiab kaw cov kab hauv Jira.
  • Koj tuaj yeem tswj hwm New Relic metrics.
  • Koj tuaj yeem tsim cov ntaub ntawv hauv dropbox yog tias koj xav tau tiag tiag.

Qhov no yog txhua yam ua tiav siv Terraform cov chaw muab kev pabcuam, uas muaj qhov qhib API uas tuaj yeem piav qhia hauv Go.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Cia peb hais tias peb pib siv Terraform, nyeem qee cov ntaub ntawv ntawm lub xaib, saib qee cov vis dis aus, thiab pib sau main.tf, raws li kuv tau pom ntawm cov slides dhau los.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Thiab txhua yam zoo heev, koj muaj cov ntaub ntawv tsim VPC.

Yog tias koj xav tsim VPC, ces koj qhia kwv yees li ntawm 12 kab no. Piav txog thaj tsam twg koj xav tsim, uas cidr_block ntawm IP chaw nyob siv. Yog tag nrho.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Lawm, qhov project yuav maj mam loj hlob.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Thiab koj yuav tau ntxiv ib pawg ntawm cov khoom tshiab muaj: cov peev txheej, cov ntaub ntawv, koj yuav koom nrog cov chaw muab kev pabcuam tshiab, mam li nco dheev koj yuav xav siv Terraform los tswj cov neeg siv hauv koj tus lej GitHub, thiab lwm yam. Koj yuav xav siv ntau yam. Cov chaw muab DNS, hla txhua yam. Terraform ua qhov no yooj yim.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Cia peb saib cov piv txwv hauv qab no.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Koj maj mam ntxiv internet_gateway vim koj xav tau cov peev txheej los ntawm koj VPC kom muaj internet nkag. Qhov no yog ib lub tswv yim zoo.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Qhov tshwm sim yog qhov main.tf:

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Qhov no yog qhov saum toj kawg nkaus ntawm main.tf.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Nov yog qhov hauv qab ntawm main.tf.

Tom qab ntawd koj ntxiv subnet. Thaum lub sij hawm koj xav ntxiv NAT rooj vag, txoj kev, routing rooj thiab ib pawg ntawm lwm cov subnets, koj yuav tsis muaj 38 kab, tab sis kwv yees li 200-300 kab.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Ntawd yog, koj cov ntaub ntawv main.tf maj mam loj tuaj. Thiab feem ntau cov neeg muab txhua yam hauv ib daim ntawv. 10-20 Kb tshwm hauv main.tf. Xav txog tias 10-20 Kb yog cov ntawv nyeem. Thiab txhua yam txuas nrog txhua yam. Qhov no maj mam dhau los ua nyuaj ua haujlwm nrog. 10-20 Kb yog cov neeg siv khoom zoo, qee zaum ntau dua. Thiab tib neeg yeej tsis xav tias qhov no yog qhov phem.

Raws li nyob rau hauv niaj hnub programming, piv txwv li tsis infrastructure raws li cov cai, peb tau siv los siv ib pawg ntawm cov chav kawm sib txawv, pob khoom, modules, pawg. Terraform tso cai rau koj ua ntau yam tib yam.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

  • Txoj cai loj hlob.
  • Dependencies ntawm cov peev txheej kuj loj tuaj.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Thiab peb muaj kev xav tau zoo heev. Peb nkag siab tias peb tsis tuaj yeem ua neej zoo li no ntxiv lawm. Peb cov cai tau dhau los ua qhov loj heev. 10-20 Kb yog, ntawm chav kawm, tsis loj heev, tab sis peb tab tom tham nkaus xwb txog pawg network, piv txwv li koj tsuas muaj peev txheej ntxiv network. Peb tsis tau tham txog Daim Ntawv Thov Load Balancer, xa tawm ES pawg, Kubernetes, thiab lwm yam, qhov twg 100 Kb tuaj yeem yooj yim weaved hauv. Yog tias koj sau tag nrho cov no, koj yuav kawm sai sai tias Terraform muab Terraform modules.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Terraform modules yog tus kheej-muaj Terraform configuration uas yog tswj raws li ib pawg. Qhov ntawd yog txhua yam koj yuav tsum paub txog Terraform modules. Lawv tsis ntse kiag li, lawv tsis tso cai rau koj ua tej yam kev sib txuas nyob ntawm seb ib yam dab tsi. Qhov no tag nrho ntog ntawm lub xub pwg nyom ntawm developers. Ntawd yog, qhov no tsuas yog qee yam ntawm Terraform configuration uas koj tau sau lawm. Thiab koj tuaj yeem hu nws ua ib pab pawg.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Yog li peb tab tom sim nkag siab yuav ua li cas peb yuav ua kom zoo dua peb 10-20-30 Kb ntawm code. Peb maj mam paub tias peb yuav tsum siv qee qhov modules.

Thawj hom modules koj ntsib yog cov peev txheej modules. Lawv tsis nkag siab tias koj qhov kev tsim kho vaj tse yog dab tsi, koj lub lag luam yog dab tsi, qhov twg thiab cov xwm txheej yog dab tsi. Cov no yog cov qauv uas kuv, ua ke nrog qhib qhov chaw hauv zej zog, tswj hwm, thiab uas peb muab tso rau pem hauv ntej raws li thawj lub tsev thaiv rau koj cov infrastructure.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Ib qho piv txwv ntawm cov peev txheej module.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Thaum peb hu rau ib qho kev pab cuam module, peb qhia los ntawm txoj kev twg peb yuav tsum thauj nws cov ntsiab lus.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Peb qhia qhov twg version peb xav mus download tau.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Peb dhau ib pawg ntawm kev sib cav muaj. Yog tag nrho. Qhov ntawd yog txhua yam peb yuav tsum paub thaum peb siv qhov module no.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Ntau tus neeg xav tias yog lawv siv qhov tseeb version, txhua yam yuav ruaj khov. Tab sis tsis muaj. Cov kev tsim kho vaj tse yuav tsum tau hloov kho; peb yuav tsum tau teb kom meej tias qhov twg version no lossis cov khoom siv tau raug xa mus rau.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Ntawm no yog cov code uas nyob rau hauv no module. Kev ruaj ntseg-pab pawg module. Ntawm no tus scroll mus rau 640th kab. Tsim kom muaj kev ruaj ntseg-croup peev txheej hauv Amazon hauv txhua qhov kev teeb tsa ua tau yog ib txoj haujlwm tsis tseem ceeb. Nws tsis txaus los tsuas yog tsim ib pab pawg neeg ruaj ntseg thiab qhia nws tias cov cai dab tsi yuav dhau mus rau nws. Nws yuav yooj yim heev. Muaj ntau lab qhov kev txwv sib txawv hauv Amazon. Piv txwv li, yog tias koj siv VPC endpoint, prefix list, ntau APIs thiab sim muab tag nrho cov no nrog txhua yam, ces Terraform tsis tso cai rau koj ua qhov no. Thiab Amazon API tsis tso cai rau qhov no thiab. Yog li ntawd, peb yuav tsum tau mus nkaum tag nrho cov txaus ntshai logic nyob rau hauv ib tug module thiab muab tus neeg siv code uas zoo li no.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Tus neeg siv tsis tas yuav paub yuav ua li cas nws ua hauv.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Qhov thib ob hom modules, uas muaj cov khoom siv modules, twb daws tau cov teeb meem uas muaj feem xyuam rau koj lub lag luam. Feem ntau qhov no yog qhov chaw uas yog qhov txuas ntxiv rau Terraform thiab teeb tsa qee qhov tseem ceeb rau cov cim npe, rau cov qauv hauv tuam txhab. Koj tuaj yeem ntxiv kev ua haujlwm nyob rau ntawd uas Terraform tsis tam sim no tso cai rau koj siv. Qhov no yog tam sim no. Tam sim no version 0.11, uas yog yuav dhau los ua ib yam ntawm yav dhau los. Tab sis tseem, preprocessors, jsonnet, cookiecutter thiab ib pawg ntawm lwm yam yog lub koom haum pab mechanism uas yuav tsum tau siv rau tag nrho-fledged ua hauj lwm.

Tom ntej no kuv yuav qhia qee qhov piv txwv ntawm qhov no.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Lub infrastructure module hu ua raws nraim tib txoj kev.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Lub hauv paus los ntawm qhov chaw rub tawm cov ntsiab lus tau qhia.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Ib pawg ntawm cov txiaj ntsig tau dhau mus thiab dhau mus rau hauv qhov module no.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Tom ntej no, hauv cov qauv no, ib pawg ntawm cov peev txheej tau raug hu los tsim VPC lossis Daim Ntawv Thov Load Balancer, lossis tsim kom muaj kev ruaj ntseg-pab pawg lossis rau Elastic Container Service pawg.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Muaj ob hom modules. Qhov no yog qhov tseem ceeb kom nkag siab vim tias feem ntau ntawm cov ntaub ntawv kuv tau muab tso rau hauv daim ntawv qhia no tsis tau sau rau hauv cov ntaub ntawv.

Thiab cov ntaub ntawv hauv Terraform tam sim no muaj teeb meem heev vim nws tsuas yog hais tias muaj cov yam ntxwv no, koj tuaj yeem siv lawv. Tab sis nws tsis tau hais tias yuav siv cov yam ntxwv no li cas, vim li cas nws thiaj zoo dua siv lawv. Yog li ntawd, coob tus neeg sau tej yam uas lawv tsis tuaj yeem nyob nrog.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Cia wb mus saib yuav ua li cas sau cov modules tom ntej. Tom qab ntawd peb yuav pom yuav ua li cas hu rau lawv thiab yuav ua li cas ua haujlwm nrog tus lej.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Terraform Registry - https://registry.terraform.io/

Tswv yim #0 yog kom tsis txhob sau cov peev txheej modules. Feem ntau ntawm cov modules twb tau sau rau koj. Raws li kuv tau hais, lawv yog qhov qhib, lawv tsis muaj ib qho ntawm koj lub lag luam logic, lawv tsis muaj hardcoded qhov tseem ceeb rau IP chaw nyob, passwords, thiab lwm yam. Lub module yog hloov tau yooj yim. Thiab nws muaj feem ntau yuav tau sau. Muaj ntau lub modules rau cov peev txheej los ntawm Amazon. Txog 650. Thiab feem ntau ntawm lawv yog cov khoom zoo.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Hauv qhov piv txwv no, ib tug neeg tuaj rau koj thiab hais tias, "Kuv xav kom muaj peev xwm tswj hwm cov ntaub ntawv. Tsim ib lub module kom kuv tuaj yeem tsim cov ntaub ntawv. " Tus neeg tsis paub txog kev siv cov ntsiab lus ntawm Amazon lossis Terraform. Nws tsuas hais tias: "Kuv xav tswj MSSQL." Ntawd yog, peb txhais tau tias nws yuav hu rau peb lub module, dhau lub cav hom nyob ntawd, thiab qhia txog lub sijhawm.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Thiab ib tug neeg yuav tsum tsis txhob paub tias peb yuav tsim ob qho kev sib txawv hauv cov qauv no: ib qho rau MSSQL, qhov thib ob rau txhua yam, tsuas yog vim nyob rau hauv Terraform 0.11 koj tsis tuaj yeem hais meej lub sijhawm thaj tsam qhov tseem ceeb raws li kev xaiv.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Thiab ntawm qhov tawm ntawm qhov module no, ib tug neeg yuav tuaj yeem tau txais qhov chaw nyob. Nws yuav tsis paub los ntawm cov ntaub ntawv twg, los ntawm cov peev txheej twg peb tab tom tsim tag nrho cov no sab hauv. Qhov no yog ib qho tseem ceeb heev ntawm kev zais. Thiab qhov no siv tsis tau rau cov modules uas yog pej xeem nyob rau hauv qhib qhov chaw, tab sis kuj rau cov modules uas koj yuav sau nyob rau hauv koj tej yaam num thiab pab pawg.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Qhov no yog qhov kev sib cav thib ob, uas tseem ceeb heev yog tias koj tau siv Terraform ib ntus. Koj muaj lub chaw cia khoom uas koj tso tag nrho koj cov Terraform modules rau koj lub tuam txhab. Thiab nws yog qhov qub heev uas dhau sij hawm qhov project no yuav loj hlob mus rau qhov loj ntawm ib lossis ob megabytes. Qhov no zoo.

Tab sis qhov teeb meem yog li cas Terraform hu cov modules. Piv txwv li, yog tias koj hu rau ib qho module los tsim txhua tus neeg siv, Terraform yuav xub thauj khoom tag nrho cov chaw cia khoom thiab tom qab ntawd mus rau lub nplaub tshev qhov twg cov module tshwj xeeb nyob. Txoj kev no koj yuav rub tawm ib megabyte txhua zaus. Yog tias koj tswj hwm 100 lossis 200 tus neeg siv, ces koj yuav rub tawm 100 lossis 200 megabytes, thiab tom qab ntawd mus rau qhov ntawd. Yog li ib txwm koj tsis xav rub tawm ib pawg ntawm cov khoom txhua zaus koj ntaus "Terraform init".

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

https://github.com/mbtproject/mbt

Muaj ob txoj hauv kev rau qhov teeb meem no. Thawj yog siv txoj kev txheeb ze. Txoj kev no koj qhia hauv cov cai uas lub nplaub tshev hauv zos (./). Thiab ua ntej koj tso dab tsi, koj ua Git clone ntawm qhov chaw cia khoom hauv zos. Txoj kev no koj ua ib zaug.

Muaj, ntawm chav kawm, ntau downsides. Piv txwv li, koj siv tsis tau versioning. Thiab qhov no yog qee zaum nyuaj rau kev ua neej nrog.

Qhov thib ob daws. Yog tias koj muaj ntau submodules thiab koj twb muaj qee yam kev tsim cov kav dej, ces muaj qhov project MBT, uas tso cai rau koj los sau ntau cov pob ntawv sib txawv los ntawm monorepository thiab xa mus rau S3. Qhov no yog ib txoj kev zoo heev. Yog li, cov ntaub ntawv iam-user-1.0.0.zip yuav hnyav tsuas yog 1 Kb, vim tias cov cai los tsim cov peev txheej no tsawg heev. Thiab nws yuav ua haujlwm sai dua.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Cia peb tham txog dab tsi yuav siv tsis tau hauv modules.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Vim li cas qhov kev phem no nyob rau hauv modules? Qhov phem tshaj yog xav tias tus neeg siv. Xav tias tus neeg siv yog tus muab kev lees paub qhov kev xaiv uas tuaj yeem siv los ntawm cov neeg sib txawv. Piv txwv li, peb txhua tus yuav assimilate lub luag haujlwm. Qhov no txhais tau hais tias Terraform yuav ua lub luag haujlwm no. Thiab tom qab ntawd nrog lub luag haujlwm no nws yuav ua lwm yam haujlwm.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Thiab qhov phem yog tias Vasya nyiam txuas rau Amazon hauv ib txoj hauv kev, piv txwv li, siv lub neej ntawd ib puag ncig hloov pauv, thiab Petya nyiam siv nws tus yuam sij sib koom, uas nws muaj nyob hauv qhov chaw zais cia, ces koj tsis tuaj yeem hais qhia ob qho tib si hauv. Terraform. Thiab txhawm rau kom lawv tsis txhob ntsib kev txom nyem, tsis tas yuav tsum tau qhia qhov thaiv no hauv qhov module. Qhov no yuav tsum tau qhia nyob rau theem siab dua. Ntawd yog, peb muaj ib qho kev pab cuam module, ib qho kev tsim kho vaj tse thiab cov khoom sib xyaw rau saum. Thiab qhov no yuav tsum tau qhia qhov chaw siab dua.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Qhov phem thib ob yog tus muab. Ntawm no qhov kev phem tsis yog qhov tsis tseem ceeb, vim yog tias koj sau code thiab nws ua haujlwm rau koj, ces koj yuav xav tias yog nws ua haujlwm, ces vim li cas hloov nws.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Qhov phem yog tias koj tsis tas yuav tswj xyuas thaum tus txheej txheem no yuav raug tso tawm, ua ntej. Thiab qhov thib ob, koj tsis tswj qhov aws ec2 txhais tau li cas, piv txwv li yog peb tham txog Linux lossis Windows tam sim no. Yog li koj tsis tuaj yeem sau qee yam uas yuav ua haujlwm ib yam ntawm cov haujlwm sib txawv lossis rau cov neeg siv sib txawv.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Qhov piv txwv zoo tshaj plaws, uas tseem tau qhia hauv cov ntaub ntawv tseem ceeb, yog tias yog tias koj sau aws_instance thiab qhia ib pawg ntawm cov lus sib cav, ces tsis muaj dab tsi tsis ncaj ncees lawm yog tias koj qhia tus neeg muab kev pabcuam "loj-exec" nyob rau ntawd thiab khiav koj cov ansible- phau ntawv ua si.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Qhov tseeb, yog, tsis muaj dab tsi tsis ncaj ncees lawm. Tab sis sai sai koj yuav paub tias qhov no hauv zos-exec yam tsis muaj nyob, piv txwv li, hauv launch_configuration.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Thiab thaum koj siv launch_configuration, thiab koj xav tsim ib pawg autoscaling los ntawm ib qho piv txwv, tom qab ntawd hauv launch_configuration tsis muaj lub tswv yim ntawm "provisioner". Muaj lub tswv yim ntawm "tus neeg siv cov ntaub ntawv".

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Yog li ntawd, ib qho kev daws teeb meem ntau dua yog siv cov ntaub ntawv neeg siv. Thiab nws yuav raug tso tawm ntawm qhov piv txwv nws tus kheej, thaum qhov piv txwv qhib, lossis hauv tib cov ntaub ntawv siv, thaum pawg autoscaling siv qhov launch_configuration.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Yog tias koj tseem xav khiav tus muab kev pabcuam, vim tias nws yog ib qho gluing tivthaiv, thaum ib qho peev txheej tsim, lub sijhawm ntawd koj yuav tsum tau khiav koj tus neeg muab kev pabcuam, koj cov lus txib. Muaj ntau qhov xwm txheej zoo li no.

Thiab cov peev txheej raug tshaj plaws rau qhov no yog hu ua null_resource. Null_resource yog ib qho khoom siv dummy uas tsis tau tsim tiag tiag. Nws tsis kov dab tsi, tsis muaj API, tsis muaj autoscaling. Tab sis nws tso cai rau koj los tswj thaum twg los khiav cov lus txib. Hauv qhov no, cov lus txib tau khiav thaum tsim.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

txuas http://bit.ly/common-traits-in-terraform-modules

Muaj ob peb lub cim. Kuv yuav tsis mus rau hauv tag nrho cov cim qhia hauv kev nthuav dav. Muaj ib tsab xov xwm hais txog qhov no. Tab sis yog tias koj tau ua haujlwm nrog Terraform lossis siv lwm tus neeg cov qauv, ces koj tau pom ntau zaus tias ntau cov qauv, zoo li feem ntau ntawm cov cai hauv qhov qhib, tau sau los ntawm tib neeg rau lawv tus kheej xav tau. Ib tug txiv neej sau nws thiab daws nws qhov teeb meem. Kuv nyam nws hauv GitHub, cia nws nyob. Nws yuav nyob, tab sis yog tias tsis muaj cov ntaub ntawv thiab cov piv txwv nyob ntawd, ces tsis muaj leej twg yuav siv nws. Thiab yog tias tsis muaj kev ua haujlwm uas tso cai rau koj los daws qhov me ntsis ntau dua li nws txoj haujlwm tshwj xeeb, ces tsis muaj leej twg yuav siv nws thiab. Muaj ntau txoj hauv kev kom poob cov neeg siv.

Yog tias koj xav sau ib yam dab tsi kom cov neeg siv nws, kuv xav kom ua raws li cov cim no.

Qhov no yog:

  • Cov ntaub ntawv thiab piv txwv.
  • Ua haujlwm puv.
  • Tsim nyog defaults.
  • huv code.
  • Kev Xeem.

Kev ntsuam xyuas yog qhov sib txawv vim lawv nyuaj heev rau sau. Kuv ntseeg ntau dua hauv cov ntaub ntawv thiab cov piv txwv.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Yog li, peb saib yuav ua li cas sau modules. Muaj ob qhov kev sib cav. Thawj, uas yog qhov tseem ceeb tshaj plaws, tsis yog sau yog tias koj tuaj yeem ua tau, vim tias ib pawg neeg twb tau ua cov haujlwm no ua ntej koj. Thiab qhov thib ob, yog tias koj tseem txiav txim siab, sim tsis txhob siv cov chaw muab kev pabcuam hauv modules thiab cov chaw muab kev pabcuam.

Qhov no yog qhov grey ntawm cov ntaub ntawv. Tej zaum koj yuav xav tias: β€œIb yam tsis meej. Tsis ntseeg." Tab sis peb yuav pom nyob rau hauv rau lub hlis.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Tam sim no cia peb tham txog yuav ua li cas hu rau cov modules.

Peb nkag siab tias peb cov cai loj hlob dhau sijhawm. Peb tsis muaj ib cov ntaub ntawv lawm, peb twb muaj 20 cov ntaub ntawv. Lawv tag nrho nyob rau hauv ib daim ntawv tais ceev tseg. Los yog tej zaum tsib folders. Tej zaum peb tab tom pib ua qee yam rhuav tshem lawv los ntawm cheeb tsam, los ntawm qee yam khoom. Tom qab ntawd peb nkag siab tias tam sim no peb muaj qee cov ntsiab lus ntawm synchronization thiab orchestration. Qhov ntawd yog, peb yuav tsum nkag siab tias peb yuav tsum ua li cas yog tias peb hloov pauv cov peev txheej hauv network, peb yuav tsum ua li cas nrog peb cov peev txheej, yuav ua li cas ua rau cov kev vam meej, thiab lwm yam.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Muaj ob qhov kawg. Thawj qhov kawg yog tag nrho hauv ib qho. Peb muaj ib tug master file. Rau lub sijhawm tam sim no, qhov no yog qhov kev coj ua zoo tshaj plaws ntawm Terraform lub vev xaib.

Tab sis tam sim no nws yog sau raws li deprecated thiab tshem tawm. Sij hawm dhau mus, lub zej zog Terraform pom tau hais tias qhov no nyob deb ntawm qhov kev coj ua zoo tshaj plaws, vim tias tib neeg pib siv txoj haujlwm sib txawv. Thiab muaj teeb meem. Piv txwv li, thaum peb sau tag nrho cov kev vam khom nyob rau hauv ib qho chaw. Muaj cov xwm txheej thaum peb nyem "Terraform txoj kev npaj" thiab kom txog thaum Terraform hloov kho cov xeev ntawm tag nrho cov peev txheej, ntau lub sijhawm tuaj yeem dhau mus.

Lub sijhawm ntau yog, piv txwv li, 5 feeb. Rau qee qhov no yog ntau lub sijhawm. Kuv tau pom cov xwm txheej uas nws siv sijhawm 15 feeb. AWS API siv sijhawm 15 feeb los txiav txim seb muaj dab tsi tshwm sim nrog lub xeev ntawm txhua qhov peev txheej. Qhov no yog thaj chaw loj heev.

Thiab, ib txwm, qhov teeb meem cuam tshuam yuav tshwm sim thaum koj xav hloov qee yam hauv ib qho chaw, tom qab ntawd koj tos 15 feeb, thiab nws muab rau koj ib daim ntaub ntawm qee qhov kev hloov pauv. Koj spat, sau "Yog", thiab ib yam dab tsi tsis ncaj ncees lawm. Qhov no yog ib qho piv txwv tiag tiag. Terraform tsis sim tiv thaiv koj ntawm teeb meem. Ntawd yog, sau qhov koj xav tau. Yuav muaj teeb meem - koj cov teeb meem. Thaum Terraform 0.11 tsis yog sim pab koj hauv txhua txoj kev. Muaj qee qhov chaw nthuav dav hauv 0.12 uas tso cai rau koj hais tias: "Vasya, koj xav tau qhov no, koj puas tuaj yeem nkag siab koj lub siab?"

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Qhov thib ob txoj kev yog txo qhov chaw no, uas yog, kev hu xov tooj los ntawm ib qho chaw tuaj yeem txuas nrog tsawg dua los ntawm lwm qhov chaw.

Qhov teeb meem nkaus xwb yog tias koj yuav tsum tau sau cov lej ntxiv, piv txwv li koj yuav tsum tau piav qhia qhov hloov pauv hauv ntau cov ntaub ntawv thiab hloov kho qhov no. Qee tus neeg tsis nyiam nws. Qhov no yog ib txwm rau kuv. Thiab qee tus neeg xav tias: "Vim li cas thiaj sau qhov no rau ntau qhov chaw, kuv yuav muab tso rau hauv ib qho chaw." Qhov no yog ua tau, tab sis qhov no yog qhov thib ob huab.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Leej twg muaj tag nrho cov no nyob hauv ib qho chaw? Ib, ob, peb tus neeg, uas yog, ib tug neeg siv nws.

Thiab leej twg hu ib qho tshwj xeeb, ib qho thaiv lossis ib qho kev tsim kho vaj tse? Tsib mus rau xya tus neeg. Qhov no yog txias.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Feem ntau cov lus teb yog qhov chaw hauv nruab nrab. Yog tias qhov project loj, ces koj feem ntau yuav muaj qhov xwm txheej uas tsis muaj kev daws teeb meem thiab tsis yog txhua yam ua haujlwm nyob rau ntawd, yog li koj xaus nrog kev sib tov. Tsis muaj ib yam dab tsi phem rau qhov no, tsuav koj nkag siab tias ob qho tib si muaj qhov zoo.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Yog tias qee yam hloov pauv hauv pawg VPC thiab koj xav siv cov kev hloov pauv no rau EC2, piv txwv li koj xav hloov kho pawg autoscaling vim tias koj muaj subnet tshiab, ces kuv hu rau hom kev vam khom orchestration. Muaj qee qhov kev daws teeb meem: leej twg siv dab tsi?

Kuv tuaj yeem hais tias cov kev daws teeb meem twg muaj. Koj tuaj yeem siv Terraform los ua cov khawv koob, lossis koj tuaj yeem siv makefiles siv Terraform. Thiab saib yog tias ib yam dab tsi tau hloov nyob rau ntawd, koj tuaj yeem tso nws ntawm no.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Koj nyiam qhov kev txiav txim no li cas? Puas muaj leej twg ntseeg tias qhov no yog kev daws teeb meem? Kuv pom ib tug luag ntxhi, pom tau tias kev tsis ntseeg tau nkag mus rau hauv.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Tau kawg, tsis txhob sim qhov no tom tsev. Terraform yeej tsis tau tsim los khiav ntawm Terraform.

Ntawm ib tsab ntawv ceeb toom lawv hais rau kuv: "Tsis yog, qhov no yuav tsis ua haujlwm." Lub ntsiab lus yog tias nws yuav tsum tsis ua haujlwm. Txawm hais tias nws zoo li zoo nkauj heev thaum koj tuaj yeem tso Terraform los ntawm Terraform, thiab tom qab ntawd Terraform, koj yuav tsum tsis txhob ua li ntawd. Terraform yuav tsum ib txwm pib yooj yim heev.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

https://github.com/gruntwork-io/terragrunt/

Yog tias koj xav tau hu rau orchestration thaum qee yam hloov pauv hauv ib qho chaw, ces muaj Terragrunt.

Terragrunt yog ib qho khoom siv hluav taws xob, ib qho ntxiv rau Terraform, uas tso cai rau koj los tswj hwm thiab tswj hwm kev hu mus rau cov qauv tsim vaj tsev.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Ib yam Terraform configuration file zoo li no.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Koj qhia meej qhov tshwj xeeb module koj xav hu.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Dab tsi yog qhov kev vam khom module muaj?

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Thiab qhov kev sib cav dab tsi no module txais. Qhov ntawd yog txhua yam kom paub txog Terragrunt.

Cov ntaub ntawv nyob ntawd, thiab muaj 1 hnub qub ntawm GitHub. Tab sis feem ntau qhov no yog qhov koj yuav tsum paub. Thiab qhov no yooj yim heev rau kev siv hauv cov tuam txhab uas nyuam qhuav pib ua haujlwm nrog Terraform.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Yog li orchestration yog Terragrunt. Muaj lwm txoj kev xaiv.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Tam sim no cia peb tham txog yuav ua li cas ua haujlwm nrog cov cai.

Yog tias koj xav tau ntxiv cov yam ntxwv tshiab rau koj cov cai, feem ntau qhov no yooj yim. Koj tab tom sau cov peev txheej tshiab, txhua yam yooj yim.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Yog tias koj muaj qee qhov peev txheej uas koj tsim ua ntej, piv txwv li, koj tau kawm txog Terraform tom qab koj qhib AWS account thiab xav siv cov peev txheej uas koj twb muaj lawm, ces nws yuav tsim nyog los txuas ntxiv koj qhov module hauv txoj kev no, yog li ntawd. nws txhawb kev siv cov peev txheej uas twb muaj lawm.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Thiab txhawb kev tsim cov peev txheej tshiab siv cov peev txheej thaiv.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Ntawm cov zis peb ib txwm rov qab tso zis id nyob ntawm seb tau siv.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Qhov teeb meem tseem ceeb thib ob hauv Terraform 0.11 yog ua haujlwm nrog cov npe.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Qhov nyuaj yog tias peb muaj xws li cov npe ntawm cov neeg siv.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Thiab thaum peb tsim cov neeg siv no siv cov peev txheej thaiv, ces txhua yam mus zoo. Peb mus dhau tag nrho cov npe, tsim cov ntaub ntawv rau txhua tus. Txhua yam zoo. Thiab tom qab ntawd, piv txwv li, user3, uas nyob hauv nruab nrab, yuav tsum raug tshem tawm ntawm no, tom qab ntawd tag nrho cov peev txheej uas tau tsim tom qab nws yuav raug rov tsim dua vim qhov ntsuas yuav hloov.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Ua hauj lwm nrog cov npe nyob rau hauv ib qho chaw muaj cai. Ib puag ncig xeev yog dab tsi? Qhov no yog qhov xwm txheej uas tus nqi tshiab raug tsim thaum cov peev txheej no raug tsim. Piv txwv li, AWS Access Key lossis AWS Secret Key, piv txwv li thaum peb tsim ib tus neeg siv, peb tau txais Access tshiab lossis Secret Key. Thiab txhua zaus peb rho tawm tus neeg siv, tus neeg siv no yuav muaj tus yuam sij tshiab. Tab sis qhov no tsis yog feng shui, vim tias tus neeg siv yuav tsis xav ua phooj ywg nrog peb yog tias peb tsim ib tus neeg siv tshiab rau nws txhua zaus ib tus neeg tawm hauv pab pawg.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Qhov no yog qhov kev daws teeb meem. Qhov no yog code sau hauv Jsonnet. Jsonnet yog ib hom lus los ntawm Google.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Qhov kev hais kom ua no tso cai rau koj lees txais cov qauv no thiab raws li cov zis tawm nws rov qab cov ntaub ntawv json uas tau ua raws li koj tus qauv.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Lub template zoo li no.

Terraform tso cai rau koj ua haujlwm nrog ob qho tib si HCL thiab Json tib txoj kev, yog li yog tias koj muaj peev xwm tsim Json, ces koj tuaj yeem plam nws mus rau Terraform. Cov ntaub ntawv nrog qhov txuas ntxiv .tf.json yuav raug rub tawm kom tiav.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Thiab ces peb ua hauj lwm nrog nws li niaj zaus: terraform init, terramorm siv. Thiab peb tsim ob tus neeg siv.

Tam sim no peb tsis ntshai yog tias ib tug neeg tawm hauv pab pawg. Peb mam li hloov cov ntaub ntawv json xwb. Vasya Pupkin sab laug, Petya Pyatochkin tseem nyob. Petya Pyatochkin yuav tsis tau txais tus yuam sij tshiab.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Kev koom ua ke Terraform nrog lwm cov cuab yeej tsis yog Terraform txoj haujlwm tiag tiag. Terraform tau tsim los ua lub platform rau kev tsim cov peev txheej thiab qhov ntawd yog nws. Thiab txhua yam uas tuaj tom qab tsis yog Terraform qhov kev txhawj xeeb. Thiab tsis muaj qhov yuav tsum tau weave nws nyob rau ntawd. Muaj Ansible, uas ua txhua yam koj xav tau.

Tab sis cov xwm txheej tshwm sim thaum peb xav txuas ntxiv Terraform thiab hu rau qee qhov lus txib tom qab qee yam ua tiav.

Thawj txoj kev. Peb tsim qhov tso zis qhov twg peb sau cov lus txib no.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Thiab tom qab ntawd peb hu cov lus txib no los ntawm lub plhaub terraform tso zis thiab qhia tus nqi uas peb xav tau. Yog li, cov lus txib raug tua nrog tag nrho cov txiaj ntsig hloov pauv. Nws yooj yim heev.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Txoj kev thib ob. Qhov no yog kev siv null_resource nyob ntawm kev hloov pauv hauv peb cov txheej txheem. Peb tuaj yeem hu rau tib lub zos-exe sai li sai tau thaum tus ID ntawm qee qhov kev hloov pauv.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Lawm, qhov no yog txhua yam du ntawm daim ntawv, vim Amazon, zoo li txhua tus neeg muab kev pabcuam pej xeem, muaj ib pawg ntawm nws tus kheej cov ntaub ntawv ntug.

Cov ntaub ntawv ntug feem ntau yog thaum koj qhib AWS account, nws tseem ceeb rau thaj chaw twg koj siv; yog qhov no feature enabled muaj; tej zaum koj tau qhib nws tom qab lub Kaum Ob Hlis 2013; Tej zaum koj siv lub neej ntawd hauv VPC thiab lwm yam. Muaj ntau yam kev txwv. Thiab Amazon tau tawg lawv thoob plaws hauv cov ntaub ntawv.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Muaj ob peb yam uas kuv xav kom zam dhau.

Txhawm rau pib, zam txhua qhov kev sib cav tsis zais hauv Terraform txoj kev npaj lossis Terraform CLI. Tag nrho cov no tuaj yeem muab tso rau hauv cov ntaub ntawv tfvars lossis rau hauv ib puag ncig hloov pauv.

Tab sis koj tsis tas yuav cim tag nrho cov lus txib no. Terraform txoj kev npaj - var thiab tawm peb mus. Thawj qhov sib txawv yog var, qhov sib txawv thib ob yog var, thib peb, plaub. Lub hauv paus ntsiab lus tseem ceeb tshaj plaws ntawm kev tsim kho vaj tse raws li cov cai uas kuv siv feem ntau yog tias tsuas yog los ntawm kev saib cov cai, kuv yuav tsum muaj kev nkag siab meej txog qhov uas tau siv nyob rau ntawd, nyob rau hauv lub xeev dab tsi thiab cov nqi dab tsi. Thiab yog li kuv tsis tas yuav nyeem cov ntaub ntawv lossis nug Vasya tias nws siv dab tsi los tsim peb pawg. Kuv tsuas yog xav qhib cov ntaub ntawv nrog tfvars txuas ntxiv, uas feem ntau cuam tshuam rau ib puag ncig, thiab saib txhua yam nyob ntawd.

Tsis tas li ntawd, tsis txhob siv cov ntsiab lus sib cav kom txo tau qhov peev txheej. Rau qhov no nws yooj yim dua los siv me me infrastructure modules.

Tsis tas li ntawd, tsis tas yuav txwv thiab nce kev sib luag. Yog tias kuv muaj 150 cov peev txheej thiab kuv xav nce Amazon parallelism los ntawm lub neej ntawd 10 txog 100, ces feem ntau yuav muaj qee yam tsis raug. Los yog nws yuav mus zoo tam sim no, tab sis thaum Amazon hais tias koj tau hu ntau dhau lawm, koj yuav muaj teeb meem.

Terraform yuav sim rov pib dua feem ntau ntawm cov teeb meem no, tab sis koj yuav ua tiav yuav luag tsis muaj dab tsi. Parallelism = 1 yog ib qho tseem ceeb uas yuav tsum tau siv yog tias koj dawm qee qhov kab mob hauv AWS API lossis sab hauv Terraform tus kws kho mob. Thiab tom qab ntawd koj yuav tsum tau qhia meej: parallelism = 1 thiab tos kom txog thaum Terraform ua tiav ib qho kev hu, tom qab thib ob, tom qab thib peb. Nws yuav tso lawv ib tug los ntawm ib tug.

Cov neeg feem ntau nug kuv, "Vim li cas kuv xav tias Terraform chaw ua haujlwm yog qhov phem?" Kuv ntseeg tias lub hauv paus ntsiab lus ntawm kev tsim kho vaj tse raws li cov cai yog saib seb cov infrastructure tau tsim thiab muaj nuj nqis dab tsi.

Cov chaw ua haujlwm tsis tau tsim los ntawm cov neeg siv. Qhov no tsis tau txhais hais tias cov neeg siv sau hauv GitHub cov teeb meem uas peb tsis tuaj yeem nyob tsis muaj Terraform chaw ua haujlwm. Tsis yog tsis zoo li no. Terraform Enterprise yog kev lag luam daws teeb meem. Terraform los ntawm HashiCorp txiav txim siab tias peb xav tau chaw ua haujlwm, yog li peb tau foob nws tam sim ntawd. Kuv pom tias nws yooj yim dua rau muab tso rau hauv ib lub nplaub tshev cais. Tom qab ntawd yuav muaj cov ntaub ntawv me ntsis ntxiv, tab sis nws yuav pom tseeb dua.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Yuav ua li cas ua haujlwm nrog tus lej? Qhov tseeb, ua haujlwm nrog cov npe yog qhov mob nkaus xwb. Thiab siv Terraform yooj yim dua. Qhov no tsis yog qhov uas yuav ua txhua yam zoo rau koj. Tsis tas yuav shov txhua yam uas tau sau rau hauv cov ntaub ntawv ntawd.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Lub ntsiab lus ntawm tsab ntawv ceeb toom tau sau "rau yav tom ntej." Kuv mam li tham txog qhov no luv luv. Rau yav tom ntej, qhov no txhais tau tias 0.12 yuav raug tso tawm sai sai.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

0.12 yog ib tuj ntawm cov khoom tshiab. Yog tias koj los ntawm kev ua haujlwm tsis tu ncua, tom qab ntawd koj nco txhua hom dynamic blocks, loops, raug thiab ua haujlwm sib piv, qhov twg sab laug thiab sab xis tsis suav ib txhij, tab sis nyob ntawm qhov xwm txheej. Koj nco nws heev, yog li 0.12 yuav daws tau rau koj.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Tab sis! Yog tias koj sau tsawg dua thiab yooj yim dua, siv cov qauv npaj ua tiav thiab cov kev daws teeb meem thib peb, ces koj yuav tsis tas tos thiab cia siab tias 0.12 yuav tuaj thiab kho txhua yam rau koj.

Kev piav qhia ntawm infrastructure hauv Terraform rau yav tom ntej. Anton Babenko (2018)

Ua tsaug rau daim ntawv qhia! Koj tau tham txog kev tsim kho vaj tse raws li cov cai thiab hais ib lo lus hais txog kev xeem. Puas xav tau kev ntsuam xyuas hauv modules? Qhov no yog leej twg? Kuv puas yuav tsum tau sau nws tus kheej lossis nws puas yog lub luag haujlwm ntawm cov modules?

Lub xyoo tom ntej yuav muaj cov ntawv ceeb toom uas peb tau txiav txim siab sim txhua yam. Yuav kuaj dab tsi yog lo lus nug loj tshaj plaws. Muaj ntau qhov kev vam khom, ntau qhov kev txwv los ntawm cov chaw muab kev pabcuam sib txawv. Thaum koj thiab kuv tab tom tham thiab koj hais tias: "Kuv xav tau kev xeem," ces kuv nug: "Koj yuav sim dab tsi?" Koj hais tias koj yuav sim hauv koj cheeb tsam. Ces kuv hais tias qhov no tsis ua hauj lwm hauv kuv cheeb tsam. Qhov ntawd yog, peb yuav tsis tuaj yeem pom zoo rau qhov no. Tsis txhob hais tias muaj ntau yam teeb meem technical. Qhov ntawd yog, yuav ua li cas sau cov ntawv xeem no kom lawv txaus.

Kuv tabtom tshawb fawb cov ncauj lus no, piv txwv li yuav ua li cas thiaj li tsim cov kev xeem raws li cov txheej txheem uas koj tau sau. Ntawd yog, yog tias koj sau cov lej no, ces kuv yuav tsum tau khiav nws, raws li qhov no kuv tuaj yeem tsim cov kev xeem.

Terrateest yog ib lub tsev qiv ntawv uas tau hais ntau zaus uas tso cai rau koj los sau cov kev xeem sib koom ua ke rau Terraform. Qhov no yog ib qho ntawm cov khoom siv hluav taws xob. Kuv nyiam hom DSL, piv txwv li, rspec.

Anton, ua tsaug rau daim ntawv qhia! Kuv lub npe yog Valery. Cia kuv nug me ntsis philosophical lo lus nug. Muaj, conditionally, provisioning, muaj deployment. Kev npaj tsim kuv qhov kev tsim kho vaj tse, hauv kev xa tawm peb sau nws nrog qee yam muaj txiaj ntsig, piv txwv li, servers, daim ntawv thov, thiab lwm yam. Thiab nws nyob hauv kuv lub taub hau tias Terraform muaj ntau dua rau kev npaj, thiab Ansible yog ntau dua rau kev xa tawm, vim Ansible kuj yog rau lub cev Cov txheej txheem. tso cai rau koj los nruab nginx, Postgres. Tab sis tib lub sijhawm, Ansible zoo li tso cai rau kev muab, piv txwv li, ntawm Amazon lossis Google cov peev txheej. Tab sis Terraform kuj tso cai rau koj siv qee cov software siv nws cov modules. Los ntawm koj qhov kev xav, puas muaj qee yam ciam teb uas khiav ntawm Terraform thiab Ansible, qhov twg thiab siv dab tsi zoo dua? Los yog, piv txwv li, koj puas xav tias Ansible yog cov khib nyiab, koj yuav tsum sim siv Terraform rau txhua yam?

Zoo lus nug, Valery. Kuv ntseeg tias Terraform tsis tau hloov pauv ntawm lub hom phiaj txij li xyoo 2014. Nws tau tsim rau infrastructure thiab tuag rau infrastructure. Peb tseem muaj thiab yuav muaj qhov xav tau rau kev tswj hwm kev teeb tsa Ansible. Qhov kev sib tw yog tias muaj cov neeg siv cov ntaub ntawv hauv launch_configuration. Thiab nyob ntawd koj rub Ansible, thiab lwm yam. Qhov no yog tus qauv sib txawv uas kuv nyiam tshaj plaws.

Yog tias peb tab tom tham txog hauv kev tsim vaj tsev zoo nkauj, ces muaj cov khoom siv xws li Packer uas sau cov duab no. Thiab tom qab ntawd Terraform siv cov ntaub ntawv los nrhiav cov duab no thiab hloov kho nws qhov launch_configuration. Ntawd yog, nyob rau hauv txoj kev no lub raj xa dej yog tias peb xub rub Tracker, ces rub Terraform. Thiab yog tias tsim tau tshwm sim, ces qhov kev hloov tshiab tshwm sim.

Nyob zoo! Ua tsaug rau daim ntawv qhia! Kuv lub npe yog Misha, RBS tuam txhab. Koj tuaj yeem hu rau Ansible ntawm tus muab kev pabcuam thaum tsim cov peev txheej. Ansible tseem muaj lub ntsiab lus hu ua dynamic inventory. Thiab koj tuaj yeem hu rau Terraform thawj zaug, thiab tom qab ntawd hu rau Ansible, uas yuav siv cov peev txheej los ntawm lub xeev thiab ua tiav nws. Dab tsi zoo dua?

Tib neeg siv ob qho tib si nrog kev vam meej. Nws zoo nkaus li kuv tias cov khoom lag luam muaj zog hauv Ansible yog qhov yooj yim, yog tias peb tsis tham txog pawg autoscaling. Vim tias hauv pawg autoscaling peb twb muaj peb tus kheej cov cuab yeej, uas yog hu ua launch_configuration. Hauv launch_configuration peb sau txhua yam uas yuav tsum tau pib thaum peb tsim cov peev txheej tshiab. Yog li ntawd, nrog Amazon, siv cov khoom lag luam dynamic thiab nyeem cov ntaub ntawv Terraform ts, hauv kuv lub tswv yim, yog overkill. Thiab yog tias koj siv lwm yam cuab yeej uas tsis muaj lub tswv yim ntawm "autoscaling group", piv txwv li, koj siv DigitalOcean lossis lwm tus neeg muab kev pabcuam uas tsis muaj autoscaling pab pawg, tom qab ntawd koj yuav tsum rub tus API, nrhiav IP chaw nyob, tsim. cov ntaub ntawv dynamic dynamic , thiab Ansible yuav dhau los ntawm nws. Ntawd yog, rau Amazon muaj launch_configuration, thiab rau txhua yam ntxiv muaj cov khoom muag dynamic.

Tau qhov twg los: www.hab.com

Ntxiv ib saib