11 Extending Terraform by writing a custom provider

 

This chapter covers

  • Developing a 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 the technology. It demonstrates high-level proficiency and grants you the power to bend Terraform to your will. Nevertheless, even the simplest provider requires a considerable investment of time and effort. When might it be worth writing your own Terraform provider?

Two excellent reasons to write a provider are

  • To wrap a remote API so you can manage your infrastructure as code
  • To expose utility functions to Terraform

Almost all Terraform providers wrap remote APIs because this is what they were designed to do. Recall from chapter 2 that Terraform Core is essentially a glorified state-management engine. Without Terraform providers, Terraform would not know how to provision cloud-based infrastructure. By creating a custom provider, you enable Terraform to manage more and new kinds of resources.

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 Creating a pet resource

11.3.1 Defining Create()

11.3.2 Defining Read()

11.3.3 Defining Update()

11.3.4 Defining Delete()

11.4 Writing acceptance tests

11.4.2 Testing the pet resource

sitemap