fix: Use eu-central network zone, handle existing SSH key
This commit is contained in:
@@ -6,6 +6,6 @@ resource "hcloud_network" "cluster" {
|
|||||||
resource "hcloud_network_subnet" "servers" {
|
resource "hcloud_network_subnet" "servers" {
|
||||||
network_id = hcloud_network.cluster.id
|
network_id = hcloud_network.cluster.id
|
||||||
type = "cloud"
|
type = "cloud"
|
||||||
network_zone = "${var.location}-network"
|
network_zone = "eu-central"
|
||||||
ip_range = var.subnet_cidr
|
ip_range = var.subnet_cidr
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ resource "hcloud_server" "control_plane" {
|
|||||||
server_type = var.control_plane_type
|
server_type = var.control_plane_type
|
||||||
image = data.hcloud_image.ubuntu.id
|
image = data.hcloud_image.ubuntu.id
|
||||||
location = var.location
|
location = var.location
|
||||||
ssh_keys = [hcloud_ssh_key.cluster.id]
|
ssh_keys = [data.hcloud_ssh_key.cluster.id]
|
||||||
|
|
||||||
labels = {
|
labels = {
|
||||||
cluster = var.cluster_name
|
cluster = var.cluster_name
|
||||||
@@ -37,7 +37,7 @@ resource "hcloud_server" "workers" {
|
|||||||
server_type = var.worker_type
|
server_type = var.worker_type
|
||||||
image = data.hcloud_image.ubuntu.id
|
image = data.hcloud_image.ubuntu.id
|
||||||
location = var.location
|
location = var.location
|
||||||
ssh_keys = [hcloud_ssh_key.cluster.id]
|
ssh_keys = [data.hcloud_ssh_key.cluster.id]
|
||||||
|
|
||||||
labels = {
|
labels = {
|
||||||
cluster = var.cluster_name
|
cluster = var.cluster_name
|
||||||
|
|||||||
@@ -2,7 +2,21 @@ data "local_file" "ssh_public_key" {
|
|||||||
filename = pathexpand(var.ssh_public_key)
|
filename = pathexpand(var.ssh_public_key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data "hcloud_ssh_keys" "all_keys" {}
|
||||||
|
|
||||||
|
locals {
|
||||||
|
existing_key = try([
|
||||||
|
for key in data.hcloud_ssh_keys.all_keys.ssh_keys :
|
||||||
|
key if key.name == "${var.cluster_name}-ssh-key"
|
||||||
|
][0], null)
|
||||||
|
}
|
||||||
|
|
||||||
resource "hcloud_ssh_key" "cluster" {
|
resource "hcloud_ssh_key" "cluster" {
|
||||||
|
count = local.existing_key == null ? 1 : 0
|
||||||
name = "${var.cluster_name}-ssh-key"
|
name = "${var.cluster_name}-ssh-key"
|
||||||
public_key = data.local_file.ssh_public_key.content
|
public_key = data.local_file.ssh_public_key.content
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data "hcloud_ssh_key" "cluster" {
|
||||||
|
fingerprint = local.existing_key != null ? local.existing_key.fingerprint : hcloud_ssh_key.cluster[0].fingerprint
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user