Terraform中用于对抗混乱和手动杂务的模式。马克西姆·科斯特里金(Ixtens)



Terraform开发人员似乎提供了使用AWS基础架构的相当方便的最佳实践。只有细微差别。随着时间的流逝,环境的数量增加,每种环境都有其功能。出现邻近区域中几乎所有应用程序堆栈的副本。而且Terraform代码需要根据新的要求仔细复制和编辑,或者制作雪花。



我谈到了Terraform中用于处理大型项目和长期项目中的混乱和手动例程的模式。



视频:







我40岁,我在IT领域有20年。我已经为Ixtens工作了12年。我们从事电子商务驱动的开发。我从事DevOps练习已有5年了。





我的故事将是关于某公司项目中的经验的,我不会说这个名字,但要隐瞒一个保密协议。



, . , , Amazon.





4 . , . , , . , - .



, , . , 4 .



.



, , time to market. , DevOps- . Terraform Puppet.





Terraform – open source HashiCorp. , , , .





– , - , , .



, . , .





Amazon. Terraform plan. Terraform plan : «, ». , , . .





, , Terraform apply Terraform instance, .





. - . instances, 53 .





. plan. , . . .



Terraform state-. . . , Amazon, , , , , Amazon. - , Terraform , Amazon.





state- . Git, . - , .



, . . Terraform bucket, state-. Terraform , state-, .





. . , .





Terraform , . . - .





, , Terraform apply . .





production - , instances, production instances .





. , . - , : , maintenance , , . , , .



, HashiCorp, - , .



production .





, - . , , , instance, , . . , .



Terraform . , IP-, , instance, IP- route53 .



, . , , 8 – .



. Jenkins job . pull request , , , , . performance , instances . , - , . . .



Jenkins shell-, Terraform. , . Terraform apply .



, .





- , , production, , , .



, , production. , production . , production operation . , , production, .



, , - . , , .



, Terraform – . . - , . .



- , pull request, , . , . , , -, . , Terraform-. , Terraform breaking chain , . . . pull request, , Terraform.



, , Terraform-, , - .



, operation, , pull request, . , . DevOps, , , . - .





, . , . : « , ».



, , - Terraform. , , , , Terraform-, , , .





, , Symlinks. Terraform . , , , . . , Symlinks .





, production assume role, - Amazon-. , , , , Terraform Amazon- .





Symlinks ? , Terraform state-. - . , Terraform . - , .



, - , . bucket. , sandbox sandbox-, production. , bucket production sandbox. , . - , - .





? , Terraform . Terraform . - . Terraform init, , .



shell-, , -, . Shell- . , -, . , state-, , , .





? JSON-. Terraform hcl (HashiCorp Configuration Language), JSON.



JSON shell-. , - bucket. bucket Terraform-, shell- .





bucket Terraform? remote state-. . . - , , Amazon: «, , instance», .



- . : «Terraform, , , state- ». environments.



state-. , VPC. Terraform-, VPC, VPC, , .





. . , VPC , , instance.





state- . , , , .





. Terraform ? , , 4 .



HashiCorp , Terraform-. Terraform fmt , . , , , HashiCorp, . .





– Terraform validate. , – , . ? . . Terraform validate.



, , , .



– , .



, Terraform, HashiCorp : « ? , – ?». .





Terraform , , Terraform : «, , , . , Terraform-».





, Terraform-, . , , , - , Terraform : « - , ».





– Terraform plan. , – . . , .



- , , - - - . Terraform plan , .



. , , Python, . , : Terraform- - , .



Terraform plan . , , .



, , , , – . pull request : «, ». . attach , .



– . , Terraform Amazon : « instance ? autoscale ?». , , refresh=false. , Terraform S3 state. , state , Amazon.



Terraform plan , state , . . -, - Terraform refresh. Terraform refresh , state , .



. . , Terraform, Terraform , . . . , , . pull request - , , . , Terraform plan.





, , user-data.



user-data? Amazon, instance, instance – -. instance , cloud init instances. Cloud init : «, – load balancer». - .





, , Terraform plan Terraform apply, user-data , . . . . , , - .



, Amazon, - .





, , template. : «, template». , Amazon.





– user-data. . . . , - user-data, : «, - – ».





, , Automate Terraform apply.



, Terraform apply , , , .



– . . . job, , , . , « » — , , , , - . , : «, , , ».



