Upgrade to Pro — share decks privately, control downloads, hide ads and more …

DevOps RVA Meetup: Terraforming Your Infrastructure

DevOps RVA Meetup: Terraforming Your Infrastructure

Overview of Hashicorp's Terraform tool. Includes a demo using Terraform to build a Docker Swarm cluster as well as using Terraform to orchestrate the deployment of containers onto the Swarm cluster.

2d9c7a8cdab3ace496e6d4c68ac7ef1c?s=128

Roderick Randolph

April 20, 2016
Tweet

Transcript

  1. Terraforming Your Infrastructure Presented by: Roderick R. Randolph

  2. Who am I • Triple R • Capital One •

    Toronto • Amelia • Dev/Ops Roderick R. Randolph Opinions expressed are solely my own and do not express the views or opinions of my employer.
  3. Agenda • Terraform Overview • Terraform Demo • Docker Swarm

    • NodeJS App • CI/CD pipeline
  4. None
  5. Terraform

  6. None
  7. None
  8. Terraform is a tool for building, combining, and versioning infrastructure

    safely and efficiently https://www.terraform.io/intro/index.html
  9. Hmm, sounds like some other tools…

  10. Terraform is a tool for building, combining, and versioning infrastructure

    safely and efficiently
  11. Terraform is a tool for building, combining, and versioning infrastructure

    safely and efficiently
  12. Building… HashiCorp Configuration Language (HCL) https://github.com/hashicorp/hcl resource "aws_instance" "app" {

    count = 5 ami = "ami-408c7f28" instance_type = "t1.micro" } File: main.tf
  13. Building… { "resource": { "aws_instance": { "app": { "count": "5",

    "ami": "ami-408c7f28", "instance_type": "t1.micro" } } } } File: main.tf.json
  14. Terraform is a tool for building, combining, and versioning infrastructure

    safely and efficiently
  15. Combining… Terraform is agnostic to the underlying platforms by supporting

    providers. A provider is responsible for understanding API interactions and exposing resources.
  16. Terraform is a tool for building, combining, and versioning infrastructure

    safely and efficiently
  17. Versioning… resource "aws_instance" "app" { count = 5 ami =

    "ami-408c7f28" instance_type = "t1.micro" } Infrastructure as Code – Simple configuration files that are versioned, managed, and treated like source code.
  18. Versioning… terraform.tfstate The terraform state file maps various resource metadata

    to actual resource IDs so that Terraform knows what it is managing. This file must be saved and distributed to anyone who might run Terraform.
  19. Terraform is a tool for building, combining, and versioning infrastructure

    safely and efficiently
  20. Safely… $ terraform plan –out my.plan ... ~ aws_autoscaling_group.my_asg load_balancers.#:

    "0" => "1" load_balancers.887959510: "" => "app-elb" + aws_instance.app ami: "" => "ami-08111162" instance_type: "" => "t2.nano" private_ip: "" => "10.0.0.4" -/+ aws_launch_configuration.my_lc image_id: "ami-09831364" => "ami-08111162" (forces new resource)
  21. Safely… $ terraform apply my.plan ... Apply complete! Resources: 1

    added, 1 changed, 1 destroyed.
  22. Terraform is a tool for building, combining, and versioning infrastructure

    safely and efficiently
  23. Efficiently… resource "aws_elb" "frontend" { name = "frontend-load-balancer" listener {

    instance_port = 8000 instance_protocol = "http" lb_port = 80 lb_protocol = "http" } instances = ["${aws_instance.app.*.id}"] } resource "aws_instance" "app" { count = 5 ami = "ami-408c7f28" instance_type = "t1.micro" }
  24. Efficiently… • Resource Graph • Dependency management • Parallelism

  25. Provisioners

  26. Provisioners • Natively supported provisioners • Chef • Connection (establishes

    a raw SSH or WinRM connection) • File • Local Exec (local shell) • Remote Exec (remote SSH / WinRM) • Null Resource • Used to initialize a resource after creation (e.g. invoke a shell script or run a CM tool) • Not a replacement for CM tools (rather complements them!)
  27. Misc • GitHub: 4511 stars / 1310 forks / 452

    contributors / 32 releases • Latest version: v0.6.14 • Usually monthly releases (sometimes semi-monthly) • New features are sometimes added before available via CloudFormation • Terraform also supports CloudFormation as a resource
  28. Demo: Triple R Tracker

  29. Consul Consul Consul Swarm Manager Swarm Manager Swarm Manager p:

    8500 p: 8301 p: 2376 Swarm Node Swarm Node Swarm Node Swarm Node Swarm Node p: 80 tracker.tripler.tech p: 8080 p: 8500 p: 3376 p: 3376 swarm.tripler.tech L L DynamoDB p: 443
  30. Resources • https://www.terraform.io/docs/index.html • https://github.com/dtan4/terraforming • https://buildkite.com/ • https://github.com/roderickrandolph/tripler-tracker