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