Skip to main content

Terraform provider overview

terraform logo terraform logo

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.

Resources need to be annotated with the x-liblab-resource attributes, and data sources with the x-liblab-datasource attributes.

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:

{
...
"languages": [
"terraform"
],
...
}

You will also need to configure the Terraform language options section:

{
...
"languageOptions": {
"terraform": {
"providerName": "my-soda-provider",
"providerVersion": "1.7.2",
"providerGoModuleName": "github.com/excitingsoda/terraform-provider-my-soda"
...
}
}
...
}

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:

{
...
"languageOptions": {
"go": {
"goModuleName": "github.com/excitingsoda/sdk"
}
}
...
}
note

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:

liblab build

The generated Terraform provider will be in the output folder, in a folder called terraform. The README.md file created in that folder will contain the instructions to configure and use the provider.