production, sandbox , , , , - . : autoscale-, security-, roles, route53 . , , .



, , , - persistent, , , - . jobs, .



Amazon Terminate protection. . . . Terraform Amazon : « instance, ». Amazon : «Sorry, . Terminate protection».





– . Terraform-, . , , - . , , , , .



. review. , - review , . , .





, . . . - , , - environment.





, , , . . , .



, Terraform, locals. output’ - , . .





, . . , ( ), , . : « , ». , , , , - , . , . , . : «, !». : «, . , ».



, , , , . , . . , , , , , .





:



  • . , , - .
  • . . . - , . , - - , Elasticsearch, Terraform plan, , . , .
  • . , , . .
  • production- . , - production - , . - .
  • Terraform- , refactoring .




  • Immutable infrastructure. AMI .
  • route53, , .
  • API rate limits. Amazon : «-, , , ». , .
  • Spot instances. Amazon – spots . .
  • IAM roles.
  • , Amazone instances , . instances 100-150 – 1 000 . – .
  • instances.




. Terraform – , . !





! state- S3, , state- ?



-, . -, flags, , - . . . , , , - - . – , state- Git . , - state-, , . . , Terraform . - , locks, , .



enterprise?



enterprise, . . , .



. . Amazon, instance . Terraform, Life Second , .



. .



. -, . - ? Test Kitchen. , - . Local Values. Input Variables? - Local Values? , - .



. – . , . , , -, , , , . , . . - , , - .



Local Values .



! ! . , . ?



, ! , , , , , . , , , , . , , , . , , . , . .



jsonnet -?



.



, . , .



– , , . . . , . . , , . .



. !



, . , Terraform . Ansible?



. Ansible , Puppet Amazon. Terraform .



Amazon?



, Amazon. Amazon. , Terraform . Ansible, : « 5 instances», , : « 3». Terraform : «, 2 », Ansible : «, 3». 8.



! ! Terraform. , Terraform - , Terraform .



. . . , , . ., .



. Remote backend, S 3. ?



?



Terraform Cloud .



?



4 .



4 , , , .



locks, state -. . .



, . .



, branch? ?



, . Terraform, Puppet, , - , . , , . branches, . , , -. , .



. . ?



.



branch . . . , , – , , . , , . . . .



! ! ! . , . , , ? - , ?



. , , - - . - .



. . ?



. . . , .



! ! . , . Puppet ?



User-data.



. . - ?



User-data – , . . , Daemon , , , load balancer.



. . - , ?



. .



! User — data. , , - - . - user — data Git, , User-data?



User-data template. . . - . Terraform . template , , , , , . – –-, -, , . , , - , . autoscale- , - instances autoscale- . , - . .



, – ?



, , . . . output’ . , , - – , User-data .



. , , Terraform .



.



, , , . . , tfvars, . . , tfvars ?



. . (: Production/environment/settings.tf) : domain = , domain vpcnetwork, vpcnetwork stvars – ?



. setting source, .



, tfvars. Tfvars testing-. tfvars instances, . . , . , , . , , tfvars.



, ?



, tfvars – . . tfvars . – . .



! , , Terraform ’? , - . ssh -. Google -, . Terraform , . , , , .



, – , , . . Terraform . . .



. . , , ?



, .



! . Mail. ru Group. …, ? , User — data, host name, Puppet ? . SG, . . SG, instances, ?



instances, , . , , , autoscale-. , .



, , . - , . , , , . , , , - .



?



SG instances, - ?



, . instance , , . , , , IP- . . -, Consul Discovery, , Kubernetes. Consul IP- instance.



. . IP, host name ?



host name, . . . instance – AE . . - , .



! , Terraform – , .



.



. , , Bare Metal instances? ? - , , Ansible, ?



Ansible . . . Ansible , instance . Terraform , instance . Bare Metal – .



, : «».



– , . Terraform-, - .



, – , . . , - : «, N , Amazon».



Terraform Front-End jobs, PagerDuty, data doc . . . .



! 4 Terraform. Terraform, , , , - - , plan. - . ? , ?



主要是用我们的手和眼睛,如果我们在报告中看到一些奇怪的东西,那么我们分析那里发生的事情,或者干脆杀死。通常,拉取请求很常见。



如果有错误,您要回滚吗?你有试过吗?



不,这是一个人看到问题时的决定。




All Articles