api | ||
example | ||
internal/provider | ||
.gitignore | ||
go.mod | ||
go.sum | ||
main.go | ||
Makefile | ||
README.md |
Receita terraform example provider
What?
This is a terraform provider to serve as example. This will give an API to generate receipts based on a terraform provider.
Building?
First step in this journey was to install go language. For that you can just follow something like this.
Next we need to init this as a go module this is basically to help us to manage go dependencies.
For this first step we ended with
go mod init balhau.net/receita-provider
the output of this command was the creation of the go.mod
file.
Since the goal here is to build a terraform provider we must add the terraform libraries needed for that. This can be achieved with
go get
To be able to use this terraform plugin you'll need to build this go project with
go build
And then move the binary into your terraform plugin directory, something like this
~/.terraform.d/plugins/terraform.local/balhau/receita/1.0.0/darwin_amd64/terraform-provider-receita
Running?
Setting the http mock server
After previous steps were taken of we are ready to run the receita terraform provider. The provider will do some http calls to the endpoint defined in the provider definition. This means that we should put a service running that matches the description in the endpoint definition
provider "receita" {
endpoint = "http://localhost:9999"
}
Running this
Managing terraform providers involves a bit of typing in the command line. To avoid typing to much we have here a Makefile
with most of the command line instructions we need.
To figure out how to use this makefile just type
make help
help: Show this help.
clean-bin: Clean all the generated binaries
clean-terraform-state: Clean all the terraform state generated by terraform-init/terraform-apply
clean: Clean all the generated resources
terraform-init: Execute terraform-init on example terraform directory
terraform-apply: Execute terraform-apply on example directory
build: Build binaries, both the backed dummy server as the terraform provider binary
install-provider: Install provider in the terraform plugin directory
run-backend: Start the backend web server