From 50899b589361c38d8c8941c636bfc805eb8e83e2 Mon Sep 17 00:00:00 2001 From: Johannes Rothe Date: Fri, 15 Sep 2023 21:58:02 +0200 Subject: [PATCH] Add possibility to enable or disable public_ip4 --- terraform/main.tf | 2 ++ terraform/modules/loadbalancer/main.tf | 2 +- terraform/modules/loadbalancer/variables.tf | 6 ++++++ terraform/modules/private_server_group/main.tf | 2 +- terraform/modules/private_server_group/variables.tf | 6 ++++++ terraform/prod.tfvars | 1 + terraform/variables.tf | 6 ++++++ 7 files changed, 23 insertions(+), 2 deletions(-) diff --git a/terraform/main.tf b/terraform/main.tf index 064db19..1f85d9b 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -5,6 +5,7 @@ module "private_server_group" { server_count = var.server_count server_subnetwork_ip_range = var.subnetwork_ip_range ssh_keys = var.ssh_keys + public_ipv4 = var.public_ipv4 } module "loadbalancer" { @@ -16,4 +17,5 @@ module "loadbalancer" { lb_external_ip = var.lb_external_ip lb_service_id = var.lb_service_id ssh_key_ids = module.private_server_group.ssh_key_ids + public_ipv4 = var.public_ipv4 } diff --git a/terraform/modules/loadbalancer/main.tf b/terraform/modules/loadbalancer/main.tf index bb009e6..416a0b6 100644 --- a/terraform/modules/loadbalancer/main.tf +++ b/terraform/modules/loadbalancer/main.tf @@ -9,7 +9,7 @@ resource "hcloud_server" "lb" { ssh_keys = var.ssh_key_ids public_net { - ipv4_enabled = true + ipv4_enabled = var.public_ipv4 ipv6_enabled = false } diff --git a/terraform/modules/loadbalancer/variables.tf b/terraform/modules/loadbalancer/variables.tf index 858fcbe..a3a8f58 100644 --- a/terraform/modules/loadbalancer/variables.tf +++ b/terraform/modules/loadbalancer/variables.tf @@ -53,3 +53,9 @@ variable "ssh_key_ids" { description = "SSH key IDs to add to the loadbalancer server" type = list(number) } + +variable "public_ipv4" { + description = "" + type = bool + default = false +} diff --git a/terraform/modules/private_server_group/main.tf b/terraform/modules/private_server_group/main.tf index f0e8142..2187d20 100644 --- a/terraform/modules/private_server_group/main.tf +++ b/terraform/modules/private_server_group/main.tf @@ -11,7 +11,7 @@ resource "hcloud_server" "private_node" { ssh_keys = hcloud_ssh_key.main[*].id public_net { - ipv4_enabled = true + ipv4_enabled = var.public_ipv4 ipv6_enabled = false } diff --git a/terraform/modules/private_server_group/variables.tf b/terraform/modules/private_server_group/variables.tf index 02f25c0..8d3875d 100644 --- a/terraform/modules/private_server_group/variables.tf +++ b/terraform/modules/private_server_group/variables.tf @@ -47,3 +47,9 @@ variable "ssh_keys" { description = "SSH keys to add to the servers" type = list(string) } + +variable "public_ipv4" { + description = "" + type = bool + default = false +} diff --git a/terraform/prod.tfvars b/terraform/prod.tfvars index 9baa773..a584031 100644 --- a/terraform/prod.tfvars +++ b/terraform/prod.tfvars @@ -5,4 +5,5 @@ subnetwork_ip_range = "10.0.0.0/24" lb_internal_ip = "10.0.0.100" lb_external_ip = "167.235.105.161" lb_service_id = 1399502 +public_ipv4 = true ssh_keys = ["rothe.pub", "alt.pub"] diff --git a/terraform/variables.tf b/terraform/variables.tf index 9bdbaf9..8c4903b 100644 --- a/terraform/variables.tf +++ b/terraform/variables.tf @@ -43,3 +43,9 @@ variable "ssh_keys" { description = "SSH keys to add to servers" type = list(string) } + +variable "public_ipv4" { + description = "" + type = bool + default = false +}