Skip to content

Instantly share code, notes, and snippets.

@bjarneo
Created November 6, 2024 06:44
Show Gist options
  • Save bjarneo/4846db41c247820bc71a287148b9fb46 to your computer and use it in GitHub Desktop.
Save bjarneo/4846db41c247820bc71a287148b9fb46 to your computer and use it in GitHub Desktop.
Using the Coolify predefined image
# Set the variable value in *.tfvars file
# or using the -var="hcloud_token=..." CLI option
variable "hcloud_token" {
type = string
default = ""
}
# Set the path to your SSH key
variable "ssh_key" {
type = string
default = "~/.ssh/id_ed25519.pub"
}
# Configure the Hetzner Cloud Provider
provider "hcloud" {
token = var.hcloud_token
}
# Create a new SSH key
resource "hcloud_ssh_key" "sudo" {
name = "My ssh key"
public_key = file(var.ssh_key)
}
# Port 8000 in needed for the initial visit of the coolify instance
resource "hcloud_firewall" "http" {
name = "allow_http"
rule {
direction = "in"
protocol = "tcp"
port = 8000
source_ips = [
"0.0.0.0/0",
"::/0"
]
}
}
# Allow SSL
resource "hcloud_firewall" "https" {
name = "allow_https"
rule {
direction = "in"
protocol = "tcp"
port = 443
source_ips = [
"0.0.0.0/0",
"::/0"
]
}
}
# Allow SSH
resource "hcloud_firewall" "ssh" {
name = "allow_ssh"
rule {
direction = "in"
protocol = "tcp"
port = 22
source_ips = ["<insert_your_ip>"]
}
}
# Create a coolify instance
resource "hcloud_server" "coolify" {
name = "coolify"
# Using the predefined coolify image from Hetzner
image = "coolify"
server_type = "cpx11"
location = "hel1"
firewall_ids = [hcloud_firewall.http.id, hcloud_firewall.https.id, hcloud_firewall.ssh.id]
ssh_keys = [hcloud_ssh_key.sudo.id]
labels = {
"purpose" = "coolify"
}
}
# Output the IP addresses of the created servers
output "server_ips" {
value = hcloud_server.coolify.ipv4_address
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment