Terraform

Hetzner Cloud basic

providers.tf
terraform {
  required_providers {
    hcloud = {
      source = "hetznercloud/hcloud"
      version = "~> 1.45"
    }
  }
}
variables.tf
# using "export TF_VAR_hcloud_token=..."
variable "hcloud_token" {
}
variable "server_name" {
  default = "awesomo"
}
variable "image_type" {
  default = "debian12"
}
server.tf
resource "hcloud_server" "node1" {
  name        = var.server_name
  image       = var.image_type
  server_type = "cx11"
  datacenter  = "fsn1-dc14"
  public_net {
    ipv4_enabled = true
    ipv6_enabled = true
  }
}
# set api token
> export TF_VAR_hcloud_token="XXX"
# setup terraform
> terraform init

# plan infrastructure
> terraform plan

# apply infrastructure
> terraform apply
> terraform apply --auto-approve

# remove infrastructure
> terraform destroy
> terraform destroy --auto-approve