Category: Terraform, github

I started, for a professional project, to look at how Terraform plugins work so that I could create custom resources using the same Infrastructure as Code base that we already use to provision resources for open-source providers like Kafka. Be careful though, this need appears especially when you want to create and update quasi-static resources that will only require manual action of updating via code and re-provisioning. As described in the diagram above, the provider plugins (or provisioners) communicate with the core of Terraform via gRPC, but this is abstracted by a library that is simple to understand and use.

So before writing our Go code, we can already write the Makefile that will build our binary for our tests and place it in this directory with the correct name: So we will use the following syntax to build our binary and make it ready to use: Let’s now start to write our provider’s code by creating a main.go file that will instantiate the provider plugin that we will name myprovider and by respecting the interfaces provided by the Terraform plugin SDK: Now let’s define the myprovider package by creating the internal/myprovider/provider.go file: The Provider structure provided by the SDK asks us to declare the following resources: For more information, I invite you to have a look at the different types available on this structure: https://pkg.go.dev/github.com/hashicorp/terraform-plugin-sdk/helper/schema?tab=doc#Provider

Here we define several methods that we will use, depending on the state of the state, to create, update, delete or simply read (to refresh the state) our query resource.

Related Articles