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

Terraform All The Things!

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest. →
Brian Hicks
December 05, 2016

Terraform All The Things!

Brian Hicks

December 05, 2016

Transcript

31 slides
  1. Hello I'm Brian Hicks I do cloud stuff [email protected] //

    @brianhicks 2 — St. Louis DevOps Meetup
  2. Provider: AWS provider "aws" { access_key = "AKIAMICJAGGER" secret_key =

    "gotthemoves/likejagger/scary" region = "us-east-1" } 14 — St. Louis DevOps Meetup
  3. Resource: AWS Key Pair resource "aws_key_pair" "brian" { key_name =

    "brian-hicks-is-the-coolest" public_key = "${file("~/.ssh/id_rsa.pub")}" } 15 — St. Louis DevOps Meetup
  4. Resource: AWS Instance resource "aws_instance" "web" { ami = "${data.aws_ami.ubuntu.id}"

    instance_type = "t2.micro" key_name = "${aws_key_pair.brian.key_name}" tags { Name = "web" } count = 3 } 16 — St. Louis DevOps Meetup
  5. Data: AMI ID data "aws_ami" "ubuntu" { most_recent = true

    filter { name = "name" values = ["ubuntu/images/hvm-ssd/ubuntu-trusty-14.04-amd64-server-*"] } filter { name = "virtualization-type" values = ["hvm"] } owners = ["099720109477"] # Canonical } 17 — St. Louis DevOps Meetup
  6. Resource: AWS ELB resource "aws_elb" "web" { name = "web"

    instances = ["${aws_instance.web.*.id}"] availability_zones = ["us-east-1b", "us-east-1c", "us-east-1d"] listener { instance_port = 80 instance_protocol = "http" lb_port = 80 lb_protocol = "http" } } 18 — St. Louis DevOps Meetup
  7. Terraform Plan (Before) + aws_instance.web.0 ami: "ami-1081b807" associate_public_ip_address: "<computed>" availability_zone:

    "<computed>" instance_state: "<computed>" instance_type: "t2.micro" key_name: "brian-hicks-is-the-coolest" network_interface_id: "<computed>" placement_group: "<computed>" private_dns: "<computed>" private_ip: "<computed>" public_dns: "<computed>" public_ip: "<computed>" source_dest_check: "true" tags.%: "1" tags.Name: "web" 20 — St. Louis DevOps Meetup
  8. Terraform Plan (Before) + aws_elb.web availability_zones.#: "3" availability_zones.1305112097: "us-east-1b" availability_zones.2762590996:

    "us-east-1d" availability_zones.986537655: "us-east-1c" cross_zone_load_balancing: "true" dns_name: "<computed>" health_check.#: "<computed>" idle_timeout: "60" listener.#: "1" listener.3057123346.instance_port: "80" listener.3057123346.instance_protocol: "http" listener.3057123346.lb_port: "80" listener.3057123346.lb_protocol: "http" listener.3057123346.ssl_certificate_id: "" name: "web" 21 — St. Louis DevOps Meetup
  9. Terraform Apply (the highlights) aws_instance.web.2: Still creating... (10s elapsed) aws_instance.web.1:

    Still creating... (10s elapsed) aws_instance.web.0: Still creating... (10s elapsed) aws_instance.web.0: Still creating... (20s elapsed) aws_instance.web.2: Still creating... (20s elapsed) aws_instance.web.1: Still creating... (20s elapsed) aws_instance.web.0: Still creating... (30s elapsed) aws_instance.web.2: Still creating... (30s elapsed) aws_instance.web.1: Still creating... (30s elapsed) aws_instance.web.1: Creation complete aws_instance.web.2: Creation complete aws_instance.web.0: Creation complete 22 — St. Louis DevOps Meetup
  10. Terraform Plan (After) Refreshing Terraform state in-memory prior to plan...

    The refreshed state will be used to calculate this plan, but will not be persisted to local or remote state storage. aws_key_pair.brian: Refreshing state... (ID: brian-hicks-is-the-coolest) data.aws_ami.ubuntu: Refreshing state... aws_instance.web.0: Refreshing state... (ID: i-8e08c999) aws_instance.web.1: Refreshing state... (ID: i-8d08c99a) aws_instance.web.2: Refreshing state... (ID: i-f908c9ee) aws_elb.web: Refreshing state... (ID: web) No changes. Infrastructure is up-to-date. This means that Terraform could not detect any differences between your configuration and the real physical resources that exist. As a result, Terraform doesn't need to do anything. 23 — St. Louis DevOps Meetup
  11. CloudFlare resource "cloudflare_record" "cats" { domain = "brianthicks.com" name =

    "cats" type = "CNAME" value = "${aws_elb.web.dns_name}" } 25 — St. Louis DevOps Meetup
  12. CloudFlare (plan) + cloudflare_record.cats domain: "brianthicks.com" hostname: "<computed>" name: "cats"

    proxied: "false" ttl: "<computed>" type: "CNAME" value: "web-336570990.us-east-1.elb.amazonaws.com" zone_id: "<computed>" 26 — St. Louis DevOps Meetup
  13. Problems, and Their Solutions → State files -> Back up

    terraform.tfstate → Adding independent resources -> terraform import → Organization -> modules 29 — St. Louis DevOps Meetup

More Decks by Brian Hicks

Other Decks in Technology