Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Lint

on:
push:
branches: [main]
pull_request:

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: opentofu/setup-opentofu@v1
with:
tofu_version: v1.7.2 # renovate: datasource=github-releases depName=opentofu/opentofu
tofu_wrapper: false

- run: |
tofu init
tofu validate
tofu fmt

- name: Check uncommitted changes
run: git diff --exit-code

- if: failure()
run: echo "::error::Check failed, please run 'tofu validate; tofu fmt' and commit the changes."

pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup python
uses: actions/setup-python@v5
with:
python-version: 3.x

- name: Install dependencies
run: pip install pre-commit

- name: Run pre-commit
run: pre-commit run --all-files --show-diff-on-failure
72 changes: 72 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Test

on:
push:
branches: [main]
pull_request:

jobs:
example:
runs-on: ubuntu-latest

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
id-token: write # Required by hetznercloud/tps-action

defaults:
run:
working-directory: example

steps:
- uses: actions/checkout@v4

- uses: opentofu/setup-opentofu@v1
with:
tofu_version: v1.7.2 # renovate: datasource=github-releases depName=opentofu/opentofu
tofu_wrapper: false

- uses: yokawasa/action-setup-kube-tools@v0.11.1
with:
setup-tools: |
kubectl
skaffold
kubectl: v1.29.6 # renovate: datasource=github-releases depName=kubernetes/kubernetes
skaffold: v2.12.0 # renovate: datasource=github-releases depName=GoogleContainerTools/skaffold

- name: Setup k3sup
run: curl -sLS https://get.k3sup.dev | sh

- uses: actions/setup-go@v5
with:
go-version-file: test-app/go.mod

- uses: hetznercloud/tps-action@main

- name: Swap module source
run: sed -i -e 's|source = ".*"|source = "./.."|' main.tf

- name: Setup environment
run: make up

- name: Verify environment
run: |
source files/env.sh

kubectl wait --for=condition=Ready --all node
kubectl wait --for=condition=Available --all --all-namespaces deployment
kubectl wait --for=condition=Ready --all --all-namespaces pod

- name: Deploy test app
working-directory: test-app
run: |
source ../example/files/env.sh

skaffold run
kubectl wait --for=condition=Ready --all pod -l app=test-app

- name: Cleanup
if: always()
run: make down
30 changes: 30 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
- id: check-executables-have-shebangs
- id: check-shebang-scripts-are-executable
- id: check-symlinks
- id: destroyed-symlinks

- id: check-json
- id: check-yaml
- id: check-toml

- id: check-merge-conflict
- id: end-of-file-fixer
- id: mixed-line-ending
args: [--fix=lf]
- id: trailing-whitespace

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.1.0
hooks:
- id: prettier
files: \.(md|ya?ml)$
exclude: ^CHANGELOG.md$
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,39 @@ This repository contains a terraform module used to setup a Kubernetes developme

> [!WARNING]
> This project is not an official Hetzner Cloud Integration and is intended to be used internally. There is no backwards-compatibility promise.

## Usage

To setup a development environment, make sure you installed the following tools:

- [tofu](https://opentofu.org/)
- [k3sup](https://github.com/alexellis/k3sup)

1. Configure a `HCLOUD_TOKEN` in your shell session.

> [!WARNING]
> The development environment runs on Hetzner Cloud servers which will induce costs.

2. Deploy the development cluster:

```sh
make -C dev up
```

3. Load the generated configuration to access the development cluster:

```sh
source files/env.sh
```

4. Check that the development cluster is healthy:

```sh
kubectl get nodes -o wide
```

⚠️ Do not forget to clean up the development cluster once are finished:

```sh
make -C dev down
```
9 changes: 9 additions & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.terraform/
terraform.tfstate
terraform.tfstate.backup
*.auto.tfvars

files/*
!files/.gitkeep

.env
114 changes: 114 additions & 0 deletions example/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions example/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
SHELL = bash
.ONESHELL:

ENV ?= dev
K3S_CHANNEL ?= stable

env.auto.tfvars:
@echo 'name = "$(ENV)"' > "$@"
@echo 'hcloud_token = "$(HCLOUD_TOKEN)"' >> "$@"
@echo 'k3s_channel = "$(K3S_CHANNEL)"' >> "$@"

.terraform:
tofu init

up: .terraform env.auto.tfvars
tofu apply -auto-approve
$(MAKE) port-forward

down: .terraform env.auto.tfvars
tofu destroy -auto-approve

port-forward:
source files/env.sh
bash files/registry-port-forward.sh

clean:
rm -Rf files/* .terraform/ terraform.tfstate* env.auto.tfvars
8 changes: 8 additions & 0 deletions example/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module "dev" {
source = "github.com/hetznercloud/terraform-k8s-dev?ref=v0.1.0" # x-release-please-version

name = "k8s-dev-${replace(var.name, "/[^a-zA-Z0-9-_]/", "-")}"
hcloud_token = var.hcloud_token

k3s_channel = var.k3s_channel
}
10 changes: 10 additions & 0 deletions example/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
variable "name" {
type = string
}
variable "hcloud_token" {
type = string
sensitive = true
}
variable "k3s_channel" {
type = string
}
Loading