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

DevOps RVA Meetup: Terraforming Your Infrastruc...

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.

Roderick Randolph

April 20, 2016
Tweet

More Decks by Roderick Randolph

Other Decks in Technology

Transcript

  1. 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.
  2. Terraform is a tool for building, combining, and versioning infrastructure

    safely and efficiently https://www.terraform.io/intro/index.html
  3. Building… { "resource": { "aws_instance": { "app": { "count": "5",

    "ami": "ami-408c7f28", "instance_type": "t1.micro" } } } } File: main.tf.json
  4. Combining… Terraform is agnostic to the underlying platforms by supporting

    providers. A provider is responsible for understanding API interactions and exposing resources.
  5. 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.
  6. 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.
  7. 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)
  8. 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" }
  9. 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!)
  10. 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
  11. 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