Skip to content

Commit 22634fa

Browse files
authored
Merge pull request #1150 from vafgoettlich/master
Added basic tofu support
2 parents 922e6ec + baaadfe commit 22634fa

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ Follow those simple steps, and your world's cheapest Kubernetes cluster will be
7070

7171
First and foremost, you need to have a Hetzner Cloud account. You can sign up for free [here](https://hetzner.com/cloud/).
7272

73-
Then you'll need to have [terraform](https://learn.hashicorp.com/tutorials/terraform/install-cli), [packer](https://developer.hashicorp.com/packer/tutorials/docker-get-started/get-started-install-cli#installing-packer) (for the initial snapshot creation only, no longer needed once that's done), [kubectl](https://kubernetes.io/docs/tasks/tools/) cli and [hcloud](https://github.com/hetznercloud/cli) the Hetzner cli for convenience. The easiest way is to use the [homebrew](https://brew.sh/) package manager to install them (available on Linux, Mac, and Windows Linux Subsystem).
73+
Then you'll need to have [terraform](https://learn.hashicorp.com/tutorials/terraform/install-cli) or [tofu](https://opentofu.org/docs/intro/install/), [packer](https://developer.hashicorp.com/packer/tutorials/docker-get-started/get-started-install-cli#installing-packer) (for the initial snapshot creation only, no longer needed once that's done), [kubectl](https://kubernetes.io/docs/tasks/tools/) cli and [hcloud](https://github.com/hetznercloud/cli) the Hetzner cli for convenience. The easiest way is to use the [homebrew](https://brew.sh/) package manager to install them (available on Linux, Mac, and Windows Linux Subsystem).
7474

7575
```sh
76-
brew install terraform
76+
brew install terraform # or brew install opentofu
7777
brew install packer
7878
brew install kubectl
7979
brew install hcloud

scripts/cleanup.sh

+11-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ command -v hcloud >/dev/null 2>&1 || { echo "hcloud (Hetzner CLI) is not install
1010
echo "You can do so by running 'hcloud context create <cluster_name>' and inputting your HCLOUD_TOKEN."
1111
echo " "
1212

13+
if command -v tofu >/dev/null 2>&1 ; then
14+
terraform_command=tofu
15+
elif command -v terraform >/dev/null 2>&1 ; then
16+
terraform_command=terraform
17+
else
18+
echo "terraform or tofu is not installed. Install it with 'brew install terraform' or 'brew install opentofu'."
19+
exit 1
20+
fi
21+
22+
1323
# Try to guess the cluster name
1424
GUESSED_CLUSTER_NAME=$(grep -oP 'cluster_name\s*=\s*"\K([^"]+)' kube.tf)
1525

@@ -52,7 +62,7 @@ fi
5262

5363
HCLOUD_SELECTOR=(--selector='provisioner=terraform' --selector="cluster=$CLUSTER_NAME")
5464
HCLOUD_OUTPUT_OPTIONS=(-o noheader -o 'columns=id')
55-
NODEPOOLS=( $(terraform state list | grep -oP 'module.kube-hetzner.data.hcloud_servers.autoscaled_nodes\["\K([^"]+)') )
65+
NODEPOOLS=( $(${terraform_command} state list | grep -oP 'module.kube-hetzner.data.hcloud_servers.autoscaled_nodes\["\K([^"]+)') )
5666

5767
VOLUMES=()
5868
while IFS='' read -r line; do VOLUMES+=("$line"); done < <(hcloud volume list "${HCLOUD_SELECTOR[@]}" "${HCLOUD_OUTPUT_OPTIONS[@]}")

scripts/create.sh

+10-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,16 @@ command -v ssh >/dev/null 2>&1 || {
55
echo "openssh is not installed. Install it with 'brew install openssh'."
66
exit 1
77
}
8-
command -v terraform >/dev/null 2>&1 || {
9-
echo "terraform is not installed. Install it with 'brew install terraform'."
8+
9+
if command -v tofu >/dev/null 2>&1 ; then
10+
terraform_command=tofu
11+
elif command -v terraform >/dev/null 2>&1 ; then
12+
terraform_command=terraform
13+
else
14+
echo "terraform or tofu is not installed. Install it with 'brew install terraform' or 'brew install opentofu'."
1015
exit 1
11-
}
16+
fi
17+
1218
command -v packer >/dev/null 2>&1 || {
1319
echo "packer is not installed. Install it with 'brew install packer'."
1420
exit 1
@@ -72,4 +78,4 @@ fi
7278
echo " "
7379
echo "Remember, don't skip the hcloud cli, to activate it run 'hcloud context create <project-name>'. It is ideal to quickly debug and allows targeted cleanup when needed!"
7480
echo " "
75-
echo "Before running 'terraform apply', go through the kube.tf file and fill it with your desired values."
81+
echo "Before running '${terraform_command} apply', go through the kube.tf file and fill it with your desired values."

0 commit comments

Comments
 (0)