This is the best practice document for XenServer terraform provider development, target to make contributors understand how to make changes, run local checks or tests, raise and merge PRs.
-
When add a new component like resource, data_source and function, create a file
<name>_<component_type>.go
under folderxenserver/
and start coding. Note: For each newresource
, requires a "id" field in the Schema. -
For each new added component, add the according "NewXX" function into the return value of provider function
Resources
,DataSources
orFunctions
underxenserver/provider.go
. -
For each new added component, create an acceptance test file
<name>_<component_type>_test.go
under folderxenserver/
. -
For each new added component, create a utils file
<name>_utils.go
under folderxenserver/
to store the type definitions and common functions. -
For each new added component, requires to add an example for it under folder
examples/
.
-
provider
create a file
examples/provider/provider.tf
to show how to config and use this provider. -
resource
create two files under folder
examples/resources/<resource_name>/
.install.sh
to show how to import a existing resource andresource.tf
to show how to configure with this resource. -
data_source
create a file
data-source.tf
under folderexamples/data-sources/<data-source_name>/
to show how to configure with this data-source. -
function
create a file
function.tf
under folderexamples/functions/<function_name>/
to show how to use this function.
- Generate new documents base on changes, run
go generate ./...
.
Before push your commit, suggest to run below checks and tests to confirm the code quality first.
- Format code with
gofmt -w -l xenserver/*.go
and rungolangci-lint
to make sure no Go lint error.
sudo docker run -it -v $(pwd):/app -w /app golangci/golangci-lint bash
golangci-lint run --config=/app/.golangci.yml
-
Run and pass the full suite of acceptance tests with
make testacc
. -
Add new component configuration under
/examples/terraform-main/main.tf
, and run some manual tests(see Prepare Terraform for local provider install).
Note: Before running tests, the XenServer instance should be properly set up.
- component name, like resource, data-source, function, follow
xenserver_<name>
. eg.
xenserver_vm
- function name and var name follow
Camel-Case
, eg.
func getFirstTemplate(){}
var srRef string
- struct key follow
Pascal
, eg.
type vmResourceModel struct {
NameLabel types.String `tfsdk:"name_label"`
TemplateName types.String `tfsdk:"template_name"``
}
Note: Always Keep your local master branch up to date of master branch on terraform-provider-xenserver.
Preparation:
- Clone the repository terraform-provider-xenserver to local machine.
- Fork the Github repository terraform-provider-xenserver. Add it as another remote "github-fork" to local repository.
- Prepare your local new commit. Make sure this commit already rebase latest master before next steps.
Steps:
- Push commit to
github-fork
and raise PR fromgithub-fork
to terraform-provider-xenserver, the PR should contains the messages of acceptance tests result. - Contact the repository owner to help trigger the internal tests.
- 2 approves needed before merger PR.
The repository owner will add a tag when decide to release a new version of terraform-provider-xenserver. Tag will trigger the Github actions to build a new package to Github release and terraform registry will pick up this new package.