• Stars
    star
    1,052
  • Rank 43,828 (Top 0.9 %)
  • Language
    Go
  • License
    MIT License
  • Created almost 7 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A command-line interface for Hetzner Cloud

hcloud: Command-line interface for Hetzner Cloud

Build status

hcloud is a command-line interface for interacting with Hetzner Cloud.

asciicast

Installation

You can download pre-built binaries for Linux, FreeBSD, macOS, and Windows on the releases page.

On macOS and Linux, you can install hcloud via Homebrew:

brew install hcloud

On Windows, you can install hcloud via Scoop

scoop install hcloud

Third-party packages

There are unofficial packages maintained by third-party users. Please note that these packages aren’t supported nor maintained by Hetzner Cloud and may not always be up-to-date. Downloading the binary or building from source is still the recommended install method.

Build manually

If you have Go installed, you can build and install the latest version of hcloud with:

go install github.com/hetznercloud/cli/cmd/hcloud@latest

Binaries built in this way do not have the correct version embedded. Use our prebuilt binaries or check out .goreleaser.yml to learn how to embed it yourself.

Getting Started

  1. Visit the Hetzner Cloud Console at console.hetzner.cloud, select your project, and create a new API token.

  2. Configure the hcloud program to use your token:

    hcloud context create my-project
    
  3. You’re ready to use the program. For example, to get a list of available server types, run:

    hcloud server-type list
    

See hcloud help for a list of commands.

Shell Completion

hcloud provides completions for various shells.

Bash

To load completions into the current shell execute:

source <(hcloud completion bash)

In order to make the completions permanent, append the line above to your .bashrc.

Zsh

If shell completions are not already enabled for your environment need to enable them. Add the following line to your ~/.zshrc file:

autoload -Uz compinit; compinit

To load completions for each session execute the following commands:

mkdir -p ~/.config/hcloud/completion/zsh
hcloud completion zsh > ~/.config/hcloud/completion/zsh/_hcloud

Finally, add the following line to your ~/.zshrc file, before you call the compinit function:

fpath+=(~/.config/hcloud/completion/zsh)

In the end your ~/.zshrc file should contain the following two lines in the order given here.

fpath+=(~/.config/hcloud/completion/zsh)
#  ... anything else that needs to be done before compinit
autoload -Uz compinit; compinit
# ...

You will need to start a new shell for this setup to take effect.

Fish

To load completions into the current shell execute:

hcloud completion fish | source

In order to make the completions permanent execute once:

 hcloud completion fish > ~/.config/fish/completions/hcloud.fish

PowerShell:

To load completions into the current shell execute:

PS> hcloud completion powershell | Out-String | Invoke-Expression

To load completions for every new session, run and source this file from your PowerShell profile.

PS> hcloud completion powershell > hcloud.ps1

Output configuration

You can control output via the -o option:

  • For list commands, you can specify -o noheader to omit the table header.

  • For list commands, you can specify -o columns=id,name to only show certain columns in the table.

  • For describe commands, you can specify -o json to get a JSON representation of the resource. The schema is identical to those in the Hetzner Cloud API which are documented at docs.hetzner.cloud.

  • For describe commands, you can specify -o format={{.ID}} to format output according to the given Go template. The template’s input is the resource’s corresponding struct in the hcloud-go library.

Configure hcloud using environment variables

You can use the following environment variables to configure hcloud:

  • HCLOUD_TOKEN
  • HCLOUD_CONTEXT
  • HCLOUD_CONFIG

When using hcloud in scripts, for example, it may be cumbersome to work with contexts. Instead of creating a context, you can set the token via the HCLOUD_TOKEN environment variable. When combined with tools like direnv, you can configure a per-directory context by setting HCLOUD_CONTEXT=my-context via .envrc.

Examples

List all servers

$ hcloud server list
ID       NAME                    STATUS    IPV4
210216   test1                   running   78.46.122.12
210729   ubuntu-8gb-nbg1-dc3-1   running   94.130.177.158

Create a server

$ hcloud server create --name test --image debian-9 --type cx11 --ssh-key demo
   7s [====================================================================] 100%
Server 325211 created

License

MIT license

More Repositories

1

awesome-hcloud

A curated list of awesome libraries, tools, and integrations for Hetzner Cloud
926
star
2

hcloud-cloud-controller-manager

Kubernetes cloud-controller-manager for Hetzner Cloud
Go
690
star
3

csi-driver

Kubernetes Container Storage Interface driver for Hetzner Cloud Volumes
Go
611
star
4

terraform-provider-hcloud

Terraform Hetzner Cloud provider
Go
484
star
5

hcloud-go

A Go library for the Hetzner Cloud API
Go
362
star
6

hcloud-python

A Python library for the Hetzner Cloud API
Python
262
star
7

apps

Hetzner Cloud Apps
Ruby
114
star
8

packer-plugin-hcloud

Packer plugin for Hetzner Cloud Builder
Go
22
star
9

kubecon-europe-2021

This repository is part of a live demo at KubeCon Europe 2021 that shows how different official integrations can be used to deploy a Kubernetes (k3s) cluster at Hetzner Cloud.
Jinja
19
star
10

hc-utils

A set of tools for the Hetzner Cloud platform
Shell
17
star
11

protractor-test-helper

Helper functions to make e2e testing with protractor more fun
TypeScript
15
star
12

ceph-s3-box

Containerized Ceph and Radosgw Playground
Shell
14
star
13

setup-hcloud

GitHub action to install the Hetzner Cloud CLI.
TypeScript
13
star
14

kubecon-europe-2022

This repository is part of a live demo at KubeCon Europe 2022 that shows how different official integrations can be used to deploy a Kubernetes (k3s) cluster at Hetzner Cloud.
Jinja
10
star
15

ngx-translate-mock

TypeScript
9
star
16

kubernetes-dev-env

Kubernetes development environment for our Integrations.
HCL
6
star
17

ansible-role-aptly

Ansible Role - Install and configure Aptly
Python
5
star
18

ansible-role-ipxe-ca

Ansible Role - Cross-Sign all Root CAs for iPXE
Python
5
star
19

cilium-tests

4
star
20

bnxt_en_xdp_redirect_reproducer

Simple reproducer for an eBPF XDP redirect issue we observe with BroadCom NetExtreme NICs (bnxt_en driver).
C
4
star
21

helm-charts

Helm Chart Repository for Hetzner Cloud projects
3
star
22

ngx-prepare-test-environment

TypeScript
3
star
23

fleeting-plugin-hetzner

Mirror of https://gitlab.com/hetznercloud/fleeting-plugin-hetzner
Go
1
star
24

tps-action

Github Action to setup a temporary Hetzner Cloud Token
Shell
1
star