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

Everything-as-Code with Terraform

Everything-as-Code with Terraform

All Things Open, 2019.

Terraform is an Infrastructure as Code tool for declaratively building and maintaining complex infrastructures on one or more cloud providers/services. But Terraform also supports over 80 non-infrastructure providers! In this demo-driven talk, will dive into the internals of Terraform and see how it works. We will show how Terraform can be used for non-infrastructure use cases by showing examples. We’ll also take a look at on how you can extend Terraform to manage anything with an API.

Be8b596c46f4c9a1aec6a7586af33134?s=128

Rosemary Wang

October 14, 2019
Tweet

More Decks by Rosemary Wang

Other Decks in Technology

Transcript

  1. Copyright © 2019 HashiCorp Everything as Code with Terraform All

    Things Open | October 14, 2019
  2. None
  3. None
  4. “I can’t stand using this interface to paste all of

    these code snippets.”
  5. (Actually 2 years, ~20 blogs, and slightly more wisdom later…)

  6. “Oh, I can build a Terraform provider that reads Markdown

    and sends it up to Medium.”
  7. “Blog-as-Code”

  8. Agenda Infrastructure-as-Code Terraforming the Datacenter Extending Terraform Writing a Provider

    Everything-as-Code Or Get Close 8
  9. hashi.co/2019-ato

  10. Infrastructure-as-Code Terraforming the Datacenter 10

  11. Infrastructure-as-Code Goals ▪ Unify the view of resources ▪ Support

    the modern data center (IaaS, PaaS, SaaS) ▪ Expose a way for individuals and teams to safely and predictably change infrastructure ▪ Provide a workflow that is technology agnostic ▪ Manage anything with an API 11
  12. “I don’t know how to code. But I do want

    to automate how I configure my infrastructure.” - An Infrastructure Engineer Who Started Using Public Cloud 12
  13. “It was hard enough for me to learn infrastructure terms

    but writing code for it too? Difficult.” - A Developer Who Started Using Public Cloud 13
  14. Terraform HashiCorp Configuration Language CODE EDITOR resource "google_compute_instance" "default" {

    name = "test" machine_type = "n1-standard-1" zone = "us-central1-a" tags = ["foo", "bar"] boot_disk { initialize_params { image = "debian-cloud/debian-9" } } // Local SSD disk scratch_disk { } network_interface { network = "default" access_config { // Ephemeral IP } 14
  15. Extensible & Idempotent CODE EDITOR resource "datadog_monitor" "foo" { name

    = "Name for monitor foo" type = "metric alert" message = "Monitor triggered. Notify: @hipchat- channel" escalation_message = "Escalation message @pagerduty" query = "avg(last_1h):avg:aws.ec2.cpu{environment:foo,host:foo} by {host} > 4" thresholds = { ok = 0 warning = 2 warning_recovery = 1 critical = 4 critical_recovery = 3 } notify_no_data = false renotify_interval = 60 15
  16. TERMINAL + resource will be created
 - resource will be

    destroyed
 ~ resource will be updated in-place
 -/+ resources will be destroyed and re-created 16
  17. Infrastructure-as-Code github.com/joatmon08/2019-demo-ato

  18. 18 terraform.io/docs/providers/

  19. Extending Terraform Writing a Provider 19

  20. terraform.io/docs/extend/how-terraform-works.html

  21. Let’s build a provider. github.com/joatmon08/2019-demo-ato

  22. Useful Resources ▪ Writing Custom Providers - official documentation ▪

    Plugin SDK - now officially separated from core ▪ Creating a Terraform Provider for Just About Anything by Eddie Zanewski ▪ Check out other providers like AWS or GCP!
  23. Everything-as-Code Or Get Close 23

  24. Terraform Provider for Medium github.com/joatmon08/ terraform-provider- medium CODE EDITOR resource

    "medium_image" "draft" { file_path = "./images/draft.png" content_type = "image/png" } resource "medium_post" "my-post" { title = "Writing a Terraform Medium Provider" content = templatefile("./ content.md", { image_url = medium_image.draft.url }) content_format = "markdown" publish_status = "draft" tags = ["terraform", "medium", "automation"] }
  25. Tips for Building _______-as-Code ▪ Non-ideal upstream APIs – Read-only

    provider – Write your own client ▪ Testing – Express functionality in acceptance tests – Examine interface changes with contract tests
  26. Alerts-as-Code? Datadog Grafana PagerDuty To Do-as-Code? Google Calendar G Suite

    Todoist
 (link) Life-as-Code? Meetup 
 (community-as-code)
 Domino’s Pizza
 (pizza-as-code)
 Pokémon
 (catch 'em-all-as-code)
  27. “I like your blog but we don’t speak much English.

    Do you have translations?” 27
  28. None
  29. Translated Blog-as-Code github.com/joatmon08/2019-demo-ato

  30. “Doing Better”-through-Code 30

  31. speakerdeck.com/joatmon08/everything-as-code-with-terraform Rosemary Wang (she/her) Developer Advocate at HashiCorp @joatmon08 joatmon08

    linkedin.com/in/rosemarywang/ 31