AWS Meetup Terraform & Terragrunt. Anton Babenko (2020)



Terraform is a popular Hashicorp tool for managing your cloud infrastructure in the Infrastructure as a Code paradigm .



Terragrunt is a wrapper for Terraform that provides additional tools for storing your Terraform configurations, working with multiple Terraform modules, and managing remote state.



Video:







Links:





AWS Community Hero. ā€“ Terraform-, Terraform. , HashiCorp-.



open source . , Terraform-, community-modules, aws-modules. , - - .



, , , Pre-commit-terraform. , . .



. , , Delivery Excellence. Terraform Terraform.



, GitHub , Linkedin . , open source, open source.





  • All-things Terraform + AWS + DevOps.



  • Consulting.



  • Workshops.



  • Trainings.



  • Mentorship.





Open source ā€“ . open source. , : Ā« ? ?Ā». .



- , Terraform, Terraform Terraform workspace, : Ā« workshops , ?Ā». workshops.



- , . ., , - , , - , , pull request, , -. , -.



email: anton [] antonbabanko.com. , , , . . , , .



Betajob.com. .





https://github.com/terraform-aws-modules



https://registry.terraform.io/modules/terraform-aws-modules



Terraform AWS ā€“ , 2017- , - , . , VPC Amazon. , - . , , - , , . . .



, . .



, . . .





https://github.com/sponsors/antonbabenko



7 000 000 , 1 000 pull requests issues . 6 , GitHub. -, , . , .





, , Cloudcraft. , , . . , . , , .





Cloudcraft , , AWS-.





https://dzone.com/articles/infrastructure-as-code-the-benefits



, , , , , , . . . , . . , . , Powerpoint. , clickops, ā€“ , , . , , .



, ā€“ , , , . , . . . cndb, Systems Manager Amazon. .





?



Terraform 0.12 Terraform 0.11.





, Terraform . , . Terraform . , Terraform .



Amazon 2011- : Ā« CloudFormationĀ». , . Spectrum, Fogs . ., JSON, YAML . ., . . - . DSL . . GitHub , , orchestration-cloudformation. . Spectrum ā€“ , -.



, Google , , , , Python, Jinja Tempating, . Google.



Azure , , , JSON. , , . , . Azure ARM Terraform . , - , Terraform ā€“ , JSON, .



Chef, Ansible, Puppet, . , , . .



: - , public cloud Amazon, Google, Azure . . configuration management - , , . , : , , .





Terraform 2014- , , , , CloudFormation, CloudFormation , , . .





Terraform, , 250 , . . HashiCorp Configuration Language, , .



Terraform , , . Terraform , - . Terraform, . Terraform . CloudFormation . , CloudFormation , 2013-2014- , .



Terraform mainframes, workers . . , , 2014- . , , API , Terraform . Terraform . use cases.





https://www.terraform.io/docs/providers/index.html



API , . . email Google permeation Dropbox, . , , Terraform . use cases.



use cases, . , Minecraft . , -. . , . , Terraform? , . hsale, , . , . Terraform , , , . , .



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



, , . , , - , email, GitHub-, Jira. pull requests Terraform. .





Terraform, 3 :





, : Ā« ?Ā». ā€“ best practices . , best practices ā€“ , terraform-best-practices. . . . , . , , Terraform . , , , , . , , - .



, , . : Ā« Ā», . ., , - , , email pull request , . , , . - .



. , , Terraform ā€“ , . , , , . Terraform , , work space .





?





Terraform 0.11 , . . . s3_bucket.





Terraform 0.12 . , . . , .





https://www.hashicorp.com/blog/announcing-terraform-0-1-2-beta



. ; , , .



Terraform 0.11, , , , , try, false . , . Correct conditional operators , , , , . Terraform AWS . .



? ? 100 -500 , . Terraform plan, Terraform apply environment, . , . test cases : . . . . , Terraform . . . , Terraform - , , review, .



. . , Terraform, . . HashiCorp . , Terraform 0.12 , .



. , HashiCorp ā€“ , , . . open source.





https://www.terraform.io/upgrade-guides/0-12.html



, 0.11 0.12 .



-, upgrade guide, , , , . . , 90 % , .



, Terraform 0.12, 0.11 , Terraform state , 0.12. , -, , , state , , .



, . - 0.12, - , , .





https://github.com/tfutils/tfenv



, tfenv. .





