Infrastructure as Code with Terraform

Infrastructure as Code with Terraform

A short intro to Infrastructure as Code using terraform. Talk for GDLJS https://www.meetup.com/Guadalajara-JS/events/236104692/.

Repo with example at https://github.com/orlando/terraform-intro

A0574e5093df6afd68f1c109c5a9bf22?s=128

Orlando Del Aguila

December 13, 2016
Tweet

Transcript

  1. 7.
  2. 15.

    2016 DevOps Report* IAC / Why • 24x faster to

    recover from failure • 50% less time to find issues • 200x more deploys • 2.2x engineer happiness** ** Likeliness to recommend their place of work to others * puppet.com/resources/white-paper/2016-state-of-devops-report
  3. 27.

    Terraform / Syntax data "aws_ami" "ubuntu" { most_recent = true

    filter { name = "name" values = ["ubuntu/images/hvm-ssd/ubuntu-trusty-*"] } } resource "aws_instance" "example" { ami = "${data.aws_ami.ubuntu.id}" instance_type = "t2.micro" }
  4. 28.

    Terraform / Syntax data "aws_ami" "ubuntu" { most_recent = true

    filter { name = "name" values = [“ubuntu/images/hvm-ssd/ubuntu-trusty-*"] } } resource "aws_instance" "example" { ami = "${data.aws_ami.ubuntu.id}" instance_type = "t2.micro" }
  5. 29.

    Terraform / Syntax data "aws_ami" "ubuntu" { most_recent = true

    filter { name = "name" values = [“ubuntu/images/hvm-ssd/ubuntu-trusty-*"] } } resource "aws_instance" "example" { ami = "${data.aws_ami.ubuntu.id}" instance_type = "t2.micro" }
  6. 30.

    Terraform / Syntax data "aws_ami" "ubuntu" { most_recent = true

    filter { name = "name" values = [“ubuntu/images/hvm-ssd/ubuntu-trusty-*"] } } resource "aws_instance" "example" { ami = "${data.aws_ami.ubuntu.id}" instance_type = "t2.micro" }
  7. 31.

    Terraform / Syntax data "aws_ami" "ubuntu" { most_recent = true

    filter { name = "name" values = [“ubuntu/images/hvm-ssd/ubuntu-trusty-*"] } } resource "aws_instance" "example" { ami = "${data.aws_ami.ubuntu.id}" instance_type = "t2.micro" }
  8. 32.

    Terraform / Syntax data "aws_ami" "ubuntu" { most_recent = true

    filter { name = "name" values = [“ubuntu/images/hvm-ssd/ubuntu-trusty-*"] } } resource "aws_instance" "example" { ami = "${data.aws_ami.ubuntu.id}" instance_type = "t2.micro" }
  9. 33.

    Terraform / Syntax data "aws_ami" "ubuntu" { most_recent = true

    filter { name = "name" values = [“ubuntu/images/hvm-ssd/ubuntu-trusty-*"] } } resource "aws_instance" "example" { ami = "${data.aws_ami.ubuntu.id}" instance_type = "t2.micro" } resource "aws_eip" "example_eip" { instance = "${aws_instance.example.id}" }
  10. 34.

    Terraform / Syntax data "aws_ami" "ubuntu" { most_recent = true

    filter { name = "name" values = [“ubuntu/images/hvm-ssd/ubuntu-trusty-*"] } } resource "aws_instance" "example" { ami = "${data.aws_ami.ubuntu.id}" instance_type = "t2.micro" } resource "aws_eip" "example_eip" { instance = "${aws_instance.example.id}" } // IP of the Bastion EC2 instance output "ip" { value = "${aws_eip.example_eip.public_ip}" }
  11. 35.

    Terraform / Syntax ... variable "instance_type" { description = "EC2

    instance type" default = "t2.nano" } resource "aws_instance" "example" { ami = "${data.aws_ami.ubuntu.id}" instance_type = "${var.instance_type}" } ...
  12. 36.

    Terraform / Syntax / Modules # Create instances module "t2nano"

    { source = "./aws_instance" instance_type = "t2.nano" } module "t2micro" { source = "./aws_instance" instance_type = "t2.micro" } # Output variables output "t2microip" { value = "${module.t2micro.ip}" } output "t2small" { value = "${module.t2small.ip}" }
  13. 39.