This repository is the Terraform Provider of XenServer, using the Terraform 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.
The following instructions are based on Linux system.
- Prepare the local XenServer SDK module
- 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 tidyTo compile the provider, run "go install". This will build the provider and put the provider binary in the $GOPATH/bin directory.
In short, you can just run make provider instead.
To generate or update documentation, run make doc.
Set up log with github.com/hashicorp/terraform-plugin-log/tflog. To enable logging during local developing run:
export TF_LOG_PROVIDER="DEBUG"
export TF_LOG_PATH=/tmp/terraform.logFind more details in Managing Log Output.
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>
export NFS_SERVER=<nfs-server-ip>
export NFS_SERVER_PATH=<nfs-server-path>
export SMB_SERVER_PATH=<smb-server-path>
export SMB_SERVER_USERNAME=<smb-server-username>
export SMB_SERVER_PASSWORD=<smb-server-password>
export SUPPORTER_HOST=<supporter-ip>
export SUPPORTER_USERNAME=<supporter-username>
export SUPPORTER_PASSWORD=<supporter-password>Run "make testacc". Note: Acceptance tests generate actual resources and frequently incur costs when run.
make testaccTerraform 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
GOBINto the path where Go installs binaries or use the default path:
export GOBIN=$HOME/go/bin
go env GOBIN- Create a new file called
.terraformrcin home directory (~). Change the to the value returned from the go envGOBINcommand 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.tfwith 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 uuid
terraform import xenserver_vm.vm <xenserver_vm.vm.uuid>
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- If you are using Terraform provider v0.1.1, you might encounter compatibility issues after applying the XenServer 8 updates released to Early Access on 25 September 2024 and Normal on 2 October 2024. Terraform v0.1.2 resolves these compatibility issues.
See CONTRIBUTING.md
See LICENSE.md