10 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

10.1       Blueprints for a Terraform Provider

10.1.1    Terraform Provider Basics

10.1.2    Petstore Provider Architecture

10.2       Writing the Petstore Provider

10.2.1    Setting up the Go Project

10.2.2    Configuring the Provider Schema

10.3       Defining a Pet Resource

10.3.1    Defining Create() – CRUD Lifecycle Management

10.3.2   Defining Read() – CRUD Lifecycle Management

10.3.3   Defining Update() – CRUD Lifecycle Management

10.3.4    Defining Delete() – CRUD Lifecycle Management

10.4.1   Testing the Provider Schema

10.4.2    Testing the Pet Resource

10.5       Build, Test, Deploy

10.5.1    Deploy the Petstore API

10.5.2    Test and Build the Provider

10.6       Fireside Chat

10.7       Summary