Skip to content

Commit

Permalink
Update hcloud infra
Browse files Browse the repository at this point in the history
  • Loading branch information
MacroPower committed Mar 19, 2023
1 parent 8189742 commit 434cca3
Show file tree
Hide file tree
Showing 7 changed files with 6,453 additions and 468 deletions.
4 changes: 3 additions & 1 deletion terraform/hcloud/extra-manifests/argocd/get-install.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
wget https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
#!/bin/bash

curl -X GET https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml --output install.yaml
6,784 changes: 6,360 additions & 424 deletions terraform/hcloud/extra-manifests/argocd/install.yaml

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions terraform/hcloud/extra-manifests/argocd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ patches:
value:
requests:
cpu: 200m
memory: 768Mi
memory: 512Mi
limits:
cpu: 1
memory: 768Mi
memory: 1024Mi
- target:
group: apps
version: v1
Expand All @@ -51,7 +51,7 @@ patches:
value:
requests:
cpu: 200m
memory: 768Mi
memory: 512Mi
limits:
cpu: 1
memory: 768Mi
memory: 1024Mi
56 changes: 17 additions & 39 deletions terraform/hcloud/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ module "kube-hetzner" {

agent_nodepools = [
{
name = "agent-small-hel1",
server_type = "cx21",
name = "agent-hel1",
server_type = "cpx31",
location = "hel1",
labels = [],
taints = [],
count = 4
count = 2
},
]

Expand All @@ -97,7 +97,7 @@ module "kube-hetzner" {

# When this is enabled, rather than the first node, all external traffic will be routed via a control-plane loadbalancer, allowing for high availability.
# The default is false.
use_control_plane_lb = false
use_control_plane_lb = true

restrict_outbound_traffic = false

Expand Down Expand Up @@ -162,42 +162,20 @@ module "kube-hetzner" {
}
}

data "hcloud_servers" "agents" {
with_selector = "role=agent_node"
}
# module "floating-ip" {
# source = "./modules/floating-ip"

resource "hcloud_floating_ip" "agent_ip" {
type = "ipv4"
server_id = data.hcloud_servers.agents.servers[0].id
}
# providers = {
# hcloud = hcloud
# }

resource "random_string" "identity_file" {
length = 20
lower = true
special = false
numeric = true
upper = false
}
# # Customize the SSH port (by default 22)
# ssh_port = random_integer.ssh_port.result

resource "null_resource" "agent_floating_ip" {
for_each = { for i, v in data.hcloud_servers.agents.servers: v.name => v }

triggers = {
agent_id = each.key
}
# ssh_public_key = tls_private_key.k8s_key.public_key_openssh
# ssh_private_key = tls_private_key.k8s_key.private_key_openssh

connection {
user = "root"
private_key = tls_private_key.k8s_key.private_key_openssh
agent_identity = tls_private_key.k8s_key.public_key_openssh
host = each.value.ipv4_address
port = random_integer.ssh_port.result
}

provisioner "remote-exec" {
inline = [
"echo \"Adding ${hcloud_floating_ip.agent_ip.ip_address}\"",
"ip addr add ${hcloud_floating_ip.agent_ip.ip_address} dev eth0",
]
}
}
# depends_on = [
# module.kube-hetzner
# ]
# }
39 changes: 39 additions & 0 deletions terraform/hcloud/modules/floating-ip/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
data "hcloud_servers" "agents" {
with_selector = "role=agent_node"
}

resource "hcloud_floating_ip" "agent_ip" {
type = "ipv4"
server_id = data.hcloud_servers.agents.servers[0].id
}

resource "random_string" "identity_file" {
length = 20
lower = true
special = false
numeric = true
upper = false
}

resource "null_resource" "agent_floating_ip" {
for_each = { for i, v in data.hcloud_servers.agents.servers: v.name => v }

triggers = {
agent_id = each.key
}

connection {
user = "root"
private_key = var.ssh_private_key
agent_identity = var.ssh_public_key
host = each.value.ipv4_address
port = var.ssh_port
}

provisioner "remote-exec" {
inline = [
"echo \"Adding ${hcloud_floating_ip.agent_ip.ip_address}\"",
"ip addr add ${hcloud_floating_ip.agent_ip.ip_address} dev eth0",
]
}
}
21 changes: 21 additions & 0 deletions terraform/hcloud/modules/floating-ip/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
variable "ssh_port" {
description = "The main SSH port to connect to the nodes."
type = number
default = 22

validation {
condition = var.ssh_port >= 0 && var.ssh_port <= 65535
error_message = "The SSH port must use a valid range from 0 to 65535."
}
}

variable "ssh_public_key" {
description = "SSH public Key."
type = string
}

variable "ssh_private_key" {
description = "SSH private Key."
type = string
sensitive = true
}
9 changes: 9 additions & 0 deletions terraform/hcloud/modules/floating-ip/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
terraform {
required_version = ">= 1.3.3"
required_providers {
hcloud = {
source = "hetznercloud/hcloud"
version = ">= 1.35.2"
}
}
}

0 comments on commit 434cca3

Please sign in to comment.