* Implement acceptance test * Add resource and data source to the provider * Add examples and markdown description * Generate docs * Adjustments after review * Move load balancer supporting infrastructure from resource config to example
8.2 KiB
8.2 KiB
| page_title | subcategory | description |
|---|---|---|
| stackit_loadbalancer Resource - stackit | 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" { userdomainname = "{OpenStack user domain name}" username = "{OpenStack username}" password = "{OpenStack password}" region = "RegionOne" authurl = "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 {
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
# 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)name(String) Load balancer name.networks(Attributes List) List of networks that listeners and targets reside in. (see below for nested schema)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)
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)
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.target_pool(String) Reference target pool by target pool name.
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.
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)
Optional:
active_health_check(Attributes) (see below for nested schema)
Nested Schema for target_pools.targets
Required:
display_name(String) Target display nameip(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 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.