Terraform module to provision Load Balancer resources in Hetzner Cloud.
# Configure the Hetzner Cloud Provider
provider "hcloud" {
token = var.hcloud_token
}
module "net" {
source = "zoro16/network/hcloud"
version = "1.0.0"
create_network = true
network_name = "example-network"
network_ip_cidr_range = "10.100.0.0/16"
network_delete_protection = false
network_expose_routes_to_vswitch = false
network_labels = {
name = "example-network"
environment = "dev"
}
create_subnet = true
subnet_type = "cloud"
subnet_ip_cidr_range = "10.100.0.0/24"
subnet_network_zone = "eu-central"
subnet_network_id = module.net.network_id
}
module "sv1" {
source = "zoro16/server/hcloud"
version = "1.0.0"
create_server = true
server_name = "sv1"
placement_group_name = "sv1"
labels = {
environment = "dev"
product = "lb-servers"
}
}
module "lb" {
source = "../../"
create_load_balancer = true
load_balancer_name = "my-lb"
load_balancer_type = "lb11"
load_balancer_location = "nbg1"
# load_balancer_network_zone = "eu-central"
load_balancer_algorithm_type = "least_connections"
load_balancer_delete_protection = false
load_balancer_labels = {
type = "demo"
environment = "dev"
}
create_load_balancer_network = true
load_balancer_network_load_balancer_id = module.lb.load_balancer_id
# load_balancer_network_network_id = module.net.network_id
# load_balancer_network_ip = "10.100.1.5"
load_balancer_network_subnet_id = module.net.subnet_id
load_balancer_network_enable_public_interface = true
create_load_balancer_target = true
load_balancer_target_type = "label_selector"
load_balancer_target_load_balancer_id = module.lb.load_balancer_id
# load_balancer_target_server_id = module.sv1.server_id
load_balancer_target_label_selector = "product=lb-servers"
# load_balancer_target_ip = "142.142.142.142"
# load_balancer_target_use_private_ip = true
create_load_balancer_service = true
load_balancer_service_load_balancer_id = module.lb.load_balancer_id
load_balancer_service_protocol = "http"
load_balancer_service_listen_port = 80
load_balancer_service_destination_port = 80
load_balancer_service_proxyprotocol = false
load_balancer_service_http = [
{
sticky_sessions = false
cookie_name = "HCLBSTICKY"
cookie_lifetime = 300
certificates = []
redirect_http = false
}
]
load_balancer_service_health_check = [
{
protocol = "http"
port = 80
interval = 5
timeout = 10
retries = 10
http = [
{
domain = "example.com"
path = "/healthz"
response = "Ok"
tls = false
status_codes = ["200", "201"]
}
]
}
]
}| Name | Version |
|---|---|
| terraform | >= 1.2.0 |
| hcloud | >= 1.49.1 |
| Name | Version |
|---|---|
| hcloud | >= 1.49.1 |
No modules.
| Name | Type |
|---|---|
| hcloud_load_balancer.load_balancer | resource |
| hcloud_load_balancer_network.lb_net | resource |
| hcloud_load_balancer_service.lb_service | resource |
| hcloud_load_balancer_target.lb_target | resource |
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
| create_load_balancer | Whether to create a Load Balancer or not. | bool |
false |
no |
| create_load_balancer_network | Whether to create a Load Balancer Network or not. | bool |
false |
no |
| create_load_balancer_service | Whether to create a Load Balancer Service or not. | bool |
false |
no |
| create_load_balancer_target | Whether to create a Load Balancer Target or not. | bool |
false |
no |
| load_balancer_algorithm_type | Configuration of the algorithm the Load Balancer use. algorithm support the following fields: type - (Required, string) Type of the Load Balancer Algorithm. round_robin or least_connections |
string |
"round_robin" |
no |
| load_balancer_delete_protection | Enable or disable delete protection. | bool |
false |
no |
| load_balancer_labels | User-defined labels (key-value pairs) should be created with. | map(any) |
{} |
no |
| load_balancer_location | The location name of the Load Balancer. Require when no network_zone is set. | string |
"nbg1-dc3" |
no |
| load_balancer_name | Name of the Load Balancer. | string |
null |
no |
| load_balancer_network_enable_public_interface | Enable or disable the Load Balancers public interface. | bool |
true |
no |
| load_balancer_network_ip | IP to request to be assigned to this Load Balancer. If you do not provide this then you will be auto assigned an IP address. | string |
null |
no |
| load_balancer_network_load_balancer_id | ID of the Load Balancer. | number |
null |
no |
| load_balancer_network_network_id | ID of the network which should be added to the Load Balancer. Required if subnet_id is not set. Successful creation of the resource depends on the existence of a subnet in the Hetzner Cloud Backend. Using network_id will not create an explicit dependency between the Load Balancer and the subnet. Therefore depends_on may need to be used. Alternatively the subnet_id property can be used, which will create an explicit dependency between hcloud_load_balancer_network and the existence of a subnet. |
number |
null |
no |
| load_balancer_network_subnet_id | ID of the sub-network which should be added to the Load Balancer. Required if network_id is not set. Note: if the ip property is missing, the Load Balancer is currently added to the last created subnet. |
string |
null |
no |
| load_balancer_network_zone | The Network Zone of the Load Balancer. Require when no location is set. | string |
"eu-central" |
no |
| load_balancer_service_destination_port | Port the service connects to the targets on, required if protocol is tcp. Can be everything between 1 and 65535. | number |
80 |
no |
| load_balancer_service_health_check | List of health check configurations when protocol is http or https. | list(object({ |
null |
no |
| load_balancer_service_http | List of http configurations when protocol is http or https. | list(object({ |
null |
no |
| load_balancer_service_listen_port | Port the service listen on, required if protocol is tcp. Can be everything between 1 and 65535. Must be unique per Load Balancer. | number |
80 |
no |
| load_balancer_service_load_balancer_id | Id of the load balancer this service belongs to. | string |
null |
no |
| load_balancer_service_protocol | Protocol of the service. http, https or tcp | string |
"http" |
no |
| load_balancer_service_proxyprotocol | Whether to enable proxyprotocol or not. | bool |
false |
no |
| load_balancer_target_ip | IP address for an IP Target. Required if type is ip. | string |
null |
no |
| load_balancer_target_label_selector | Label Selector selecting targets for this Load Balancer. Required if type is label_selector. | string |
null |
no |
| load_balancer_target_load_balancer_id | ID of the Load Balancer to which the target gets attached. | string |
null |
no |
| load_balancer_target_server_id | ID of the server which should be a target for this Load Balancer. Required if type is server | number |
null |
no |
| load_balancer_target_type | Type of the target. Possible values server, label_selector, ip."server => VM Serverlabel_selector => All servers that match this label query will be used as a target.ip => Dedicated Server (root) IP address |
string |
"server" |
no |
| load_balancer_target_use_private_ip | Use the private IP to connect to Load Balancer targets. Only allowed if type is server or label_selector. | bool |
null |
no |
| load_balancer_type | Type of the Load Balancer. | string |
"lb11" |
no |
| Name | Description |
|---|---|
| load_balancer_algorithm | Configuration of the algorithm the Load Balancer use. |
| load_balancer_delete_protection | Enable or disable delete protection. |
| load_balancer_first_network_id | ID of the first private network that this Load Balancer is connected to. |
| load_balancer_first_network_ip | IP of the Load Balancer in the first private network that it is connected to. |
| load_balancer_id | Unique ID of the Load Balancer. |
| load_balancer_ipv4 | IPv4 Address of the Load Balancer. |
| load_balancer_ipv6 | IPv6 Address of the Load Balancer. |
| load_balancer_labels | User-defined labels (key-value pairs) should be created with. |
| load_balancer_location | The location name of the Load Balancer. Require when no network_zone is set. |
| load_balancer_name | Name of the Load Balancer. |
| load_balancer_network_id | ID of the Load Balancer network. |
| load_balancer_network_load_balancer_id | ID of the Load Balancer. |
| load_balancer_network_network_id | ID of the network. |
| load_balancer_network_network_ip | IP assigned to this Load Balancer. |
| load_balancer_service_destination_port | Port the service connects to the targets on, required if protocol is tcp. Can be everything between 1 and 65535. |
| load_balancer_service_health_check | List of health check configurations when protocol is http or https. |
| load_balancer_service_http | List of http configurations when protocol is http or https. |
| load_balancer_service_listen_port | Port the service listen on, required if protocol is tcp. Can be everything between 1 and 65535. Must be unique per Load Balancer. |
| load_balancer_service_protocol | Protocol of the service. http, https or tcp |
| load_balancer_service_proxyprotocol | Whether to enable proxyprotocol or not. |
| load_balancer_target_ip | IP address for an IP Target. Required if type is ip. |
| load_balancer_target_label_selector | Label Selector selecting targets for this Load Balancer. Required if type is label_selector. |
| load_balancer_target_server_id | ID of the server which should be a target for this Load Balancer. Required if type is server |
| load_balancer_target_type | Type of the target. Possible values server, label_selector, ip. |
| load_balancer_target_use_private_ip | Use the private IP to connect to Load Balancer targets. Only allowed if type is server or label_selector. |
| load_balancer_type | Type of the Load Balancer. |