Difficulty: Advanced
Estimated Time: 40

This is the workspace for the Terraform Build a Custom Terraform Provider Workshop and contains the latest version of Terraform CLI and HashiCups provider.

In this workshop, you will modify an existing Terraform provider to add create, read, update and delete (CRUD) functionality to a new resource. This workshop comprises of seven main steps, estimated to take a total of 45 minutes.

  1. Map target resource's data model to a Terraform schema type
  2. Add create functionality to a resource
  3. Add complex read functionality (with flattening functions) to a resource
  4. Add update functionality to a resource
  5. Add delete functionality to a resource
  6. Build provider
  7. Apply configuration with new resource to test implementation

Most of the implementation for each step is provided for you. This workshop and the commented code will guide you to complete the remaining portion of each step.

These sections will start the following in a code comment.

\\ ** |

By the end of this workshop, you should understand how to use the Terraform Plugin SDK v2 to map target APIs to Terraform to create, read, update and delete (CRUD) resources.

Congrats you've completed this guide!

In this tutorial, you created, read, updated, and deleted an order resource in HashiCorp's demo application. In the process, you've learned how Terraform interacts with target APIs via providers.

A full list of official, partner and community Terraform providers can be found on the Terraform Provider Registry. We encourage you to find a provider you're interested in and experiment!

To learn how to recreate the HashiCups provider, visit our Learn Providers Collection.

To learn more about provider source, refer to Automatic Installation of Third-Party Providers with Terraform 0.13 blog post.

To learn more about interpolation, refer to the Configuration Language documentation.

HashiConf Digital: Build a Custom Terraform Provider Workshop

Step 1 of 8

Overview

In this workshop, you will add functionality to create, read, update and delete a HashiCups order using a Terraform provider.

This workspace is an Ubuntu image with Terraform 0.15, Go, and a custom environment containing code for the HashiCups provider.

Explore your development environment

Your development environment contains the following.

  • The Makefile file contains helper functions used to build, package and install the HashiCups provider. The OS_ARCH is linux_amd64, which matches the katacoda workspace you are building.
  • The docker_compose directory contains the files required to initialize a local instance of HashiCups.
  • The examples directory contains sample Terraform configuration that can be used to test the HashiCups provider.
  • The main.go file is the provider's entry point. You will compile this file into a valid, executable Go binary that Terraform Core can consume.
  • The hashicups directory contains the main provider code. This will be where the provider's resources and data source implementations will be defined.
    • hashicups/resource_order.go defines resourceOrder() and contains boilerplate and comments to guide you through adding CRUD capabilities to an existing provider.

Katacoda Notes

  • Any changes to the file using the file editor will be automatically saved.
  • To format your code, run go fmt ./... then close and reopen your file.
  • Clicking on code snippets with a Copy to Editor command will automatically add the code snippet to the correct spot in the file. Use this to speed up your implementation process.
  • Click on KataCoda commands to run them automatically in your terminal.