
====================================================================================
Requirements
- Terraform 0.13.x
- Go 1.19 (to build the provider plugin)
Latest provider
Building the provider
$ mkdir -p $GOPATH/src/github.com/terraform-providers
$ cd $GOPATH/src/github.com/terraform-providers
$ git clone https://github.com/Edge-Center/terraform-provider-edgecenter.git
$ cd $GOPATH/src/github.com/terraform-providers/terraform-provider-edgecenter
$ make build
To override terraform provider for development goals you do next steps:
create Terraform configuration file
$ touch ~/.terraformrc
point provider to development path
provider_installation {
dev_overrides {
"local.edgecenter.ru/repo/edgecenter" = "/<dev-path>/terraform-provider-edgecenter/bin"
}
# 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 {}
}
add local.edgecenter.ru/repo/edgecenter
to .tf configuration file
terraform {
required_version = ">= 0.13.0"
required_providers {
edgecenter = {
source = "local.edgecenter.ru/repo/edgecenter"
version = "{version_number}" # need to specify
}
}
}
Using the provider
To use the provider, prepare configuration files based on examples
$ cp ./examples/... .
$ terraform init
Testing
Remote: Tests are run with provided secrets envs in the GitHub repository.
Local: execute the command make test_local_data_source
and make test_local_resource
. For this command to work, you need to:
- Create a
.local.env
file and fill it with the necessary envs.
- Run
make envs
to automatically fill the envs from Vault (don't forget to export VAULT_TOKEN
to terminal).
make envs
requires the installation of jq
and the vault
binary. You can install them with the make vault
and make jq
commands, respectively.
Docs generating
To generate Terraform documentation, use the command make docs
. This command uses the terraform-plugin-docs
library to create provider documentation with examples and places it in the docs
folder. These docs can be viewed on the provider registry page.
Debugging
There are two ways to debug the provider:
VSCode debugging
- Create a
launch.json
file:
- In the Run view, click
create a launch.json file
.
- Choose Go: Launch Package from the debug configuration drop-down menu.
- VS Code will create a
launch.json
file in a .vscode
folder in your workspace.
- Add a new configuration to
launch.json
:
- The
address
argument must be equal to the source
field from your provider.tf
.
"version": "0.2.0",
"configurations": [
{
"name": "Debug Terraform Provider",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${workspaceFolder}",
"env": {},
"args": [
"-debug",
"-address=local.edgecenter.ru/repo/edgecenter"
]
}
]
}
- Launch the debug mode:
Run > Start Debugging (F5)
.
- Copy the
TF_REATTACH_PROVIDERS
env from the console and export it to the terminal as follows:
export TF_REATTACH_PROVIDERS='{"local.edgecenter.ru/repo/edgecenter":{...'
- Set a breakpoint in your code and apply the Terraform config:
terraform apply
.
- Debugging.
using delve
- Install the Delve library - installation
- Build binary without optimization or use
make build_debug
go build -o bin/$(BINARY_NAME) -gcflags '-N -l'
- Open the first terminal:
- Run the binary with the debug option:
dlv exec bin/terraform-provider-edgecenter -- -debug
- Open the second terminal:
Thank You