Check examples
folder for working examples
First, clone the repository:
git clone [email protected]:dariusbakunas/terraform-provider-opentoolchain.git
To compile the provider, run make build. This will build the provider and put the provider binary in the current directory.
make build
Run make install
to install provider binary under ~/.terraform.d/plugins/ibm.com/dbakuna/opentoolchain/{VERSION}/{OS_ARCH}
.
After it is installed, terraform should be able to detect it during terraform init
phase.
To run unit tests, simply run:
make test
To run acceptance tests, make sure IAM_API_KEY
environment variable is set and execute:
make testacc
Note: Acceptance tests create/destroy real resources, while they are named using tf_acc_test
testing prefix, use some caution. Check provider_test.go
contents for supported environment variables and their default values.
- Install pipenv
% brew install pipenv
- Install pyenv
% brew install pyenv
- Use
pyenv
to installPython 3
if not installed already (runpyenv versions
to check installed versions orpyenv list
to list available for install):
% pyenv install 3.8.1
-
Run
pipenv install
to installmkdocs
dependencies -
In order to activate the virtual environment associated with this project you can simply use the shell keyword:
% pipenv shell
-
To generate or update Terraform documentation, run
go generate
. -
To serve mk-docs locally, run
mkdocs serve
. -
To push changes to
gh-pages
branch, runmkdocs gh-deploy
Run your debugger (eg. delve), and pass it the provider binary as the command to run, specifying whatever flags, environment variables, or other input is necessary to start the provider in debug mode:
make build-debug
dlv exec --listen=:54526 --headless ./terraform-provider-opentoolchain -- --debug
Note: IntelliJ may need additional flag --api-version=2
Connect your debugger (whether it's your IDE or the debugger client) to the debugger server. Example launch configuration for VSCode:
{
"apiVersion": 1,
"name": "Debug",
"type": "go",
"request": "attach",
"mode": "remote",
"port": 54526,
"host": "127.0.0.1",
"showLog": true,
//"trace": "verbose",
}
Have it continue execution and it will print output like the following to stdout:
Provider started, to attach Terraform set the TF_REATTACH_PROVIDERS env var:
TF_REATTACH_PROVIDERS='{"dariusbakunas/opentoolchain":{"Protocol":"grpc","Pid":30101,"Test":true,"Addr":{"Network":"unix","String":"/var/folders/mq/00hw97gj08323ybqfm763plr0000gn/T/plugin900766792"}}}'
Copy the line starting with TF_REATTACH_PROVIDERS
from your provider's output. Either export it, or prefix every Terraform command with it. Run Terraform as usual. Any breakpoints you have set will halt execution and show you the current variable values.