export TF_CLI_CONFIG_FILE=/example-project/dev.tfrc
NOTE: if you use
~/
instead of an absolute path, then be sure your shell expands it to an absolute path (e.g.echo $TF_CLI_CONFIG_FILE
should show the absolute path).
The dev.tfrc
file:
provider_installation {
# Use /your-terraform-provider as an overridden package directory for the
# your/provider provider. This disables the version and checksum
# verifications for this provider and forces Terraform to look for the
# null provider plugin in the given directory.
dev_overrides {
"your/provider" = "/absolute/path/to/your-terraform-provider/bin" # wherever directory the binary is compiled and accessible from
}
# For all other providers, install them directly from their origin provider
# registries as normal. If you omit this, Terraform will _only_ use
# the dev_overrides block, and so no other providers will be available.
direct {}
}
If your provider exists here https://registry.terraform.io/providers/foo/bar/latest
then your/provider
above would be set to foo/bar
in this example.
Make a change to your terraform provider code in /your-terraform-provider
directory. Build your terraform provider binary (e.g. go build
) and then from your /example-project
project directory (where you have your terraform code that consumes the provider) run terraform init
so it picks up the updated provider binary to be used.
NOTE: use
log.Print<T>()
functions notfmt.Print<T>()
because when usingTF_LOG=TRACE
you'll cause terraform to error.
You can then run terraform plan
prefixed with either TF_LOG=<TRACE|DEBUG|INFO>
or TF_LOG_PROVIDER=<TRACE|DEBUG|INFO>
(the latter only displays log data for the provider and not all providers + terraform itself (which can be very noisy).
Another approach still used by the official hashicorp boilerplate repo is to stick your provider plugin into ~/.terraform.d/plugins/
.
TEST?=$$(go list ./... | grep -v 'vendor')
HOSTNAME=hashicorp.com
NAMESPACE=edu
NAME=hashicups
BINARY=terraform-provider-${NAME}
VERSION=0.2
OS_ARCH=darwin_amd64
default: install
build:
go build -o ${BINARY}
release:
GOOS=darwin GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_darwin_amd64
GOOS=freebsd GOARCH=386 go build -o ./bin/${BINARY}_${VERSION}_freebsd_386
GOOS=freebsd GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_freebsd_amd64
GOOS=freebsd GOARCH=arm go build -o ./bin/${BINARY}_${VERSION}_freebsd_arm
GOOS=linux GOARCH=386 go build -o ./bin/${BINARY}_${VERSION}_linux_386
GOOS=linux GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_linux_amd64
GOOS=linux GOARCH=arm go build -o ./bin/${BINARY}_${VERSION}_linux_arm
GOOS=openbsd GOARCH=386 go build -o ./bin/${BINARY}_${VERSION}_openbsd_386
GOOS=openbsd GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_openbsd_amd64
GOOS=solaris GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_solaris_amd64
GOOS=windows GOARCH=386 go build -o ./bin/${BINARY}_${VERSION}_windows_386
GOOS=windows GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_windows_amd64
install: build
mkdir -p ~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/${OS_ARCH}
mv ${BINARY} ~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/${OS_ARCH}
test:
go test -i $(TEST) || exit 1
echo $(TEST) | xargs -t -n4 go test $(TESTARGS) -timeout=30s -parallel=4
testacc:
TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 120m