-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: implement new environment setup
Co-authored-by: Jonas Lammler <jonas.lammler@hetzner-cloud.de> Co-authored-by: Julian Tölle <julian.toelle@hetzner-cloud.de>
- Loading branch information
1 parent
9a4f97d
commit 26c57af
Showing
23 changed files
with
533 additions
and
306 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
# Setup the infrastructure | ||
|
||
provider "hcloud" { | ||
token = var.hcloud_token | ||
} | ||
|
||
locals { | ||
labels = { | ||
env = var.name | ||
} | ||
} | ||
|
||
# SSH Key | ||
|
||
resource "tls_private_key" "ssh" { | ||
algorithm = "ED25519" | ||
} | ||
|
||
resource "local_sensitive_file" "ssh" { | ||
content = tls_private_key.ssh.private_key_openssh | ||
filename = abspath("${path.root}/files/id_ed25519") | ||
} | ||
|
||
resource "hcloud_ssh_key" "default" { | ||
name = var.name | ||
public_key = tls_private_key.ssh.public_key_openssh | ||
labels = local.labels | ||
} | ||
|
||
# Network | ||
|
||
resource "hcloud_network" "cluster" { | ||
name = var.name | ||
ip_range = "10.0.0.0/8" | ||
labels = local.labels | ||
} | ||
|
||
resource "hcloud_network_subnet" "cluster" { | ||
network_id = hcloud_network.cluster.id | ||
network_zone = "eu-central" | ||
type = "cloud" | ||
ip_range = "10.0.0.0/24" | ||
} | ||
|
||
# Control Plane Node | ||
|
||
resource "hcloud_server" "control" { | ||
name = "${var.name}-control" | ||
server_type = var.hcloud_server_type | ||
location = var.hcloud_location | ||
image = var.hcloud_image | ||
ssh_keys = [hcloud_ssh_key.default.id] | ||
labels = local.labels | ||
|
||
connection { | ||
host = self.ipv4_address | ||
private_key = tls_private_key.ssh.private_key_openssh | ||
} | ||
|
||
provisioner "remote-exec" { | ||
inline = ["cloud-init status --wait || test $? -eq 2"] | ||
} | ||
} | ||
|
||
resource "hcloud_server_network" "control" { | ||
server_id = hcloud_server.control.id | ||
subnet_id = hcloud_network_subnet.cluster.id | ||
} | ||
|
||
# Worker / Agent Nodes | ||
|
||
variable "worker_count" { | ||
type = number | ||
default = 3 | ||
} | ||
|
||
resource "hcloud_server" "worker" { | ||
count = var.worker_count | ||
|
||
name = "${var.name}-worker-${count.index}" | ||
server_type = var.hcloud_server_type | ||
location = var.hcloud_location | ||
image = var.hcloud_image | ||
ssh_keys = [hcloud_ssh_key.default.id] | ||
labels = local.labels | ||
|
||
connection { | ||
host = self.ipv4_address | ||
private_key = tls_private_key.ssh.private_key_openssh | ||
} | ||
|
||
provisioner "remote-exec" { | ||
inline = ["cloud-init status --wait || test $? -eq 2"] | ||
} | ||
} | ||
|
||
resource "hcloud_server_network" "worker" { | ||
count = var.worker_count | ||
|
||
server_id = hcloud_server.worker[count.index].id | ||
subnet_id = hcloud_network_subnet.cluster.id | ||
} |
Oops, something went wrong.