https://www.terraform.io/docs/configuration/terraform.html



, , . , . ? -. , AWS. , . . Terraform-, . . .





, : Ā«, , ?Ā», Terraform state , . .





, Terraform , .





, , Terraform , Terraform . , .





, all-in-one, tf Terraform-. , , outputs. , refresh , plan . .





ā€“ , 1-in-1. . - , - , . , .





. : all-in-one 1-in-1? , , , all-in-one ā€“ , 1-in-1 ā€“ .





MFA (Most Frequent Answer) ā€“ .





, - , . Google : Ā«Google, - , Ā», terraform.io, - ā€“ all-in-one. , . Terraform plan 20 . all-in-one.



, , all-in-one , . , , . , environment. . . - .



1-in-1 , . , Registry terraform.io, VPC-. , , , . . - , . 1-in-1.



, , - Terraform-, - , , .



, , Terragrunt, 1-in-1 .





?





, all-in-one. Terraform plan. 15 . . , - . Terraform apply, 15 , Ā«YesĀ», .



, , main targets. terraform apply -targets = module.vpc. VPC. , shell-, makefile, PowerShell - Terraform, , war- , . .



1-in-1, mikefile . Terraform apply , Terraform apply . . . . , make terraform apply - . .



? , state input . , , shell-, , . , , Terraform apply, data-source , Terraform remote state . . shell-, makefiles.





? ? . . Terraform Terraform.





, . . ? Terraform . . . , Ā«Terraform applyĀ». -, . , .



, Terraform , , . .





, Terragrunt. .





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



https://github.com/antonbabenko/terragrunt-reference-architecture



ā€“ Terraform Terraform-.



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



, . Terragrunt .



, , Ā«starĀ» GitHub, 3 000 . , . .



, , , . .



, , . Terragrunt-reference-architecture , . , . , , . , , .





Terragrunt. .hcl. , - Terraform , .



3 , . inputs 14- , . , , Terragrunt.



: registry, . , 3. , . 14. terragrunt apply .



Terraform, , . , AutoScaling 200-300 , .



, , Terraform, AWS SDK, , .



, Amazon, DevOps, , Terraform-. , , : .



: Terragrunt , , , .





Terragrunt. , hooks . . , hooks , . - hooks .





. 10 , , autoscaling group, VPC. VPC? 11 , VPC. autoscaling group, public subnet . 20 dependency.vpc.outputs.public_subnets.



, - : Ā« , data-source data-sourceā€™ - state ?Ā». , terraform output. Terragrunt? , (.vpc) terraform outputs.public_subnets. subnets dependency.vpc. vpc_zone_identifier. data-source . .



. 1-in-1, , , , terragrunt apply, , - , Ā«YesĀ» . . terragrunt apply all, , , . : Ā« ?Ā». Ā«Ā». , .



Terragrunt pre-commit. pre-commit hooks Terragrunt , .



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





, Terragrunt, , Terraform Cloud. ? Terragrunt , , .



Terraform Cloud, Terragrunt . Terraform Cloud . , , 0 70 . -, .



, , Terraform Cloud ā€“ , , open source. , enterprise. , open source , shell-. - workspaces. - open source enterprise, .





workspaces?





, Terraform, Terraform apply. , . , - . Ā«Terraform workspaces newĀ» workspace. Ā«Terraform planĀ». Terraform plan : Ā« Ā». . . , workspace, , - workspace. workspace , . 100 .





ā€“ , workspaces . shell-, bucket , .



ā€“ workspaces, . , Terraform.workspaces = prod, 5, 25. , . , 5 environment , , lookup . lookup , Terraform workspaces. , .



: Ā« workspaces ? production QA environment?Ā». : Ā« , slackĀ». . - : Ā« staging production environment ?Ā». .



, , , Terraform . Terraform.tfvars, , . , instances. .



workspaces, . S3_bucket, state .



, . . : Ā« , , workspaces nameĀ». .



workspaces , workspaces ā€“ . . workspaces workspaces shell-, AWS-, , , .



use cases, workspaces . , . , , , .



use cases , , pull request. . . pull request, - workspaces, , -, GitHub. - , , . , workspaces. , , . - . , production environment workspaces.



use cases . , . inmem. workspaces. . . workspaces , - - . , , Terraform state, Terraform backend configuration type inmem ( ). , .





