ip -> ipv4...
...explictly label current ip values as ipv4, in order to more easily add ipv6 support later on.
This commit is contained in:
parent
52b3d9b82c
commit
38fc145ad0
@ -12,8 +12,8 @@ module "agents" {
|
|||||||
placement_group_id = hcloud_placement_group.k3s.id
|
placement_group_id = hcloud_placement_group.k3s.id
|
||||||
location = var.location
|
location = var.location
|
||||||
server_type = each.value.server_type
|
server_type = each.value.server_type
|
||||||
subnet_id = hcloud_network_subnet.subnet[each.value.subnet].id
|
ipv4_subnet_id = hcloud_network_subnet.subnet[each.value.subnet].id
|
||||||
private_ip = cidrhost(var.network_subnets[each.value.subnet], each.value.index + 1)
|
private_ipv4 = cidrhost(var.network_ipv4_subnets[each.value.subnet], each.value.index + 1)
|
||||||
labels = {
|
labels = {
|
||||||
"provisioner" = "terraform",
|
"provisioner" = "terraform",
|
||||||
"engine" = "k3s"
|
"engine" = "k3s"
|
||||||
@ -44,7 +44,7 @@ resource "null_resource" "agents" {
|
|||||||
provisioner "file" {
|
provisioner "file" {
|
||||||
content = yamlencode({
|
content = yamlencode({
|
||||||
node-name = module.agents[each.key].name
|
node-name = module.agents[each.key].name
|
||||||
server = "https://${local.first_control_plane_network_ip}:6443"
|
server = "https://${local.first_control_plane_network_ipv4}:6443"
|
||||||
token = random_password.k3s_token.result
|
token = random_password.k3s_token.result
|
||||||
kubelet-arg = "cloud-provider=external"
|
kubelet-arg = "cloud-provider=external"
|
||||||
flannel-iface = "eth1"
|
flannel-iface = "eth1"
|
||||||
|
@ -12,8 +12,8 @@ module "control_planes" {
|
|||||||
placement_group_id = hcloud_placement_group.k3s.id
|
placement_group_id = hcloud_placement_group.k3s.id
|
||||||
location = var.location
|
location = var.location
|
||||||
server_type = var.control_plane_server_type
|
server_type = var.control_plane_server_type
|
||||||
subnet_id = hcloud_network_subnet.subnet["control_plane"].id
|
ipv4_subnet_id = hcloud_network_subnet.subnet["control_plane"].id
|
||||||
private_ip = cidrhost(var.network_subnets["control_plane"], count.index + 1)
|
private_ipv4 = cidrhost(var.network_ipv4_subnets["control_plane"], count.index + 1)
|
||||||
|
|
||||||
labels = {
|
labels = {
|
||||||
"provisioner" = "terraform",
|
"provisioner" = "terraform",
|
||||||
|
10
init.tf
10
init.tf
@ -96,11 +96,11 @@ resource "null_resource" "kustomization" {
|
|||||||
content = templatefile(
|
content = templatefile(
|
||||||
"${path.module}/templates/traefik_config.yaml.tpl",
|
"${path.module}/templates/traefik_config.yaml.tpl",
|
||||||
{
|
{
|
||||||
load_balancer_disable_ipv6 = var.load_balancer_disable_ipv6
|
load_balancer_disable_ipv6 = var.load_balancer_disable_ipv6
|
||||||
load_balancer_type = var.load_balancer_type
|
load_balancer_type = var.load_balancer_type
|
||||||
location = var.location
|
location = var.location
|
||||||
traefik_acme_tls = var.traefik_acme_tls
|
traefik_acme_tls = var.traefik_acme_tls
|
||||||
traefik_acme_email = var.traefik_acme_email
|
traefik_acme_email = var.traefik_acme_email
|
||||||
})
|
})
|
||||||
destination = "/tmp/post_install/traefik.yaml"
|
destination = "/tmp/post_install/traefik.yaml"
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
locals {
|
locals {
|
||||||
first_control_plane_network_ip = module.control_planes[0].private_ipv4_address
|
first_control_plane_network_ipv4 = module.control_planes[0].private_ipv4_address
|
||||||
|
|
||||||
ssh_public_key = trimspace(file(var.public_key))
|
ssh_public_key = trimspace(file(var.public_key))
|
||||||
# ssh_private_key is either the contents of var.private_key or null to use a ssh agent.
|
# ssh_private_key is either the contents of var.private_key or null to use a ssh agent.
|
||||||
|
10
main.tf
10
main.tf
@ -10,11 +10,11 @@ resource "hcloud_ssh_key" "k3s" {
|
|||||||
|
|
||||||
resource "hcloud_network" "k3s" {
|
resource "hcloud_network" "k3s" {
|
||||||
name = "k3s"
|
name = "k3s"
|
||||||
ip_range = var.network_ip_range
|
ip_range = var.network_ipv4_range
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "hcloud_network_subnet" "subnet" {
|
resource "hcloud_network_subnet" "subnet" {
|
||||||
for_each = var.network_subnets
|
for_each = var.network_ipv4_subnets
|
||||||
network_id = hcloud_network.k3s.id
|
network_id = hcloud_network.k3s.id
|
||||||
type = "cloud"
|
type = "cloud"
|
||||||
network_zone = var.network_region
|
network_zone = var.network_region
|
||||||
@ -30,7 +30,7 @@ resource "hcloud_firewall" "k3s" {
|
|||||||
protocol = "tcp"
|
protocol = "tcp"
|
||||||
port = "any"
|
port = "any"
|
||||||
source_ips = [
|
source_ips = [
|
||||||
var.network_ip_range,
|
var.network_ipv4_range,
|
||||||
"127.0.0.1/32",
|
"127.0.0.1/32",
|
||||||
"169.254.169.254/32",
|
"169.254.169.254/32",
|
||||||
"213.239.246.1/32"
|
"213.239.246.1/32"
|
||||||
@ -41,7 +41,7 @@ resource "hcloud_firewall" "k3s" {
|
|||||||
protocol = "udp"
|
protocol = "udp"
|
||||||
port = "any"
|
port = "any"
|
||||||
source_ips = [
|
source_ips = [
|
||||||
var.network_ip_range,
|
var.network_ipv4_range,
|
||||||
"127.0.0.1/32",
|
"127.0.0.1/32",
|
||||||
"169.254.169.254/32",
|
"169.254.169.254/32",
|
||||||
"213.239.246.1/32"
|
"213.239.246.1/32"
|
||||||
@ -51,7 +51,7 @@ resource "hcloud_firewall" "k3s" {
|
|||||||
direction = "in"
|
direction = "in"
|
||||||
protocol = "icmp"
|
protocol = "icmp"
|
||||||
source_ips = [
|
source_ips = [
|
||||||
var.network_ip_range,
|
var.network_ipv4_range,
|
||||||
"127.0.0.1/32",
|
"127.0.0.1/32",
|
||||||
"169.254.169.254/32",
|
"169.254.169.254/32",
|
||||||
"213.239.246.1/32"
|
"213.239.246.1/32"
|
||||||
|
@ -64,7 +64,7 @@ resource "hcloud_server" "server" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resource "hcloud_server_network" "server" {
|
resource "hcloud_server_network" "server" {
|
||||||
ip = var.private_ip
|
ip = var.private_ipv4
|
||||||
server_id = hcloud_server.server.id
|
server_id = hcloud_server.server.id
|
||||||
subnet_id = var.subnet_id
|
subnet_id = var.ipv4_subnet_id
|
||||||
}
|
}
|
||||||
|
@ -54,12 +54,12 @@ variable "location" {
|
|||||||
type = string
|
type = string
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "subnet_id" {
|
variable "ipv4_subnet_id" {
|
||||||
description = "The subnet id"
|
description = "The subnet id"
|
||||||
type = string
|
type = string
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "private_ip" {
|
variable "private_ipv4" {
|
||||||
description = "Private IP for the server"
|
description = "Private IP for the server"
|
||||||
type = string
|
type = string
|
||||||
}
|
}
|
||||||
|
10
output.tf
10
output.tf
@ -1,16 +1,16 @@
|
|||||||
output "controlplanes_public_ip" {
|
output "control_planes_public_ipv4" {
|
||||||
value = module.control_planes.*.ipv4_address
|
value = module.control_planes.*.ipv4_address
|
||||||
description = "The public IP addresses of the controlplane server."
|
description = "The public IPv4 addresses of the controlplane server."
|
||||||
}
|
}
|
||||||
|
|
||||||
output "agents_public_ip" {
|
output "agents_public_ipv4" {
|
||||||
value = [
|
value = [
|
||||||
for obj in module.agents : obj.ipv4_address
|
for obj in module.agents : obj.ipv4_address
|
||||||
]
|
]
|
||||||
description = "The public IP addresses of the agent server."
|
description = "The public IPv4 addresses of the agent server."
|
||||||
}
|
}
|
||||||
|
|
||||||
output "load_balancer_public_ip" {
|
output "load_balancer_public_ipv4" {
|
||||||
description = "The public IPv4 address of the Hetzner load balancer"
|
description = "The public IPv4 address of the Hetzner load balancer"
|
||||||
value = data.hcloud_load_balancer.traefik.ipv4
|
value = data.hcloud_load_balancer.traefik.ipv4
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,8 @@ private_key = "/home/username/.ssh/id_ed25519"
|
|||||||
# For Hetzner server types see https://www.hetzner.com/cloud
|
# For Hetzner server types see https://www.hetzner.com/cloud
|
||||||
location = "fsn1" # change to `ash` for us-east Ashburn, Virginia location
|
location = "fsn1" # change to `ash` for us-east Ashburn, Virginia location
|
||||||
network_region = "eu-central" # change to `us-east` if location is ash
|
network_region = "eu-central" # change to `us-east` if location is ash
|
||||||
network_ip_range = "10.0.0.0/8"
|
network_ipv4_range = "10.0.0.0/8"
|
||||||
network_subnets = {
|
network_ipv4_subnets = {
|
||||||
control_plane = "10.1.0.0/16"
|
control_plane = "10.1.0.0/16"
|
||||||
subnet1 = "10.2.0.0/16"
|
subnet1 = "10.2.0.0/16"
|
||||||
subnet2 = "10.3.0.0/16"
|
subnet2 = "10.3.0.0/16"
|
||||||
|
@ -30,12 +30,12 @@ variable "network_region" {
|
|||||||
type = string
|
type = string
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "network_ip_range" {
|
variable "network_ipv4_range" {
|
||||||
description = "Default IP range for network"
|
description = "Default IPv4 range for network"
|
||||||
type = string
|
type = string
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "network_subnets" {
|
variable "network_ipv4_subnets" {
|
||||||
description = "Subnets definition for default network"
|
description = "Subnets definition for default network"
|
||||||
type = map(string)
|
type = map(string)
|
||||||
}
|
}
|
||||||
@ -50,7 +50,6 @@ variable "control_plane_count" {
|
|||||||
type = number
|
type = number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
variable "load_balancer_type" {
|
variable "load_balancer_type" {
|
||||||
description = "Default load balancer server type"
|
description = "Default load balancer server type"
|
||||||
type = string
|
type = string
|
||||||
|
Loading…
Reference in New Issue
Block a user