Add terraform module to deploy a hcloud loadbalancer
This commit is contained in:
parent
a00abcd884
commit
bb0aa44a1a
@ -3,4 +3,13 @@ module "private_server_group" {
|
||||
location = var.location
|
||||
network_zone = var.network_zone
|
||||
server_count = var.server_count
|
||||
server_subnetwork_ip_range = var.subnetwork_ip_range
|
||||
}
|
||||
|
||||
module "loadbalancer" {
|
||||
source = "./modules/loadbalancer"
|
||||
location = var.location
|
||||
subnet_id = module.private_server_group.subnetwork_id
|
||||
lb_internal_ip = var.lb_internal_ip
|
||||
lb_external_ip = var.lb_external_ip
|
||||
}
|
||||
|
26
terraform/modules/loadbalancer/main.tf
Normal file
26
terraform/modules/loadbalancer/main.tf
Normal file
@ -0,0 +1,26 @@
|
||||
resource "hcloud_load_balancer" "main" {
|
||||
name = "main"
|
||||
load_balancer_type = var.lb_type
|
||||
location = var.location
|
||||
algorithm {
|
||||
type = var.lb_algorithm
|
||||
}
|
||||
}
|
||||
|
||||
resource "hcloud_load_balancer_network" "main" {
|
||||
load_balancer_id = hcloud_load_balancer.main.id
|
||||
subnet_id = var.subnet_id
|
||||
ip = var.lb_internal_ip
|
||||
}
|
||||
|
||||
resource "hcloud_load_balancer_target" "main" {
|
||||
type = "label_selector"
|
||||
load_balancer_id = hcloud_load_balancer.main.id
|
||||
label_selector = "app=web"
|
||||
use_private_ip = true
|
||||
}
|
||||
|
||||
resource "hcloud_load_balancer_service" "main" {
|
||||
load_balancer_id = hcloud_load_balancer.main.id
|
||||
protocol = "http"
|
||||
}
|
0
terraform/modules/loadbalancer/outputs.tf
Normal file
0
terraform/modules/loadbalancer/outputs.tf
Normal file
40
terraform/modules/loadbalancer/variables.tf
Normal file
40
terraform/modules/loadbalancer/variables.tf
Normal file
@ -0,0 +1,40 @@
|
||||
variable "location" {
|
||||
description = <<-EOT
|
||||
Location of the infrastructure. Needs to be aligned with network zone.
|
||||
For more information visit https://docs.hetzner.com/cloud/general/locations/
|
||||
EOT
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "lb_type" {
|
||||
description = "Type of loadbalancer"
|
||||
type = string
|
||||
default = "lb11"
|
||||
}
|
||||
|
||||
variable "lb_algorithm" {
|
||||
description = "Type of the Load Balancer Algorithm. round_robin or least_connections"
|
||||
type = string
|
||||
default = "least_connections"
|
||||
}
|
||||
|
||||
variable "domain" {
|
||||
description = "Domain name of the load balancer"
|
||||
type = string
|
||||
default = "wordpress-jr.senecops.com"
|
||||
}
|
||||
|
||||
variable "lb_external_ip" {
|
||||
description = "IP address of the loadbalancer"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "lb_internal_ip" {
|
||||
description = "Internal IP address of the loadbalancer"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "subnet_id" {
|
||||
description = "ID of the subnetwork to attach the loadbalancer to"
|
||||
type = string
|
||||
}
|
8
terraform/modules/loadbalancer/versions.tf
Normal file
8
terraform/modules/loadbalancer/versions.tf
Normal file
@ -0,0 +1,8 @@
|
||||
terraform {
|
||||
required_providers {
|
||||
hcloud = {
|
||||
source = "hetznercloud/hcloud"
|
||||
version = "1.42.1"
|
||||
}
|
||||
}
|
||||
}
|
@ -18,3 +18,18 @@ variable "server_count" {
|
||||
description = "The number of servers to create"
|
||||
type = number
|
||||
}
|
||||
|
||||
variable "subnetwork_ip_range" {
|
||||
description = "Subnetwork IP range of the servers"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "lb_external_ip" {
|
||||
description = "IP address of the loadbalancer"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "lb_internal_ip" {
|
||||
description = "Internal IP address of the loadbalancer"
|
||||
type = string
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user