Terraform is an infrastructure as code tool that lets you build, change, and version infrastructure safely and efficiently. Terraform providers, written in Go, allow you to manage infrastructure as code, and if you have an infrastructure API, allow your customers to deploy and manage their infrastructure on your platform.
liblab can generate a Terraform provider from your API. You can also enhance the generated SDK with custom code, including hooks and plan modifiers to add custom functionality to your provider.
Requirements to generate a Terraform provider
To generate a Terraform provider, you will need:
Annotated API spec
liblab uses API specifications in a variety of formats to generate SDKs. For Terraform providers, these specs need to be annotated with additional information so that the provider can know what endpoints provide resources and actions, and data sources.
You can read more about these annotations, along with other supported Terraform annotations, in the API spec annotations guide.
liblab config file
The liblab config file tells liblab how to generate the Terraform provider. You can read more about the config file in the liblab config file guide.
To generate a Terraform provider, you will need to include the
terraform value in the
languages section of your config file:
You will also need to configure the Terraform language options section:
The Terraform provider uses a Go SDK under the hood, so you will also need to provide a Go module name for this underlying SDK. This is set in the Go language options:
The Terraform provider uses an internal Go SDK, but you do not need to list
go in the
languages section of your config file to create a Terraform provider. Adding the
go language will also generate a Go SDK in the
output folder the same as any other language.
If you generate a Go SDK as well as the Terraform provider, both the Go SDK and the internal Go SDK used by the Terraform provider will share the same Go module name, set in the Go language options.
Generate a Terraform provider
Once you have your annotated API spec and config file, you can generate a Terraform provider using the
liblab build command in the same way as any other SDK:
The generated Terraform provider will be in the
output folder, in a folder called
README.md file created in that folder will contain the instructions to configure and use the provider.