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.

Rosemary Wang

October 14, 2019
Tweet

More Decks by Rosemary Wang

Other Decks in Technology

Transcript

  1. 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
  2. “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
  3. “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
  4. 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
  5. 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
  6. TERMINAL + resource will be created
 - resource will be

    destroyed
 ~ resource will be updated in-place
 -/+ resources will be destroyed and re-created 16
  7. 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!
  8. 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"] }
  9. 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
  10. 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)