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

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

Orlando Del Aguila

December 13, 2016
Tweet

More Decks by Orlando Del Aguila

Other Decks in Programming

Transcript

  1. 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
  2. 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" }
  3. 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. 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. 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. 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. 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. 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}" }
  9. 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}" }
  10. 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}" } ...
  11. 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}" }