This repository the terraform provider of XenServer, using the Terraform Plugin Framework(https://developer.hashicorp.com/terraform/tutorials/providers-plugin-framework), containing:
docs/
The generated documentation.examples/
The examples of provider, resources and data sources.tools/
The tool files, like generate document tool.xenserver/
The provider, resources, data sources and tests.- Miscellaneous meta files.
If you wish to work on the provider, you'll first need Go installed on your machine (see Requirements above).
To build the provider, you'll need to prepare the local XenServer module for Go.
- Download the XenServer SDK zip package and unzip
- Create
goSDK/
directory underterraform-provider-xenserver/
- Copy all source files under
XenServer-SDK/XenServerGo/src/
toterraform-provider-xenserver/goSDK/
folder
Run the commands as follows:
go get -u all
go mod tidy
To compile the provider, run "go install"
. This will build the provider and put the provider binary in the $GOPATH/bin
directory.
To generate or update documentation, run go generate ./...
.
Set up log with github.com/hashicorp/terraform-plugin-log/tflog
. To enable logging during local developing run:
export TF_LOG_PROVIDER="DEBUG"
See https://developer.hashicorp.com/terraform/plugin/log/managing.
In order to run the full suite of acceptance tests, prepare a local .env
file like:
export XENSERVER_HOST=https://<xenserver-host-ip>
export XENSERVER_USERNAME=<username>
export XENSERVER_PASSWORD=<password>
Run "make testacc"
. Note: Acceptance tests create real resources, and often cost money to run.
make testacc
Terraform allows to use local provider builds by setting a dev_overrides
block in a configuration file called .terraformrc
. This block overrides all other configured installation methods.
- Set
GOBIN
to the path where Go installs binaries or use the default path:
export GOBIN=/Users/<Username>/go/bin
go env GOBIN
- Create a new file called
.terraformrc
in home directory (~). Change the to the value returned from the go envGOBIN
command above.
provider_installation {
dev_overrides {
"registry.terraform.io/xenserver/xenserver" = "<PATH>"
}
direct {}
}
-
To compile the provider, run
"go install ."
. This will build the provider and put the provider binary in the directory. -
Local test with terraform command, you'll first need Terraform installed on your machine (see Requirements above). Go to
examples/terraform-main/
folder, update themain.tf
with your own configuration, then run terraform commands like:
terraform plan
terraform apply -auto-approve
// show state
terraform state show xenserver_vm.vm
// remove state
terraform state rm xenserver_vm.vm
// import state with id
terraform import xenserver_vm.vm <xenserver_vm.vm.id>
terraform show
// change resource.tf data and re-apply
terraform apply -auto-approve
terraform destroy -auto-approve
- Local Run Go lint check:
gofmt -w -l xenserver/*.go
sudo docker run -it -v $(pwd):/app -w /app golangci/golangci-lint bash
golangci-lint run --config=/app/.golangci.yml
See DEVELOP.md
See LICENSE.md