workspaces , , , . , , , workspaces. , workspaces, - . , Feature 1. , terraform apply. , . , terraform destroy.



, , , , .



Terraform workspaces . . , 20 , 10 . workspaces, . .





, , . , Terraform. , , .





Terraform developers . , , DevOps-.



DevOps- Terraform 0.12, . . , , , . ? , , .



DevOps- Terraform developers reference architectures, . , ICS-, 100 , Amazon load balancer, . . . cloud- DevOps- , 100 , , . , , , , , . Terraform-, frontend-, , Terraform. : Ā« , - Ā». , .





Terraform , frontend developer, 0.12 5 , . , , . . Terraform 0.12 ā€“ Terraform developer, .



, full stack developer Terraform. - , , frontend application. , . .





, , . - , , , frontend developer, backend developer, machine learning . . DevOps- , , . .





Modules.tf. ? .





- 2 , , .



. , - - , , .





https://github.com/antonbabenko/modules.tf-lambda



https://github.com/antonbabenko/modules.tf-demo



. , , , , , - .



ā€“ modules.tf.demo.





, Terraform AWS . Terragruntā€™ .





, , . open source .





https://asciinema.org/a/32rkyxIBJ2K4taqZLSlKYNDDI



asciinema.org , .





, , , . Terraform best practices , , Terragrunt.



, , Terraform , . Terragrunt - - .



, , . , , , , open source, , pull requests, issues . .





, , , . , . , . , Amazon. Amazon, . - . , . . 10 , , . . , - close course .



Terraform ā€“ . , Terraform-, . . 99 % Terraform , . . , . .





https://github.com/sponsors/antonbabenko



. . . , Delivery excellence.





! . , Terraform Cloud ā€“ , . Terraform backend. tfstate, . , S3, Diff, , CI. Terraform pipeline. all-in-one, 1-in-1. Terraform depends_on, . . . , Terragrunt . ?



, . , Terraform Cloud , . , open source community, , 99 % Terraform Cloud , . , Atlantis, GitHub-actions. - .



Terraform Cloud, . , , . Remote state Terraform S3.



, , . , Terraform Cloud, Atlantis, Terraform pull request. . . pull request, atlantis plan. Terraform , - Jenkins. AWS forget instance. Terraform plan pull request. .



Atlassian Terraform. Terraform Cloud. . .



.



? , ?



. , , MasterCard REST Provider. , swagger . Terraform- swagger . swagger , swagger , . . - , .



. Amazon, , - issue , , . upload , : Ā« ? ?Ā». - , , Brian . , .



, . , . open source?



Cloudcraft?



.



Cloudcraft ā€“ open source.



. , , , Terraform, AWS. , - AWS. ?



, , , . , , . . . , ? , EC2 instance, 50 : IP-, subnet . . . . - - . . , open source . drowto.io, open source, Cloudcraft, .



! , , . Terraform-. Terraform Helm Charts?



, .



.



. Terraform- Terraform . , provisioning, , shell- ā€“ Terraform. , . Helm Charts . , - . , Helm Terraform, - . , , , . Terraform , . . . Helm, Kubernetes, - , Terraform apply. Terraform apply . .



, . - Helm, . issue Ā«Helm 3 provider TerraformĀ», , - . , -, . .



, Kubernetes- Terraform. , , .



. , - use cases. -, Kubernetes-. , - , . Terraform , , . , Kubernetes, Terraform . .



! . , count output , list map?



. . , - ?



, VPC VPC, - , restrictions security group VPC. list.



, - , , Terraform , , , , . , Terragrunt. . . Terragrunt . . outputā€™ . Terragrant , , . , , .



Terraform, , , Terraform .



, . terraform apply -target , terragrunt apply . , Terragrunt. . . ā€“target , . , , , , , .



, ! all-in-one 1-in-1. , . . AWS. , , AWS, . all-in-one . . Terragrunt, , . ? , ā€“ all-in-one 1-in-1.



, MFA somewhere in between. , , . use cases ā€“ . , 100-500 AM userā€™ . - . all-in-one . all-in-one, 1-in-1 .



And I wanted to show more that there are such ways. There is one way, there is a second way. And you know the advantage of both one and the second way. And then you can come up with a third way, which is somewhere in between. In live projects, I have not met completely all-in-one. If you separate everything to the point of fanaticism, it turns out to be impractical. And it turns out a lot of code that can be grouped.




All Articles