# Terraform Provider for VirtFusion A Terraform provider for managing [VirtFusion](https://virtfusion.com) virtualization platform resources. Automate server provisioning, user management, networking, and self-service billing through infrastructure as code. ## Quick Install ### Linux (amd64) ```bash VERSION=1.0.0 curl -Lo terraform-provider-virtfusion.zip \ https://git.ezscale.cloud/EZSCALE/terraform-provider-virtfusion/releases/download/v${VERSION}/terraform-provider-virtfusion_${VERSION}_linux_amd64.zip unzip terraform-provider-virtfusion.zip -d ~/.terraform.d/plugins/registry.terraform.io/EZSCALE/virtfusion/${VERSION}/linux_amd64/ rm terraform-provider-virtfusion.zip ``` ### macOS (Apple Silicon) ```bash VERSION=1.0.0 curl -Lo terraform-provider-virtfusion.zip \ https://git.ezscale.cloud/EZSCALE/terraform-provider-virtfusion/releases/download/v${VERSION}/terraform-provider-virtfusion_${VERSION}_darwin_arm64.zip unzip terraform-provider-virtfusion.zip -d ~/.terraform.d/plugins/registry.terraform.io/EZSCALE/virtfusion/${VERSION}/darwin_arm64/ rm terraform-provider-virtfusion.zip ``` ### macOS (Intel) ```bash VERSION=1.0.0 curl -Lo terraform-provider-virtfusion.zip \ https://git.ezscale.cloud/EZSCALE/terraform-provider-virtfusion/releases/download/v${VERSION}/terraform-provider-virtfusion_${VERSION}_darwin_amd64.zip unzip terraform-provider-virtfusion.zip -d ~/.terraform.d/plugins/registry.terraform.io/EZSCALE/virtfusion/${VERSION}/darwin_amd64/ rm terraform-provider-virtfusion.zip ``` ### Windows (PowerShell) ```powershell $VERSION = "1.0.0" Invoke-WebRequest -Uri "https://git.ezscale.cloud/EZSCALE/terraform-provider-virtfusion/releases/download/v$VERSION/terraform-provider-virtfusion_${VERSION}_windows_amd64.zip" -OutFile tf-vf.zip Expand-Archive tf-vf.zip -DestinationPath "$env:APPDATA\terraform.d\plugins\registry.terraform.io\EZSCALE\virtfusion\$VERSION\windows_amd64\" Remove-Item tf-vf.zip ``` ### From Source ```bash git clone https://git.ezscale.cloud/EZSCALE/terraform-provider-virtfusion.git cd terraform-provider-virtfusion && go install . ``` Then add dev_overrides to `~/.terraformrc`: ```bash cat >> ~/.terraformrc <<'EOF' provider_installation { dev_overrides { "registry.terraform.io/EZSCALE/virtfusion" = "${GOPATH}/bin" } direct {} } EOF ``` ## Quick Start **1. Set your credentials:** ```bash export VIRTFUSION_ENDPOINT="https://cp.example.com" export VIRTFUSION_API_TOKEN="your-api-token" ``` **2. Create `main.tf`:** ```hcl terraform { required_providers { virtfusion = { source = "registry.terraform.io/EZSCALE/virtfusion" } } } provider "virtfusion" {} data "virtfusion_servers" "all" {} output "server_count" { value = length(data.virtfusion_servers.all.servers) } ``` **3. Run it:** ```bash terraform plan ``` The provider reads `VIRTFUSION_ENDPOINT` and `VIRTFUSION_API_TOKEN` from the environment. You can also set them directly in the provider block: ```hcl provider "virtfusion" { endpoint = "https://cp.example.com" api_token = var.virtfusion_api_token } ``` ## Usage Examples ### Create a user, SSH key, server, and build it ```hcl resource "virtfusion_user" "customer" { name = "Jane Doe" email = "jane@example.com" ext_relation_id = "cust-001" } resource "virtfusion_ssh_key" "key" { user_id = virtfusion_user.customer.id name = "deploy-key" public_key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIExample deploy@example.com" } resource "virtfusion_server" "web" { package_id = 19 user_id = virtfusion_user.customer.id hypervisor_id = 8 } resource "virtfusion_server_build" "web" { server_id = virtfusion_server.web.id name = "web-server" hostname = "web.example.com" osid = 13 vnc = true ipv6 = true ssh_keys = [virtfusion_ssh_key.key.id] } ``` ### Read infrastructure data ```hcl data "virtfusion_servers" "all" {} data "virtfusion_packages" "all" {} data "virtfusion_hypervisors" "all" {} output "server_count" { value = length(data.virtfusion_servers.all.servers) } ``` List data sources support a `results` parameter (default: 300) and automatically paginate through all pages: ```hcl data "virtfusion_servers" "all" { results = 100 # override per-page limit } ``` ## Resources | Resource | Description | |----------|-------------| | `virtfusion_server` | Create and manage servers | | `virtfusion_server_build` | Build (install OS on) a server | | `virtfusion_server_firewall` | Manage server firewall rules | | `virtfusion_server_ipv4` | Add IPv4 addresses to a server | | `virtfusion_server_network_whitelist` | Manage network whitelist entries | | `virtfusion_server_traffic_block` | Manage traffic blocks | | `virtfusion_server_power_action` | Control server power state | | `virtfusion_server_password_reset` | Reset server root password | | `virtfusion_ssh_key` | Manage SSH keys | | `virtfusion_user` | Manage users | | `virtfusion_user_auth_token` | Generate user authentication tokens | | `virtfusion_user_server_auth_token` | Generate server-scoped authentication tokens | | `virtfusion_user_password_reset` | Reset user passwords | | `virtfusion_ip_block_range` | Add IPv4 ranges to IP blocks | | `virtfusion_self_service_credit` | Manage self-service billing credits | | `virtfusion_self_service_resource_pack` | Manage resource packs | | `virtfusion_self_service_hourly_group_profile` | Manage hourly billing group profiles | | `virtfusion_self_service_hourly_resource_pack` | Manage hourly resource packs | | `virtfusion_self_service_resource_group_profile` | Manage resource group profiles | | `virtfusion_self_service_pack_servers_action` | Suspend/unsuspend/delete pack servers | ## Data Sources | Data Source | Description | |-------------|-------------| | `virtfusion_server` | Read a single server by ID | | `virtfusion_servers` | List all servers | | `virtfusion_servers_by_user` | List servers owned by a user | | `virtfusion_server_backups` | List server backups | | `virtfusion_server_firewall` | Read server firewall configuration | | `virtfusion_server_templates` | List available templates for a server | | `virtfusion_server_traffic` | Read server traffic usage | | `virtfusion_server_traffic_blocks` | List server traffic blocks | | `virtfusion_server_vnc` | Get VNC connection info | | `virtfusion_hypervisor` | Read a single hypervisor | | `virtfusion_hypervisors` | List all hypervisors | | `virtfusion_hypervisor_group` | Read a single hypervisor group | | `virtfusion_hypervisor_groups` | List all hypervisor groups | | `virtfusion_hypervisor_group_resources` | Read aggregated resources for a group | | `virtfusion_package` | Read a single package | | `virtfusion_packages` | List all packages | | `virtfusion_package_templates` | List templates for a package | | `virtfusion_ip_block` | Read a single IP block | | `virtfusion_ip_blocks` | List all IP blocks | | `virtfusion_ssh_key` | Read a single SSH key | | `virtfusion_ssh_keys_by_user` | List SSH keys for a user | | `virtfusion_user` | Read a user by external relation ID | | `virtfusion_dns_service` | Read DNS service configuration | | `virtfusion_iso` | Read ISO media info | | `virtfusion_queue_item` | Read a queue item status | | `virtfusion_self_service_currencies` | List available currencies | | `virtfusion_self_service_resource_pack` | Read a resource pack | | `virtfusion_self_service_hourly_stats` | Read hourly billing stats | | `virtfusion_self_service_report` | Read self-service reports | | `virtfusion_self_service_usage` | Read self-service usage | ## Development ### Build ```bash go build ./... ``` ### Install locally ```bash go install . ``` ### Run linter ```bash golangci-lint run ``` ## License [MPL-2.0](LICENSE)