Terraform Colonise the cloud! Stefan Magnus Landr, BEKK Consulting - - PowerPoint PPT Presentation

terraform
SMART_READER_LITE
LIVE PREVIEW

Terraform Colonise the cloud! Stefan Magnus Landr, BEKK Consulting - - PowerPoint PPT Presentation

Terraform Colonise the cloud! Stefan Magnus Landr, BEKK Consulting AS ApacheCon North America 2017 - 17. May 2017 1 Terraform Commandline tool (go) (OS X, Windows, Linux, ) Developed by Hashicorp (Vagrant, Packer, Consul, Nomad)


slide-1
SLIDE 1

Terraform

Colonise the cloud!

Stefan Magnus Landrø, BEKK Consulting AS

ApacheCon North America 2017 - 17. May 2017 1
slide-2
SLIDE 2

Terraform

  • Commandline tool (go) (OS X, Windows, Linux, …)
  • Developed by Hashicorp (Vagrant, Packer, Consul, Nomad)
  • Lets you describe and provision cloud infrastructure using

HCL formatted text files

  • Servers, networks, load balancing, storage, containers
  • Multi-provider (AWS, Azure, GC, Cloudstack, …)
ApacheCon North America 2017 - 17. May 2017 2
slide-3
SLIDE 3

Demo

  • CloudStack @ Exoscale (Switzerland)
  • Web servers (CentOS/Linux)
  • Bastion host for management/provisioning
  • SSH public/private key
  • Run Apache httpd web server
  • Domain name (DNS) (AWS)
ApacheCon North America 2017 - 17. May 2017 3
slide-4
SLIDE 4

Provider (1)

  • A provider is used to connect to a cloud provider
  • AWS, Azure, GC, Digital Ocean, Cloudstack, Openstack,

Heroku, CloudFoundry, Mailgun, easyDNS, CloudFlare…

  • Providers know the APIs and expose available services
ApacheCon North America 2017 - 17. May 2017 4
slide-5
SLIDE 5

Resource (2)

  • A resource defines how to use a cloud resource/service
  • VM, IP-address, load balancer, network, firewall, object

storage, DNS-record

  • The name of the provider is used as a resource name prefix
  • Resources have unique ids
  • Combination of resource type and name
ApacheCon North America 2017 - 17. May 2017 5
slide-6
SLIDE 6

Dependencies (3)

  • A resource can depend on another resource
  • Can determine the order of creation
ApacheCon North America 2017 - 17. May 2017 6
slide-7
SLIDE 7

terraform show

  • When manipulating resources, Terraform saves the current

state i a .tfstate file (or S3, Consul)

  • Knows a resource's current state in the cloud

terraform show

ApacheCon North America 2017 - 17. May 2017 7
slide-8
SLIDE 8

Syntax (4)

  • Variables
  • Interpolation
  • Functions (math, base64, join, lower, ...)
  • Count
ApacheCon North America 2017 - 17. May 2017 8
slide-9
SLIDE 9

provisioner (5)

  • A provisioner lets you provision against the resource right

after creation

  • chef
  • remote-exec (script run on the server)
  • local-exec (script run locally)
ApacheCon North America 2017 - 17. May 2017 9
slide-10
SLIDE 10

terraform taint

  • When resources have to be recreated from scratch, they

have to be tainted

terraform taint <resource_type>.<resource_id>

ApacheCon North America 2017 - 17. May 2017 10
slide-11
SLIDE 11

Security first! (6)

  • Connect to you web server through bastion host
  • Limit access to bastion host to your IP range
  • Use smart card to protect your private key
  • E.g. yubikey as OpenPGP smartcard and gpg-agent

emulating ssh-agent

ApacheCon North America 2017 - 17. May 2017 11
slide-12
SLIDE 12 ApacheCon North America 2017 - 17. May 2017 12
slide-13
SLIDE 13
  • utput (7)
  • Outputs lets you define values that will be output when

Terraform applies

  • Can be queried easily:

terraform output [-json]

ApacheCon North America 2017 - 17. May 2017 13
slide-14
SLIDE 14

Multi-provider (8)

  • Can connect resources from different cloud providers
  • Unique feature in Terraform!
ApacheCon North America 2017 - 17. May 2017 14
slide-15
SLIDE 15

Multi provider, multi datacenter, multi technology (9)

  • DNS using weighted record set
  • Could have used latency / geolocation
  • Health checks to determine data center (or service) outage
ApacheCon North America 2017 - 17. May 2017 15
slide-16
SLIDE 16

Bonus: Dependency graph

  • Dependency graphs can be generated dynamically

terraform graph | dot -Tpng | open -f -a Preview

ApacheCon North America 2017 - 17. May 2017 16
slide-17
SLIDE 17

Summary

  • Terraform is great for defining infrastructure as code
  • Perform incremental changes to your infrastructure
  • Can combine several cloud providers in your infrastructure

github.com/landro @landro

ApacheCon North America 2017 - 17. May 2017 17