Terraform
Manage HF Cloud servers, SSH keys and security groups with the humanfrog/hfcloud Terraform provider.
The humanfrog/hfcloud provider (version 0.2) manages servers, SSH keys and security groups through
the API. It works with Terraform 1.0 or newer (plugin protocol 6).
| Resources | Data sources |
|---|---|
hfcloud_server |
hfcloud_server (by id or name) |
hfcloud_ssh_key |
hfcloud_ssh_key (by name or fingerprint) |
hfcloud_security_group |
hfcloud_security_group (by id or name) |
hfcloud_image, hfcloud_images |
|
hfcloud_size (by name or vcpu + memory_gb), hfcloud_sizes |
|
hfcloud_location (by code), hfcloud_locations |
Install
The provider is not in the Terraform Registry yet, so terraform init cannot download it by itself. You build it
once from source and tell Terraform where the binary is. You need Go 1.24 or newer, make and Terraform 1.0+.
1. Get the source and build it
The source is the directory integrations/terraform-provider-hfcloud of the HF Cloud portal repository (Go module
github.com/humanfrog/terraform-provider-hfcloud, with a README.md and the generated reference in docs/).
Get it as a clone or as the source archive of that directory from your HF Cloud contact, then:
cd terraform-provider-hfcloud # integrations/terraform-provider-hfcloud in the repository
make build # produces ./terraform-provider-hfcloud
./terraform-provider-hfcloud -h # a plugin binary: it only explains that Terraform starts it
There is no public download or release page yet; until there is, the source from your contact is the only way to
get the provider. Build for the machine that runs Terraform (GOOS=linux GOARCH=amd64 make build to cross-compile).
Then pick one of the two ways below to make Terraform use the binary.
Option A: filesystem mirror
Put the binary where Terraform looks for local providers; terraform init then works as usual.
VERSION=0.2.0
OS_ARCH=$(go env GOOS)_$(go env GOARCH) # e.g. linux_amd64, darwin_arm64
DIR=~/.terraform.d/plugins/registry.terraform.io/humanfrog/hfcloud/$VERSION/$OS_ARCH
mkdir -p "$DIR"
cp terraform-provider-hfcloud "$DIR/terraform-provider-hfcloud_v$VERSION"
(make install in the provider's source does exactly this and needs no manual copying.) Pin the version in your configuration:
terraform {
required_providers {
hfcloud = { source = "humanfrog/hfcloud", version = "0.2.0" }
}
}
Option B: dev_overrides
Skips terraform init for this provider and uses the binary from a directory. Put this in ~/.terraformrc
(or in a file named by TF_CLI_CONFIG_FILE):
provider_installation {
dev_overrides {
"humanfrog/hfcloud" = "/path/to/directory/with/terraform-provider-hfcloud"
}
direct {}
}
Terraform prints a warning about the override on every run; that is expected.
Configure
Create an API token (API → New token, read and write; a service token for shared or CI use) and pass it through the environment:
export HFCLOUD_TOKEN=hfc_...
export HFCLOUD_ENDPOINT=https://hfcloud.eu/api/cloud/v1
| Argument | Environment | Default |
|---|---|---|
token |
HFCLOUD_TOKEN |
required, sensitive |
endpoint |
HFCLOUD_ENDPOINT |
https://hfcloud.eu/api/cloud/v1 |
provider "hfcloud" {} # token and endpoint from the environment
A read-only token works for data sources only.
Full example
An SSH key, a security group and a server with nginx installed by cloud-init:
terraform {
required_providers {
hfcloud = { source = "humanfrog/hfcloud", version = "~> 0.1" }
}
}
provider "hfcloud" {}
data "hfcloud_size" "small" {
vcpu = 2
memory_gb = 4
}
data "hfcloud_image" "ubuntu" {
id = "ubuntu-24.04"
}
resource "hfcloud_ssh_key" "admin" {
name = "admin"
public_key = file(pathexpand("~/.ssh/id_ed25519.pub"))
}
resource "hfcloud_security_group" "web" {
name = "web"
description = "HTTP(S) from anywhere, SSH from the office"
rules = [
{ protocol = "tcp", port = "80,443", comment = "web" },
{ protocol = "tcp", port = "22", source = "203.0.113.0/24", comment = "office ssh" },
{ protocol = "icmp" },
{ protocol = "any", source = "private", comment = "private network" },
]
}
resource "hfcloud_server" "web" {
name = "web-1"
image = data.hfcloud_image.ubuntu.id
size = data.hfcloud_size.small.id
location = "LJ02"
ssh_key_ids = [hfcloud_ssh_key.admin.id]
security_groups = [hfcloud_security_group.web.id]
backups = true
user_data = <<-EOT
#cloud-config
packages: [nginx]
EOT
timeouts {
create = "20m"
}
}
output "ssh" {
value = "ssh ${data.hfcloud_image.ubuntu.default_user}@${hfcloud_server.web.ipv4}"
}
terraform init
terraform apply
Import
Existing resources can be imported by id:
terraform import hfcloud_server.web 0b6f1c1e-1234-4abc-9def-0123456789ab # server UUID
terraform import hfcloud_ssh_key.admin 42 # SSH key id
terraform import hfcloud_security_group.web web # security group id
After importing a server, the create-only arguments (ssh_key_ids, ssh_keys, user_data) are unknown to the
API; the first apply adopts your configured values without replacing the server.
Server behaviour
- Create waits until the server is
ready(default 15 minutes,timeouts { create }). If provisioning fails, the error is shown and the server is marked tainted, so the next apply replaces it. - Changed in place:
size,security_groups,private_network,backups,running. Changingsizeon a running server shuts it down (gracefully, a hard stop after 3 minutes), resizes it and starts it again ifrunning = true. A private network change on a running server takes effect after its next reboot. - Replaced:
name,image,location,user_data,ssh_key_ids,ssh_keys,public_ip. - Delete confirms with the server's name and waits until the server is gone (default 10 minutes).
locationtakes a code (LJ02, any case) or a numeric id. Differences in case innameandimagenever cause a diff.running(defaulttrue) is the desired power state: a server stopped outside Terraform is started again.autoscale { max_size = ... }turns on automatic scaling. A size that grew by itself is then not drift (Terraform keeps yoursizeand does not shrink the server); raisesizeto catch up.
Notes
- The provider retries
429and503answers (up to 5 attempts, honouringRetry-After). - Every create sends an
Idempotency-Key, so a timeout never orders a second server. - Validation errors are shown per field;
402 payment_requiredshows the link to the billing page. - Load balancers, firewalls, reserved IPs and webhooks are not in the provider yet; use the API.
- Debugging:
TF_LOG=DEBUG terraform applyshows the provider's log.