
Es scheint, dass Terraform-Entwickler recht praktische Best Practices fĂŒr die Arbeit mit der AWS-Infrastruktur anbieten. Nur gibt es eine Nuance. Mit der Zeit nimmt die Anzahl der Umgebungen zu, jede verfĂŒgt ĂŒber Funktionen. Es erscheint fast eine Kopie des Anwendungsstapels in der Nachbarregion. Und der Terraform-Code muss sorgfĂ€ltig kopiert und gemÀà den neuen Anforderungen bearbeitet werden oder um eine Schneeflocke herzustellen.
Mein Vortrag ĂŒber Muster in Terraform fĂŒr den Umgang mit Chaos und manueller Routine bei groĂen und langen Projekten.
Video:

Ich bin 40, ich bin 20 Jahre in der IT. Ich arbeite seit 12 Jahren fĂŒr Ixtens. Wir beschĂ€ftigen uns mit E-Commerce-getriebener Entwicklung. Und ich praktiziere seit 5 Jahren DevOps.

Meine Geschichte handelt von Erfahrungen in einem Projekt in einem Unternehmen, dessen Namen ich nicht sagen werde und das sich hinter einer Geheimhaltungsvereinbarung versteckt.
, . , , 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. - . ? , ?
HauptsÀchlich mit unseren HÀnden und Augen, wenn wir in dem Bericht etwas Seltsames sehen, analysieren wir, was dort passiert, oder wir töten einfach. Pull-Anfragen sind im Allgemeinen an der Tagesordnung.
Wenn ein Fehler auftritt, fĂŒhren Sie einen Rollback durch? Hast du das versucht?
Nein, dies ist die Entscheidung einer Person in dem Moment, in dem sie ein Problem sieht.