Successfully reported this slideshow.
Your SlideShare is downloading. ×

Infrastructure as code, using Terraform

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Loading in …3
×

Check these out next

1 of 30 Ad
Advertisement

More Related Content

Slideshows for you (20)

Similar to Infrastructure as code, using Terraform (20)

Advertisement

Recently uploaded (20)

Infrastructure as code, using Terraform

  1. 1. Infrastructure as code usingTerraform
  2. 2. Hello! I am Harkamal Singh I enjoy AWS, DevOps, Solutions architecture, data analytics I code in Python and Go @harkamals
  3. 3. Stop!  Who are you  Systems, developer, .. languages, favorite code editor  Experience with cloud platforms  Why are you here  It’s a safe zone, so feel free to ask questions anytime
  4. 4. Poll Q: How long does it take to request a virtual machine ? .. and load balancer, database, then deploy application stack .. and repeat it for development, staging, production Put it into perspective  SpaceX launches a rocket every 4 weeks
  5. 5. Agenda  Why  State of things  Terraform  Getting started  Advanced concepts
  6. 6. Why  Build infrastructure automagically  Ensure consistent repeatable deployment  Reuse existing configurations  Increase your productivity  Learn for your job  As a developer, ship complete code to deploy infrastructure stack and the application.  Iterate faster, fail fast.  Stay ahead of the curve
  7. 7. State of things  Current infrastructure deployments  Manually managed  Manually deployed or ad-hoc scripted  No history or context  Only few understand end to end  Out of date runbooks  Configuration drift
  8. 8. State of things  What is Infrastructure as code  Automate creation and maintenance resources (servers, load balancers, volumes, databases, middleware etc.)  Build from source control, no manual changes !!  Ensure testability Infrastructure is described using a high-level configuration syntax. This allows a blueprint of your datacenter to be versioned and treated as you would any other code. Write and execute code to define, deploy and update infrastructure.  Tooling  Terraform, by Hashicorp  Libraries – boto3, fog, apache libcloud  Ansible, chef, puppet,CFengine  AWS Cloud formation
  9. 9. State of things  Imperative  Traditional control flow programming  Build the logic  Python, java, c++, …  Declarative  JSON-like files  Define the outcomes, not how it should be done  Dependency management  Graphing  Immutable; everything is disposable
  10. 10. State of things  DevOps 2017 report  24x faster to recover from failures  50% less time to find issues  200x more deploys  2.2x developer happiness
  11. 11. Enter Terraform  Terraform is a tool for building, changing, and versioning infrastructure safely and efficiently.  As the configuration changes,Terraform is able to determine what changed and create incremental execution plans which can be applied.  Cloud agnostic  JSON like syntax, HCL (.tf file extension)  https://www.terraform.io/docs/configuration/syntax.html  Standalone binary, written in Golang, cross-platform  Leader in Infra-as-code space, 11,000+ stars on github  Open source  Very active development cycle  You can contribute or submit issues, feature requests  https://github.com/hashicorp/terraform
  12. 12. Example: Declarative code #Create a new RHEL74 virtual machine onAWS # https://www.terraform.io/docs/providers/aws/r/instance.html provider "aws” { region = ”eu-west-1" } resource "aws_instance” ”vm1” { ami = "ami-c90195b0" instance_type = "t2.micro" tags { Name = "HelloWorld” costcentre = “307100” } }
  13. 13. Example: Declarative code #Create a new RHEL74 virtual machine onAWS # https://www.terraform.io/docs/providers/aws/r/instance.html provider "aws” { region = ”eu-west-1" } resource "aws_key_pair” “ssh_key” { key_name = "deployer-key" public_key = "ssh-rsa .. 2xwWdhXmXSrbX8ZbabVohBK41" } resource "aws_instance” ”vm1” { ami = "ami-c90195b0" instance_type = "t2.micro” key_name = “${aws_key_pair.ssh_key}” tags { Name = "HelloWorld” costcentre = “307100” } }
  14. 14. Example: Dependency management # https://www.terraform.io/docs/commands/graph.html $ terraform graph
  15. 15. Example: Providers A provider is responsible for understandingAPI interactions and exposing resources. Providers generally are an IaaS (e.g. AWS, GCP, Microsoft Azure, OpenStack), PaaS (e.g. Heroku), or SaaS services (e.g.Terraform Enterprise, DNSimple,CloudFlare). https://www.terraform.io/docs/providers
  16. 16. Demo time! Download terraform: https://www.terraform.io/downloads.html
  17. 17. Terraform: init
  18. 18. Terraform: validate
  19. 19. Terraform: plan
  20. 20. Terraform: apply
  21. 21. Terraform: apply
  22. 22. Terraform: show
  23. 23. AWS console view
  24. 24. Terraform: destroy
  25. 25. AWS console view
  26. 26. IDESupport (optional but essential) IntelliJ, PyCharm: full featured IDE extension for auto-completion, syntax highlighting, code snippets, validation, formatting etc.
  27. 27. AWS billing
  28. 28. Pitfalls
  29. 29. Terraform: advanced topics  State files  Saves current state in a file (s3, consul, etcd, local)  Applies diff from current state to apply changes  Provisioners  Run local or remove scripts as part of resource creation or deletion.  Can be used to bootstrap, cleanup before destroy  Pre-post custom actions  Modules  DRY – don’t repeat yourself  Reuseable, ex: postgres db instance or s3 bucket
  30. 30. What’s next  Terraform is cool, isn’t it !  Learning resources  Terraform – up and running (ebook)  Pluralsight (online training)  https://www.terraform.io/docs/  https://terraformbook.com

×