Sebastien Tardif
Sebastien Tardif

Reputation: 387

How to build Terraform provider for all platform?

How do I build a Terraform provider like https://github.com/hashicorp/terraform-provider-aws for all platforms?

When I do make build, I only get one binary on Mac.

I would like to build for all the platforms Terraform usually supports.

Upvotes: 0

Views: 595

Answers (2)

Martin Atkins
Martin Atkins

Reputation: 74299

You can compile for a particular single other platform by setting the environment variables GOOS and GOARCH that the Go toolchain understands. For example, you can build for Windows on x86_64 by running this inside the provider's main package:

GOOS=windows GOARCH=amd64 go install

The process of building for all architectures that the provider team supports is unfortunately a build process maintained by each provider team and thus can vary between providers. However, a common pattern -- and one which is true for the AWS provider -- is to use GoReleaser to build, tag, and publish releases across multiple platforms.

At the time of writing the AWS provider's .goreleaser.yml specifies the matrix of supported OS and architecture combinations. Therefore if you install GoReleaser you can build distribution packages for the same set of targets using goreleaser build.

The same should be true for other providers where the team uses GoReleaser to manage their releases. Some providers might use other patterns, but at the time of writing GoReleaser is the technique recommended in the Terraform docs and so it's a pretty common choice.

Upvotes: 2

The joker
The joker

Reputation: 32

you can pass environment variables GOOS and GOARCH for the desired OS and architecture.

for ex: GOOS=linux GOARCH=ppc64 go build builds for linux ppc64 architecture.

Upvotes: 1

Related Questions