Update loadbalancer example to use stackit sources instead of openstack (#601)

Signed-off-by: Alexander Dahmen <alexander.dahmen@inovex.de>
This commit is contained in:
Alexander Dahmen 2024-12-02 13:52:12 +01:00 committed by GitHub
parent 0b1b13eb80
commit 58e99b4d67
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 95 additions and 195 deletions

View file

@ -4,31 +4,7 @@ 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.
The example below creates the supporting infrastructure using the STACKIT Terraform provider, including the network, network interface, a public IP address and server resources.
---
# stackit_loadbalancer (Resource)
@ -36,99 +12,60 @@ 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
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.
The example below creates the supporting infrastructure using the STACKIT Terraform provider, including the network, network interface, a public IP address and server resources.
## 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
resource "stackit_network" "example_network" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
name = "example-network"
ipv4_nameservers = ["8.8.8.8"]
ipv4_prefix = "192.168.0.0/25"
labels = {
"key" = "value"
}
routed = true
}
network {
name = openstack_networking_network_v2.example.name
# Create a network interface
resource "stackit_network_interface" "nic" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
network_id = stackit_network.example_network.network_id
}
# Create a public IP and assign it to the network interface
resource "stackit_public_ip" "public-ip" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
network_interface_id = stackit_network_interface.nic.network_interface_id
}
# Create a key pair for accessing the server instance
resource "stackit_key_pair" "keypair" {
name = "example-key-pair"
public_key = chomp(file("path/to/id_rsa.pub"))
}
# Create a server instance
resource "stackit_server" "boot-from-volume" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
name = "example-server"
boot_volume = {
size = 64
source_type = "image"
source_id = "59838a89-51b1-4892-b57f-b3caf598ee2f" // Ubuntu 24.04
}
availability_zone = "xxxx-x"
machine_type = "g1.1"
keypair_name = stackit_key_pair.keypair.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
# Attach the network interface to the server
resource "stackit_server_network_interface_attach" "nic-attachment" {
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
server_id = stackit_server.boot-from-volume.server_id
network_interface_id = stackit_network_interface.nic.network_interface_id
}
# Create a load balancer
@ -142,7 +79,7 @@ resource "stackit_loadbalancer" "example" {
targets = [
{
display_name = "example-target"
ip = openstack_compute_instance_v2.example.network.0.fixed_ip_v4
ip = stackit_network_interface.nic.ipv4
}
]
active_health_check = {
@ -164,11 +101,11 @@ resource "stackit_loadbalancer" "example" {
]
networks = [
{
network_id = openstack_networking_network_v2.example.id
network_id = stackit_network.example_network.network_id
role = "ROLE_LISTENERS_AND_TARGETS"
}
]
external_address = openstack_networking_floatingip_v2.example.address
external_address = stackit_public_ip.public-ip.ip
options = {
private_network_only = false
}