- Terraform >= 0.13
$ touch ~/.terraformrc
For using terraform without VPN, you should configure mirror in ~/.terraformrc
file:
provider_installation {
network_mirror {
url = "https://terraform-mirror.yandexcloud.net/"
include = ["registry.terraform.io/*/*"]
}
# 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 {
exclude = ["registry.terraform.io/*/*"]
}
}
It is necessary to add provider settings according to the instructions https://developer.hashicorp.com/terraform/language/providers/requirements: Each Terraform module must declare which providers it requires, so that Terraform can install and use them.
To use the provider, prepare configuration file provider.tf
in the module directory.
terraform {
required_version = ">= 0.13.0"
required_providers {
edgecenter = {
source = "Edge-Center/edgecenter"
version = "{version_number}" # need to specify (choose from https://github.com/Edge-Center/terraform-provider-edgecenter/releases)
}
}
}
provider edgecenter {
edgecenter_platform_api = "https://api.edgecenter.ru/iam"
edgecenter_cloud_api = "https://api.edgecenter.ru/cloud"
permanent_api_token = "{your_permanent_token}" # need to specify (you can create it on the page https://accounts.edgecenter.ru/profile/api-tokens)
}
Run terraform init in the module directory.
terraform init
This command initializes a working directory containing Terraform configuration files. This is the first command that should be run after writing a new Terraform configuration or cloning an existing one from version control. It is safe to run this command multiple times
Create module files using the examples provided in the ./examples
folder.
Before initializing the project you should to set VAULT_ADDR and VAULT_TOKEN envs:
export VAULT_ADDR=<you can ask address from Cloud team (matermost tag: @devcloud)>
export VAULT_TOKEN=<you can generate this token at the ${VAULT_ADDR} page>
Initialize the project using this command:
$ make init
$ make build
To use the built provider from the previous step, you should add the dev_overrides option to the ~/.terraformrc
file:
provider_installation {
dev_overrides {
"local.edgecenter.ru/repo/edgecenter" = "/<dev-path>/terraform-provider-edgecenter/bin"
}
network_mirror {
url = "https://terraform-mirror.yandexcloud.net/"
include = ["registry.terraform.io/*/*"]
}
# 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 {
exclude = ["registry.terraform.io/*/*"]
}
}
Then you should use "local.edgecenter.ru/repo/edgecenter"
source in required_provider settings in the provider.tf
file:
terraform {
required_version = ">= 0.13.0"
required_providers {
edgecenter = {
source = "local.edgecenter.ru/repo/edgecenter"
}
}
}
provider edgecenter {
edgecenter_platform_api = "https://api.edgecenter.ru/iam"
edgecenter_cloud_api = "https://api.edgecenter.ru/cloud"
permanent_api_token = "{your_permanent_token}" # need to specify (you can create it on the page https://accounts.edgecenter.ru/profile/api-tokens)
}
Tests are run with provided secrets envs in the GitHub repository.
For testing cloud data sources
make test_cloud_data_source
For testing cloud resources
make test_cloud_resource
For testing not cloud (storage, cdn, dns) data sources and resources:
make test_not_cloud
To lint project code, use:
make linters
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.
There are two ways to debug the provider:
- Add new go build configuration with field
program arguments
:
-debug -address=local.edgecenter.ru/repo/edgecenter
- Run this configuration;
- Export generated TF_REATTACH_PROVIDERS env from debug output:
export TF_REATTACH_PROVIDERS='{"local.edgecenter.ru/repo/edgecenter":{"Protocol":"grpc","ProtocolVersion":5,"Pid":65114,"Test":true,"Addr":{"Network":"unix","String":"/var/folders/g4/q8cpkx6n7gg_1cvr0lrtkd4w0000gq/T/plugin1422839680"}}}'
- Set a breakpoint in your code and apply the Terraform config:
terraform apply
- 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.
- In the Run view, click
- Add a new configuration to
launch.json
:- The
address
argument must be equal to thesource
field from yourprovider.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" ] } ] }
- The
- 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.
Thank You