This commit is contained in:
10
main.tf
10
main.tf
@@ -1,11 +1,11 @@
|
||||
# SSH Key
|
||||
resource "hcloud_ssh_key" "default" {
|
||||
name = "${var.server_name}-ssh-key"
|
||||
public_key = var.ssh_public_key
|
||||
# SSH Key (existing)
|
||||
data "hcloud_ssh_key" "default" {
|
||||
name = local.ssh_key_name
|
||||
}
|
||||
|
||||
# Cloud-init script
|
||||
locals {
|
||||
ssh_key_name = length(trimspace(var.ssh_key_name)) > 0 ? var.ssh_key_name : "${var.server_name}-ssh-key"
|
||||
user_data = templatefile("${path.module}/scripts/cloud-init.sh", {
|
||||
username = var.username
|
||||
ssh_public_key = var.ssh_public_key
|
||||
@@ -21,7 +21,7 @@ resource "hcloud_server" "vps" {
|
||||
image = var.image
|
||||
server_type = data.hcloud_server_type.selected.name
|
||||
location = data.hcloud_location.selected.name
|
||||
ssh_keys = concat([hcloud_ssh_key.default.id])
|
||||
ssh_keys = concat([data.hcloud_ssh_key.default.id])
|
||||
user_data = local.user_data
|
||||
|
||||
labels = {
|
||||
|
||||
@@ -4,4 +4,5 @@ server_type = "cax21"
|
||||
image = "ubuntu-24.04"
|
||||
location = "nbg1"
|
||||
ssh_public_key = "__SSH_KEY__"
|
||||
ssh_key_name = melchiorreimers@Melchiors-MacBook-Pro.local"
|
||||
|
||||
|
||||
@@ -33,6 +33,12 @@ variable "ssh_public_key" {
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "ssh_key_name" {
|
||||
description = "Existing Hetzner SSH key name (must already exist)"
|
||||
type = string
|
||||
default = ""
|
||||
}
|
||||
|
||||
variable "username" {
|
||||
description = "Non-root user to create"
|
||||
type = string
|
||||
|
||||
Reference in New Issue
Block a user