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

Terraform Anything with Custom Providers in Go

Terraform Anything with Custom Providers in Go

Originally presented at the Phoenix Golang Meetup
https://www.meetup.com/Golang-Phoenix/events/263762398/

Terraform is typically used by DevOps teams to provision infrastructure from code. Its modular design allows it to interact with any system by writing a little bit of Go.

Resources:
https://www.terraform.io/docs/extend/writing-custom-providers.html
https://www.terraform.io/docs/configuration/providers.html#third-party-plugins
https://github.com/ChristianAlexander/Example-AWS-Terraform-Environment
https://github.com/ChristianAlexander/terraform-provider-slack
https://api.slack.com/custom-integrations/legacy-tokens

Slide Notes:

6
Terraform has three main operations.
Plan shows what would happen
Apply performs the plan
Destroy tears down all managed resources (from state)

7
Let’s say you want to build something like this
There are a ton of steps, each of which would be done by ops manually (error-prone, not peer-reviewed, not scalable)

8
It’s hard to keep track and properly build. Begins to feel like one of these things.

9
Cloud misconfiguration happens in the wild. It's costly.

11
https://github.com/ChristianAlexander/Example-AWS-Terraform-Environment
terraform apply
Show instance https://us-west-1.console.aws.amazon.com/ec2/v2/home?region=us-west-1
Update SSH config with the plan output
SSH via public (bastion) instance

12
Modules and variables as inputs
Modules are just directories with .tf files in them
APIs called on your behalf
State is produced and tracked
Outputs are displayed

15
A provider is responsible for understanding API interactions and exposing resources.
https://www.terraform.io/docs/providers/

16
A data source is something to look up, usually from an API
Example: the latest Ubuntu 14.04 Amazon Machine Image
https://www.terraform.io/docs/providers/aws/d/ami.html

17
A resource is something managed by Terraform.
Example: an AWS EC2 instance
https://www.terraform.io/docs/providers/aws/d/instance.html

20
Plugins listed by HashiCorp are pulled automatically on terraform init
Community and custom providers have to be placed in a special directory
(System-level installation is possible)

23
Originally set out to (and built) a provider to list and upload to another workspace
Slack broke the (undocumented) method I used to upload.
https://github.com/christianalexander/terraform-provider-slack

24
New goal: list all emoji in a workspace and expose them as routes on an ALB.

26
Terraform could be used to expose your company’s APIs
Employees requesting access to resources as PRs (reviewable, auditable)
Legacy shell scripts and things that one person has on their machine can be centralized
Or literally anything else…

27
Go out there and Terraform all the things.
The more providers there are, the more powerful the tool is (like IFTTT)

Christian Alexander

August 27, 2019
Tweet

Other Decks in Programming

Transcript

  1. VPC Subnet B Subnet A Private Instance Public Instance Internet

    Gateway Route Table Me Not Me 1 2 3 4 5 6 7 8 9
  2. Goal ALB If /300 redirect to emoji.slack-edge.com/... If /dogeparrot redirect

    to emoji.slack-edge.com/... If /scienceparrot redirect to emoji.slack-edge.com/... …