Copyright © 2019 HashiCorp
Everything as Code with
Terraform
All Things Open | October 14, 2019
“I can’t stand using this interface to
paste all of these code snippets.”
(Actually 2 years, ~20 blogs, and slightly more wisdom later…)
“Oh, I can build a Terraform provider that
reads Markdown and sends it up to
Medium.”
“Blog-as-Code”
Agenda Infrastructure-as-Code
Terraforming the Datacenter
Extending Terraform
Writing a Provider
Everything-as-Code
Or Get Close
8
hashi.co/2019-ato
Infrastructure-as-Code
Terraforming the Datacenter
10
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
“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
“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
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
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
TERMINAL
+ resource will be created

- resource will be destroyed

~ resource will be updated in-place

-/+ resources will be destroyed and re-created
16
Infrastructure-as-Code
github.com/joatmon08/2019-demo-ato
18
terraform.io/docs/providers/
Extending Terraform
Writing a Provider
19
terraform.io/docs/extend/how-terraform-works.html
Let’s build a provider.
github.com/joatmon08/2019-demo-ato
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!
Everything-as-Code
Or Get Close
23
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"]
}
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
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)
“I like your blog but we don’t speak
much English.
Do you have translations?”
27
Translated Blog-as-Code
github.com/joatmon08/2019-demo-ato
“Doing Better”-through-Code
30
speakerdeck.com/joatmon08/everything-as-code-with-terraform
Rosemary Wang (she/her)
Developer Advocate at HashiCorp
@joatmon08
joatmon08
linkedin.com/in/rosemarywang/
31

Everything as Code with Terraform