Skip to content

Commit

Permalink
Merge pull request #1150 from vafgoettlich/master
Browse files Browse the repository at this point in the history
Added basic tofu support
  • Loading branch information
mysticaltech authored Jan 5, 2024
2 parents 922e6ec + baaadfe commit 22634fa
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ Follow those simple steps, and your world's cheapest Kubernetes cluster will be

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

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).
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).

```sh
brew install terraform
brew install terraform # or brew install opentofu
brew install packer
brew install kubectl
brew install hcloud
Expand Down
12 changes: 11 additions & 1 deletion scripts/cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ command -v hcloud >/dev/null 2>&1 || { echo "hcloud (Hetzner CLI) is not install
echo "You can do so by running 'hcloud context create <cluster_name>' and inputting your HCLOUD_TOKEN."
echo " "

if command -v tofu >/dev/null 2>&1 ; then
terraform_command=tofu
elif command -v terraform >/dev/null 2>&1 ; then
terraform_command=terraform
else
echo "terraform or tofu is not installed. Install it with 'brew install terraform' or 'brew install opentofu'."
exit 1
fi


# Try to guess the cluster name
GUESSED_CLUSTER_NAME=$(grep -oP 'cluster_name\s*=\s*"\K([^"]+)' kube.tf)

Expand Down Expand Up @@ -52,7 +62,7 @@ fi

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

VOLUMES=()
while IFS='' read -r line; do VOLUMES+=("$line"); done < <(hcloud volume list "${HCLOUD_SELECTOR[@]}" "${HCLOUD_OUTPUT_OPTIONS[@]}")
Expand Down
14 changes: 10 additions & 4 deletions scripts/create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@ command -v ssh >/dev/null 2>&1 || {
echo "openssh is not installed. Install it with 'brew install openssh'."
exit 1
}
command -v terraform >/dev/null 2>&1 || {
echo "terraform is not installed. Install it with 'brew install terraform'."

if command -v tofu >/dev/null 2>&1 ; then
terraform_command=tofu
elif command -v terraform >/dev/null 2>&1 ; then
terraform_command=terraform
else
echo "terraform or tofu is not installed. Install it with 'brew install terraform' or 'brew install opentofu'."
exit 1
}
fi

command -v packer >/dev/null 2>&1 || {
echo "packer is not installed. Install it with 'brew install packer'."
exit 1
Expand Down Expand Up @@ -72,4 +78,4 @@ fi
echo " "
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!"
echo " "
echo "Before running 'terraform apply', go through the kube.tf file and fill it with your desired values."
echo "Before running '${terraform_command} apply', go through the kube.tf file and fill it with your desired values."

0 comments on commit 22634fa

Please sign in to comment.