---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "stackit_loadbalancer Resource - stackit"
subcategory: ""
description: |-
Setting up supporting infrastructure
Configuring an OpenStack provider
To automate the creation of load balancers, OpenStack can be used to setup the supporting infrastructure.
To set up the OpenStack provider, you can create a token through the STACKIT Portal, in your project's Infrastructure API page.
There, the OpenStack user domain name, username, and password are generated and can be obtained. The provider can then be configured as follows:
terraform {
required_providers {
(...)
openstack = {
source = "terraform-provider-openstack/openstack"
}
}
}
provider "openstack" {
user_domain_name = "{OpenStack user domain name}"
user_name = "{OpenStack username}"
password = "{OpenStack password}"
region = "RegionOne"
auth_url = "https://keystone.api.iaas.eu01.stackit.cloud/v3"
}
Configuring the supporting infrastructure
The example below uses OpenStack to create the network, router, a public IP address and a compute instance.
---
# stackit_loadbalancer (Resource)
## Setting up supporting infrastructure
### Configuring an OpenStack provider
To automate the creation of load balancers, OpenStack can be used to setup the supporting infrastructure.
To set up the OpenStack provider, you can create a token through the STACKIT Portal, in your project's Infrastructure API page.
There, the OpenStack user domain name, username, and password are generated and can be obtained. The provider can then be configured as follows:
```terraform
terraform {
required_providers {
(...)
openstack = {
source = "terraform-provider-openstack/openstack"
}
}
}
provider "openstack" {
user_domain_name = "{OpenStack user domain name}"
user_name = "{OpenStack username}"
password = "{OpenStack password}"
region = "RegionOne"
auth_url = "https://keystone.api.iaas.eu01.stackit.cloud/v3"
}
```
### Configuring the supporting infrastructure
The example below uses OpenStack to create the network, router, a public IP address and a compute instance.
## Example Usage
```terraform
# Create a network
resource "openstack_networking_network_v2" "example" {
name = "example-network"
}
# Create a subnet
resource "openstack_networking_subnet_v2" "example" {
name = "example-subnet"
cidr = "192.168.0.0/25"
dns_nameservers = ["8.8.8.8"]
network_id = openstack_networking_network_v2.example.id
}
# Get public network
data "openstack_networking_network_v2" "public" {
name = "floating-net"
}
# Create a floating IP
resource "openstack_networking_floatingip_v2" "example" {
pool = data.openstack_networking_network_v2.public.name
}
# Get flavor for instance
data "openstack_compute_flavor_v2" "example" {
name = "g1.1"
}
# Create an instance
resource "openstack_compute_instance_v2" "example" {
depends_on = [openstack_networking_subnet_v2.example]
name = "example-instance"
flavor_id = data.openstack_compute_flavor_v2.example.id
admin_pass = "example"
security_groups = ["default"]
block_device {
uuid = "4364cdb2-dacd-429b-803e-f0f7cfde1c24" // Ubuntu 22.04
volume_size = 32
source_type = "image"
destination_type = "volume"
delete_on_termination = true
}
network {
name = openstack_networking_network_v2.example.name
}
}
# Create a router and attach it to the public network
resource "openstack_networking_router_v2" "example" {
name = "example-router"
admin_state_up = "true"
external_network_id = data.openstack_networking_network_v2.public.id
}
# Attach the subnet to the router
resource "openstack_networking_router_interface_v2" "example_interface" {
router_id = openstack_networking_router_v2.example.id
subnet_id = openstack_networking_subnet_v2.example.id
}
# Create a load balancer
resource "stackit_loadbalancer" "example" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
name = "example-load-balancer"
target_pools = [
{
name = "example-target-pool"
target_port = 80
targets = [
{
display_name = "example-target"
ip = openstack_compute_instance_v2.example.network.0.fixed_ip_v4
}
]
active_health_check = {
healthy_threshold = 10
interval = "3s"
interval_jitter = "3s"
timeout = "3s"
unhealthy_threshold = 10
}
}
]
listeners = [
{
display_name = "example-listener"
port = 80
protocol = "PROTOCOL_TCP"
target_pool = "example-target-pool"
}
]
networks = [
{
network_id = openstack_networking_network_v2.example.id
role = "ROLE_LISTENERS_AND_TARGETS"
}
]
external_address = openstack_networking_floatingip_v2.example.address
options = {
private_network_only = false
}
}
```
## Schema
### Required
- `listeners` (Attributes List) List of all listeners which will accept traffic. Limited to 20. (see [below for nested schema](#nestedatt--listeners))
- `name` (String) Load balancer name.
- `networks` (Attributes List) List of networks that listeners and targets reside in. (see [below for nested schema](#nestedatt--networks))
- `project_id` (String) STACKIT project ID to which the Load Balancer is associated.
- `target_pools` (Attributes List) List of all target pools which will be used in the Load Balancer. Limited to 20. (see [below for nested schema](#nestedatt--target_pools))
### Optional
- `external_address` (String) External Load Balancer IP address where this Load Balancer is exposed.
- `options` (Attributes) Defines any optional functionality you want to have enabled on your load balancer. (see [below for nested schema](#nestedatt--options))
### Read-Only
- `id` (String) Terraform's internal resource ID. It is structured as "`project_id`","`name`".
- `private_address` (String) Transient private Load Balancer IP address. It can change any time.
### Nested Schema for `listeners`
Optional:
- `display_name` (String)
- `port` (Number) Port number where we listen for traffic.
- `protocol` (String) Protocol is the highest network protocol we understand to load balance. Supported values are: `PROTOCOL_UNSPECIFIED`, `PROTOCOL_TCP`, `PROTOCOL_UDP`, `PROTOCOL_TCP_PROXY`, `PROTOCOL_TLS_PASSTHROUGH`.
- `server_name_indicators` (Attributes List) A list of domain names to match in order to pass TLS traffic to the target pool in the current listener (see [below for nested schema](#nestedatt--listeners--server_name_indicators))
- `target_pool` (String) Reference target pool by target pool name.
### Nested Schema for `listeners.server_name_indicators`
Optional:
- `name` (String) A domain name to match in order to pass TLS traffic to the target pool in the current listener
### Nested Schema for `networks`
Required:
- `network_id` (String) Openstack network ID.
Optional:
- `role` (String) The role defines how the load balancer is using the network. Supported values are: `ROLE_UNSPECIFIED`, `ROLE_LISTENERS_AND_TARGETS`, `ROLE_LISTENERS`, `ROLE_TARGETS`.
### Nested Schema for `target_pools`
Required:
- `name` (String) Target pool name.
- `target_port` (Number) Identical port number where each target listens for traffic.
- `targets` (Attributes List) List of all targets which will be used in the pool. Limited to 250. (see [below for nested schema](#nestedatt--target_pools--targets))
Optional:
- `active_health_check` (Attributes) (see [below for nested schema](#nestedatt--target_pools--active_health_check))
- `session_persistence` (Attributes) Here you can setup various session persistence options, so far only "`use_source_ip_address`" is supported. (see [below for nested schema](#nestedatt--target_pools--session_persistence))
### Nested Schema for `target_pools.targets`
Required:
- `display_name` (String) Target display name
- `ip` (String) Target IP
### Nested Schema for `target_pools.active_health_check`
Optional:
- `healthy_threshold` (Number) Healthy threshold of the health checking.
- `interval` (String) Interval duration of health checking in seconds.
- `interval_jitter` (String) Interval duration threshold of the health checking in seconds.
- `timeout` (String) Active health checking timeout duration in seconds.
- `unhealthy_threshold` (Number) Unhealthy threshold of the health checking.
### Nested Schema for `target_pools.session_persistence`
Optional:
- `use_source_ip_address` (Boolean) If true then all connections from one source IP address are redirected to the same target. This setting changes the load balancing algorithm to Maglev.
### Nested Schema for `options`
Optional:
- `acl` (Set of String) Load Balancer is accessible only from an IP address in this range.
- `private_network_only` (Boolean) If true, Load Balancer is accessible only via a private network IP address.