Terraform v0.12.0 Spoiler: Recompiling third-party providers

Sanooj Mananghat
4 min readApr 19, 2019
Picture Courtesy: HBO

Terraform v0.12.0 is way off on the original release date. But v0.12.0 is packed with a lot of features which will improve the professional lives of many of us. For those who can’t wait to try, Terraform has released the beta version of v0.12.0 as I am writing this article. However, the third party providers written for the older versions won't just work out of the box. We will see how to start using the current providers with Terraform v0.12.0.

NB: This is a pre-release build and it may contain bugs hence refrain from using it against your production infrastructure.

Setup Golang Environment

Terraform and most of its providers are written in Golang. Hence we need to set up “Go” environment for rebuilding the providers for Terraform v0.12.0.

Choose a Golang version higher than v1.11 and download the archive from here.

We need go module support and Golang supports go module from v1.11 onwards.

curl -s https://dl.google.com/go/go1.12.4.linux-386.tar.gz -o go1.12.4.linux-386.tar.gztar -C /usr/local -xzf go1.12.4.linux-386.tar.gzexport PATH=$PATH:/usr/local/go/bin
golang version

Get Terraform v0.12.0 Beta

Terraform v0.12.0 Beta version can be downloaded from here.

curl -s https://releases.hashicorp.com/terraform/0.12.0-beta2/terraform_0.12.0-beta2_linux_amd64.zip -o terraform_0.12.0-beta2_linux_amd64.zipunzip terraform_0.12.0-beta2_linux_amd64.zip
Archive: terraform_0.12.0-beta2_linux_amd64.zip
inflating: terraform

Let's rename this version of the binary as terraform12 to avoid conflict.

mv terraform /usr/local/bin/terraform12
terraform version

Choose a Third-Party Provider

In this article, “terraform-provider-aws” is taken as an example.

go get github.com/terraform-providers/terraform-provider-aws

“go get” downloads the packages named by the import paths, along with their dependencies. It then installs the named packages.

From Go 1.11 onwards, the environment variable GO111MODULE controls whether module support is enabled or disabled.

Lets set Go Modules to “on”.

export GO111MODULE=on

A Go module is a collection of related go packages. Which is added to a file named “go.mod”. It contains the module import name, and the declaration of dependency requirements, exclusions, and replacements.

go mod init

“go mod init” initializes and writes a new “go.mod” to the current directory. Ignore if you already have a “go.mod” file.

At this point, we have “golang” environment setup and the third-party Terraform module configured with “go modules”.

Now, for this third-party provider to work, we need to update the Terraform vendor framework to v0.12.0 SDK.

grep terraform go.mod

Search for all terraform references in the “go.mod” file.

In the above output, “github.com/hasicorp/terraform” is using v0.11.12 version.

Get the latest commit of v0.12.0 beta from here. And run “go get” to get this version.

go get github.com/hashicorp/terraform@v0.12.0-beta2

Once “go get” completed execution, search for the “terraform version again.

grep terraform go.mod

It should be updated in the “go.mod” file to “v0.12.0-beta2".

Let's build the provider now with these changes.

go build

After a successful build, the provider binary file will be generated.

This third-party provider is now compiled to work with v0.12.0 SDK.

In order to use this provider, copy the generated binary file to “~/.terraform.d/plugins/terraform-provider-aws_vX.Y.Z”.

cp terraform-provider-aws ~/.terraform.d/plugins/terraform-provider-aws_v7.1.2

References

--

--