11 Extending Terraform by Writing Your Own Provider

 

This chapter covers:

  • Developing a custom Terraform provider from scratch
  • Implementing CRUD operations for managed resources
  • Writing acceptance tests for the provider schema and resource files
  • Deploying a serverless API to listen to requests from the provider
  • Building and installing third-party providers

Extending Terraform by writing your own provider is one of the most satisfying things you can do with Terraform. It demonstrates a high-level proficiency with the technology and grants considerable flexibility to tweak Terraform to your needs. Although it’s not as challenging as some people make it out to be, it still a huge investment in time and effort. When might it be worth it to develop your own custom provider?

Two good reasons are:

  1. Wrapping an API for self-service infrastructure provisioning
  2. Exposing utility functions to Terraform

11.1  Blueprints for a Terraform Provider

11.1.1    Terraform Provider Basics

11.1.2    Petstore Provider Architecture

11.2  Writing the Petstore Provider

11.2.1    Setting up the Go Project

11.2.2    Configuring the Provider Schema

11.3  Defining a Pet Resource

11.3.4    Defining Delete() – CRUD Lifecycle Management

11.4.2    Testing the Pet Resource

11.5  Build, Test, Deploy

11.5.1    Deploy the Petstore API

11.5.2    Test and Build the Provider

11.6  Fireside Chat

11.7          Summary