using terraform.io (human talks montpellier, epitech, 2014/09/09)

49
Using Terraform.io Build & Change an Infrastructure with Terraform 2014/09/09

Upload: stephane-jourdan

Post on 29-Nov-2014

789 views

Category:

Engineering


4 download

DESCRIPTION

How to build an infrastructure & handle change with Hashicorp's Terraform. The talk was "distributed teams" oriented.

TRANSCRIPT

Page 1: Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)

Using Terraform.ioBuild & Change an Infrastructure with Terraform 2014/09/09

Page 2: Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)

`whoami`

@sjourdan

@greenalto

Page 3: Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)

Vagrant?

Page 4: Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)

Vagrant

For development environments

Page 5: Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)

Vagrant

Mimic production environments

Page 6: Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)

Vagrant

!sharing

!durability

!evolution

!services

!production

Page 7: Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)

Terraform

Page 8: Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)

Terraform

Infrastructure?

servers, VMs (EC2, DigitalOcean…)

services (Heroku, ELB, EIP…)

DNS (DNSimple,…)

email (Mailgun…)

Page 9: Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)

Terraform

Page 10: Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)

Terraform

Page 11: Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)

Terraform

APIs

Page 12: Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)

Terraform

Page 13: Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)

Terraform

Launch infrastructure

Change infrastructure

Page 14: Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)

Terraform

Simple file based configuration

Page 15: Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)

5 days since CoreOS on DO

Page 16: Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)

Terraform

resource "digitalocean_droplet" "coreos-1" {

}

Page 17: Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)

Terraform

resource "digitalocean_droplet" "coreos-1" {

name = “coreos-1”

}

Page 18: Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)

Terraform

resource "digitalocean_droplet" "coreos-1" {

name = “coreos-1”

size = "512mb"

}

Page 19: Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)

Terraform

resource "digitalocean_droplet" "coreos-1" {

name = “coreos-1”

size = “512mb"

image = "coreos-alpha"

}

Page 20: Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)

Terraform

resource "digitalocean_droplet" "coreos-1" {

name = “coreos-1”

size = “512mb"

image = “coreos-alpha"

region = "nyc3"

}

Page 21: Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)

Terraformresource "digitalocean_droplet" "coreos-1" {

name = “coreos-1”

size = “512mb"

image = “coreos-alpha"

region = “nyc3"

private_networking = true

}

Page 22: Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)

Terraformresource "digitalocean_droplet" "coreos-1" {

name = “coreos-1”

size = “512mb"

image = “coreos-alpha"

region = “nyc3"

private_networking = true

ssh_keys = [ "131228" ]

}

Page 23: Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)

Terraform

$ terraform apply

Page 24: Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)

Terraform$ terraform apply digitalocean_droplet.ht-coreos-1: Creating... image: "" => "coreos-alpha" name: "" => "ht-coreos-1" private_networking: "" => "true" region: "" => "nyc3" size: "" => "512mb" ssh_keys.#: "" => "1" ssh_keys.0: "" => "131228" digitalocean_droplet.ht-coreos-1: Creation complete !Apply complete! Resources: 1 added, 0 changed, 0 destroyed. !The state of your infrastructure has been saved to the path below. This state is required to modify and destroy your infrastructure, so keep it safe. To inspect the complete state use the `terraform show` command. !State path: terraform.tfstate

Page 25: Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)

Terraform

$ terraform show terraform.tfstate

Page 26: Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)

Terraform$ terraform show terraform.tfstate digitalocean_droplet.ht-coreos-1: id = 2574081 image = coreos-alpha ipv4_address = 104.131.47.30 ipv4_address_private = 10.132.241.137 locked = false name = ht-coreos-1 private_networking = true region = nyc3 size = 512mb ssh_keys.# = 1 ssh_keys.0 = 131228 status = active

Page 27: Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)

Terraform

Page 28: Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)

Terraform

Scale? Handle Change?

Page 29: Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)

Terraform

Page 30: Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)

Terraform

$ terraform plan

Page 31: Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)

Terraform

$ terraform plan -out=terraform.plan !

+ digitalocean_droplet.ht-coreos-2 !

[…] !

+ digitalocean_droplet.ht-coreos-3 […]

Page 32: Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)

Terraform$ terraform apply digitalocean_droplet.ht-coreos-1: Refreshing state... (ID: 2574081) digitalocean_droplet.ht-coreos-2: Creating... […] digitalocean_droplet.ht-coreos-3: Creating... […] digitalocean_droplet.ht-coreos-3: Creation complete digitalocean_droplet.ht-coreos-2: Creation complete !Apply complete! Resources: 2 added, 0 changed, 0 destroyed.

Page 33: Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)

Terraform

Page 34: Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)

Terraform

Downscale ?

Page 35: Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)

Terraform

$ terraform plan -out=terraform.plan !

[…] - digitalocean_droplet.ht-coreos-1

Page 36: Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)

Terraform$ terraform apply digitalocean_droplet.ht-coreos-1: Refreshing state... (ID: 2574081) digitalocean_droplet.ht-coreos-3: Refreshing state... (ID: 2574214) digitalocean_droplet.ht-coreos-2: Refreshing state... (ID: 2574215) digitalocean_droplet.ht-coreos-1: Destroying... digitalocean_droplet.ht-coreos-1: Destruction complete !Apply complete! Resources: 0 added, 0 changed, 1 destroyed.

Page 37: Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)

Terraform

Page 38: Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)

Terraform

Page 39: Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)

Terraform

terraform.tfstate

=> git pull your infrastructure state!

Page 40: Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)

Terraform

Page 41: Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)

Terraform

Page 42: Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)

Terraform

Provisionners

echo, cat or grep

myapp.conf

Chef, Puppet, Ansible, whatever

Page 43: Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)

Terraform

provisioner "remote-exec" { inline = [ "curl -L https://www.opscode.com/chef/install.sh | sudo bash", "sudo chef-solo -j chef/node.json" ] }

Page 44: Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)

Terraform

resource "dnsimple_record" “cluster-1" { domain = “humantalks.com" name = "cluster-1" value = “${digitalocean_droplet.web.ipv4_address}" type = "A" }

Page 45: Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)

Terraform

autoscaling_group db_instance security_group eip elb instance route53 s3 …

Page 46: Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)

Terraform (Sept. 2014)

Page 47: Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)

Terraform

2014/07/28: 0.1.0

2014/08/28: 0.2.0

Page 48: Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)

Terraform

https://github.com/hashicorp/terraform/

http://www.terraform.io/

Page 49: Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)

Q&A

Questions ?