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 = {
|
||||
|
||||
Reference in New Issue
Block a user