Terraform provider code generation now in tech preview

Terraform provider code generation is an extensible solution that lets developers automate portions of their provider development workflow — now in tech preview.

Today, we are excited to announce a tech preview of HashiCorp Terraform provider code generation, consisting of a suite of tools that generate Terraform provider code from an OpenAPI specification. Included in this preview is a provider code specification that lets developers extend code generation to work with their own tooling and development practices.

»A new ecosystem for Terraform provider code generation

Providers are executable binaries written in the Go language that act as a bridge between Terraform and an API service. Terraform’s ecosystem currently has more than 3,600 providers in the public registry, of which a majority of the code has been manually developed.

Bridging between API services and Terraform provider code is often repetitive across resources and operations. This repetitive maintenance can result in code consistency issues such as schema definitions missing attributes and validation, or data mapping that has invalid conversions between types.

Provider maintainers have managed these issues with shared code, linting tools, and in some cases, specialized code generation. Code generation can reduce maintenance burden, as well as create more consistency in the codebase. However, existing provider code generation tooling tends to be very specialized to individual providers.

The HashiCorp Terraform provider code generation tech preview introduces a scalable code generation ecosystem based on a shared specification that can be extended by the existing provider developer community. HashiCorp is offering three general-purpose solutions to bootstrap the ecosystem that can be used together or independently.

  1. The provider code specification is a versioned interface, implemented with a JSON schema, upon which specialized provider code generation tools can be based.
  2. The OpenAPI provider spec generator is a CLI tool that transforms an OpenAPI 3.x specification into a provider code specification.
  3. The framework code generator is a CLI tool that generates Terraform plugin framework code from a provider code specification. This tool currently generates schema and data modeling provider code.

If your Terraform provider interacts with an API service that is documented with an OpenAPI specification, you could use all of the available tools to generate provider code, as shown here:

Generate provider code with an OpenAPI specification

However, if your API service uses a different interface definition language (IDL), such as Protobuf, you may prefer to build your own provider spec generator specific to your API, then use the available framework code generator, as shown here:

Generate provide code using Protobuf

»Getting started with Terraform provider code generation

To learn more about the code generation tools and the overall solution design, please refer to the code generation documentation. You can get a hands-on understanding of the new tools in the code generation tools tutorial and workflow example.

Please share any bugs, enhancement requests, or questions with us via the Terraform discussion forum. We look forward to your feedback and want to thank you for being such a great community!

If you are completely new to Terraform, sign up for Terraform Cloud and get started using the Free offering today.


Sign up for the latest HashiCorp news

By submitting this form, you acknowledge and agree that HashiCorp will process your personal information in accordance with the Privacy Policy.