rync files between servers with bandwidth throttling

As part of moving from one hosting provider to another, I needed to move a large amount of uploaded files to my local machine and then out to a VM on a new provider. Looking at rsync to do this, for moving the content locally first I didn’t want to eat up all my home bandwidth, so found there is a ‘bwlimit’ parameter in KB, e.g. –bwlimit=500 would limit to 500kbps:

rsync --bwlimit=[bw here in kbps] -a --progress [id]@[host]:/source/path .

Run this from the folder where you want the files to arrive what also contains folder ‘path’ (otherwise you’ll end up with path/path/[files here])

Terraform error provisioning new VMs on Hetzner: error during placement (resource_unavailable)

I’ve been moving to use Terraform to provision VMs on Hetzner, and recently while adding a minor change and doing a ‘terraform apply’ I got this error:

Error: error during placement (resource_unavailable, ...

I hadn’t seen this before, but according to this post, ‘resource_unavailable’ means that Hetzner are unable to provision a new VM of the selected type (I’m using cx22), and may be a temporary issue, or maybe changing the location to one of their other locations may work.

Re-running a few minutes later and the provisioning was successful.

Importing a Hetzner VM into a new Terraform template

I’m creating a new VM on Hetzner that I want to manage with Terraform, but this is the first time I’ve used the Hetzner Provider. Rather than stumble through the required options for a new VM, I used the -generate-config-out option with terraform plan to generate the Terraform config for me based on the currrent config.

Here’s my starting point for my main.tf:

terraform {
  required_providers {
    hcloud = {
      source  = "hetznercloud/hcloud"
      version = "~> 1.45"
    }
  }
}


# Set the variable value in *.tfvars file
# or using the -var="hcloud_token=..." CLI option
variable "hcloud_token" {
  sensitive = true
}

# Configure the Hetzner Cloud Provider
provider "hcloud" {
  token = var.hcloud_token
}

import {
  id = "name-of-my-hertzner-vm"
  to = hcloud_server.name-of-my-new-terraform-resource
}

On running:

terraform plan -generate-config-out=generated.tf

I now have the equivalent Terraform config for my VM, in generated.tf, and now I can include this in my main.tf and manage it incrementally via Terraform from this point onwards.

ssh into Hetzner VMs with an ssh key

During VM creation, assuming you added an ssh public key value when prompted:

Add an entry like the following to your ~/.ssh/config:

Host ip-of-your-new-vm
PreferredAuthentications publickey
IdentityFile ~/.ssh/name-of-your-private-key

ssh into your VM with:

ssh root@ip-of-your-new-vm