Move declaration of primary IPs into kubernetes-module
This commit is contained in:
32
main.tf
32
main.tf
@@ -4,42 +4,22 @@ resource "hcloud_ssh_key" "this" {
|
|||||||
public_key = each.value
|
public_key = each.value
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "hcloud_primary_ip" "k8s_ipv4" {
|
|
||||||
count = var.k8s_server_count < 1 ? 1 : var.k8s_server_count
|
|
||||||
|
|
||||||
name = "k8s_primary_ipv4_${count.index}"
|
|
||||||
datacenter = var.k8s_ip_datacenter
|
|
||||||
type = "ipv4"
|
|
||||||
assignee_type = "server"
|
|
||||||
auto_delete = !var.k8s_test_installation
|
|
||||||
}
|
|
||||||
|
|
||||||
resource "hcloud_primary_ip" "k8s_ipv6" {
|
|
||||||
count = var.k8s_server_count < 1 ? 1 : var.k8s_server_count
|
|
||||||
|
|
||||||
name = "k8s_primary_ipv6_${count.index}"
|
|
||||||
datacenter = var.k8s_ip_datacenter
|
|
||||||
type = "ipv6"
|
|
||||||
assignee_type = "server"
|
|
||||||
auto_delete = !var.k8s_test_installation
|
|
||||||
}
|
|
||||||
|
|
||||||
module "k8s" {
|
module "k8s" {
|
||||||
source = "./modules/hetzner/kubernetes"
|
source = "./modules/hetzner/kubernetes"
|
||||||
|
|
||||||
name = "cluster1"
|
name = "cluster1"
|
||||||
ssh_keys = [for o in hcloud_ssh_key.this : o.id]
|
ssh_keys = [for o in hcloud_ssh_key.this : o.id]
|
||||||
servers = [for n in range(var.k8s_server_count) : {
|
servers = [for n in range(var.k8s_server_count) : {
|
||||||
ipv4_id = hcloud_primary_ip.k8s_ipv4[n].id
|
|
||||||
ipv6_id = hcloud_primary_ip.k8s_ipv6[n].id
|
|
||||||
type = var.k8s_server_type
|
type = var.k8s_server_type
|
||||||
location = var.k8s_location
|
location = var.k8s_location
|
||||||
|
ip_datacenter = var.k8s_ip_datacenter
|
||||||
}]
|
}]
|
||||||
agents = [{
|
agents = [{
|
||||||
type = var.k8s_agent_type
|
type = var.k8s_agent_type
|
||||||
location = var.k8s_location
|
location = var.k8s_location
|
||||||
count = var.k8s_agent_count
|
count = var.k8s_agent_count
|
||||||
}]
|
}]
|
||||||
|
auto_delete_primary_ips = false
|
||||||
kubernetes_exposed_ips = var.kubernetes_allowed_ips
|
kubernetes_exposed_ips = var.kubernetes_allowed_ips
|
||||||
ssh_exposed_ips = var.ssh_allowed_ips
|
ssh_exposed_ips = var.ssh_allowed_ips
|
||||||
ssh_port = 1022
|
ssh_port = 1022
|
||||||
@@ -66,12 +46,12 @@ locals {
|
|||||||
zone_ttl = values.zone_ttl
|
zone_ttl = values.zone_ttl
|
||||||
records = toset(concat(
|
records = toset(concat(
|
||||||
values.default_A ? [
|
values.default_A ? [
|
||||||
{ name = "@", type = "A", value = hcloud_primary_ip.k8s_ipv4[0].ip_address },
|
{ name = "@", type = "A", value = module.k8s.server_ips_v4[0] },
|
||||||
{ name = "*", type = "A", value = hcloud_primary_ip.k8s_ipv4[0].ip_address },
|
{ name = "*", type = "A", value = module.k8s.server_ips_v4[0] },
|
||||||
] : [],
|
] : [],
|
||||||
values.default_AAAA ? [
|
values.default_AAAA ? [
|
||||||
{ name = "@", type = "AAAA", value = "${hcloud_primary_ip.k8s_ipv6[0].ip_address}1" },
|
{ name = "@", type = "AAAA", value = module.k8s.server_ips_v6[0] },
|
||||||
{ name = "*", type = "AAAA", value = "${hcloud_primary_ip.k8s_ipv6[0].ip_address}1" },
|
{ name = "*", type = "AAAA", value = module.k8s.server_ips_v6[0] },
|
||||||
] : [],
|
] : [],
|
||||||
tolist(values.custom_records)
|
tolist(values.custom_records)
|
||||||
))
|
))
|
||||||
|
|||||||
@@ -1,3 +1,23 @@
|
|||||||
|
resource "hcloud_primary_ip" "ipv4" {
|
||||||
|
count = length(var.servers)
|
||||||
|
|
||||||
|
name = "k8s_primary_ipv4_${count.index}"
|
||||||
|
datacenter = var.servers[count.index].ip_datacenter
|
||||||
|
type = "ipv4"
|
||||||
|
assignee_type = "server"
|
||||||
|
auto_delete = var.auto_delete_primary_ips
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "hcloud_primary_ip" "ipv6" {
|
||||||
|
count = length(var.servers)
|
||||||
|
|
||||||
|
name = "k8s_primary_ipv6_${count.index}"
|
||||||
|
datacenter = var.servers[count.index].ip_datacenter
|
||||||
|
type = "ipv6"
|
||||||
|
assignee_type = "server"
|
||||||
|
auto_delete = var.auto_delete_primary_ips
|
||||||
|
}
|
||||||
|
|
||||||
locals {
|
locals {
|
||||||
network = "10.0.0.0/16"
|
network = "10.0.0.0/16"
|
||||||
subnet_eu_central = "10.0.0.0/24"
|
subnet_eu_central = "10.0.0.0/24"
|
||||||
@@ -5,6 +25,8 @@ locals {
|
|||||||
for idx, config in var.servers : "${var.name}-server-${idx + 1}" => merge(
|
for idx, config in var.servers : "${var.name}-server-${idx + 1}" => merge(
|
||||||
config,
|
config,
|
||||||
{
|
{
|
||||||
|
ipv4_id = hcloud_primary_ip.ipv4[idx].id
|
||||||
|
ipv6_id = hcloud_primary_ip.ipv6[idx].id
|
||||||
ip = cidrhost(local.subnet_eu_central, idx + 2)
|
ip = cidrhost(local.subnet_eu_central, idx + 2)
|
||||||
first_ip = idx == 0 ? "" : cidrhost(local.subnet_eu_central, 2)
|
first_ip = idx == 0 ? "" : cidrhost(local.subnet_eu_central, 2)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,10 +8,9 @@ variable "ssh_keys" {
|
|||||||
|
|
||||||
variable "servers" {
|
variable "servers" {
|
||||||
type = list(object({
|
type = list(object({
|
||||||
ipv4_id = number
|
|
||||||
ipv6_id = number
|
|
||||||
type = string
|
type = string
|
||||||
location = string
|
location = string
|
||||||
|
ip_datacenter = string
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,3 +46,14 @@ variable "ssh_port" {
|
|||||||
type = number
|
type = number
|
||||||
default = 1022
|
default = 1022
|
||||||
}
|
}
|
||||||
|
|
||||||
|
variable "auto_delete_primary_ips" {
|
||||||
|
default = true
|
||||||
|
description = <<EOF
|
||||||
|
Set this to "false" to keep the primary IPs bound to your Hetzner-Account, even after a destroy.
|
||||||
|
This setting would allow for reuse of the same IPs between multiple create/destroy cycles.
|
||||||
|
Though, it doesn't guarantee reuse of the same IPs.
|
||||||
|
|
||||||
|
Note, that reserved IPs will create costs, even if they're not used.
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|||||||
@@ -20,15 +20,6 @@ variable "ssh_keys" {
|
|||||||
type = map(string)
|
type = map(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "k8s_test_installation" {
|
|
||||||
default = false
|
|
||||||
description = <<EOF
|
|
||||||
When this is set to true we configure primary-ips to not be deleted automatically!
|
|
||||||
This allows us to reuse the same IP for multiple create/destroy cycles.
|
|
||||||
As soon as the test-phase is over this should be false.
|
|
||||||
EOF
|
|
||||||
}
|
|
||||||
|
|
||||||
# Right now this only supports 1 location, but that's okay for me!
|
# Right now this only supports 1 location, but that's okay for me!
|
||||||
variable "k8s_location" {
|
variable "k8s_location" {
|
||||||
type = string
|
type = string
|
||||||
|
|||||||
Reference in New Issue
Block a user