Setup a Cluster
Cluster on Hetzner
In this section we show you how to use the hetzner terraform module to setup your own infrastructure on hetzner provider.
Setup Project
You can use our hcloud template to create a repository. Click on the Use this template
link on the repo.
Name the module and simply clone the repository down.
Let’s begin by cloning our repository we created using the template.
git clone [email protected]:<your-organization>/<your-repo>.git
Cluster Bootstrap
Once you’ve cloned down the repository simply replace the cluster_name
with the desired name for your cluster. You can also update the node_size
and the size
parameter in the cluster_topology
based on the value you wish to use from list of slugs from hcloud.
Once you’ve updated the values create a .auto.tfvars
and add your tokens.
hcloud_token = <your hetzner api token>
instellar_auth_token = <your instellar auth token>
You can get the instellar_auth_token
by signing up and heading over to the Credentials
page on instellar.
SSH Key
This section assumes you already know how to generate the ssh-key. If you don’t know how to do this I recommend this post. To add the ssh-key to Hetzner. Head to the Security
area. Under your project. Click on the Add SSH Key
button.
You will see the following modal box. You can copy your public key into the box and give the key a name. You can copy the public key by running
cat ~/.ssh/id_ed25519.pub
This will print out your public key and you can copy it and paste it as the content of the key. The name is important you’ll need to use it in the main.tf
file.
Once you add the key, you can refrence the name inside the main.tf
file.
API Token
Before you push to your repository let’s look at how we can retrieve the API token to be used with Hetzner cloud on terraform cloud.
Head over to the Security
section under the project. Then Click on the API tokens
tab.
Go ahead and click the Generate API Token
, you’ll be prompted with the following. Make sure you select Read & Write
. Give it a recognizable name like Terraform
.
You’ll get to see the token once. Copy it and either use it in your .auto.tfvars
or your terraform cloud.
Running Locally via CLI
Sensitive Token
The hcloud_token
variable should not be checked into your code repository.
If you’re planning on running terraform locally, you can create a .auto.tfvars
file and add the variable there. This file will only exist locally on your machine and will not be checked into your github repo.
hcloud_token = "<your-hcloud-token>"
If you use the template above the .auto.tfvars
is automatically ignored.
Once all the configuration files are in place simply run:
terraform init
terraform plan
terraform apply