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

Installing Solaris 8 x86 on VirtualBox 7.0.20 – when to remove the iso during install

After initially booting from disk 1 and following the prompts to format the disk, you’ll reach a prompt where it asks you to remove the install media and reboot. Note that it also says to only remove the media after the machine has reset before you eject- this is important otherwise the disk will not be bootable:

The sequence that appears to work is:

  • press Enter
  • wait for VM to reset
  • remove mounted iso in VirtualBox just as the VM is restarting and you see the VirtualBox logo/BIOS screen

At this point you’re asked what partition to boot from (select 1) and the installer will continue as normal from that point:

If you remove the iso from the VM before it resets, you’ll see the screen to select either the boot disk or the cdrom (the initial installer screen, not the partition selection screen above), and if you select the disk at this point it will not boot (after pressing Enter it appears there’s a few seconds delay where there is a disk sync step, and this needs to complete before the machine resets and when it’s safe to remove the iso).