Skip to content

Commit

Permalink
Update loadbalancer example to use stackit sources instead of opensta…
Browse files Browse the repository at this point in the history
…ck (#601)

Signed-off-by: Alexander Dahmen <[email protected]>
  • Loading branch information
Fyusel authored Dec 2, 2024
1 parent 0b1b13e commit 58e99b4
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 183 deletions.
147 changes: 42 additions & 105 deletions docs/resources/loadbalancer.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,131 +4,68 @@ 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)

## 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
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
}
# Get public network
data "openstack_networking_network_v2" "public" {
name = "floating-net"
# 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 floating IP
resource "openstack_networking_floatingip_v2" "example" {
pool = data.openstack_networking_network_v2.public.name
# 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
}
# Get flavor for instance
data "openstack_compute_flavor_v2" "example" {
name = "g1.1"
# 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 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 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
Expand All @@ -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 = {
Expand All @@ -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
}
Expand Down
91 changes: 40 additions & 51 deletions examples/resources/stackit_loadbalancer/resource.tf
Original file line number Diff line number Diff line change
@@ -1,63 +1,52 @@
# 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
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
}

# Get public network
data "openstack_networking_network_v2" "public" {
name = "floating-net"
# 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 floating IP
resource "openstack_networking_floatingip_v2" "example" {
pool = data.openstack_networking_network_v2.public.name
# 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
}

# Get flavor for instance
data "openstack_compute_flavor_v2" "example" {
name = "g1.1"
# 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 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 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
Expand All @@ -71,7 +60,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 = {
Expand All @@ -93,11 +82,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
}
Expand Down
28 changes: 1 addition & 27 deletions stackit/internal/services/loadbalancer/loadbalancer/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,33 +262,7 @@ func (r *loadBalancerResource) Schema(_ context.Context, _ resource.SchemaReques
MarkdownDescription: `
## Setting up supporting infrastructure` + "\n" + `
### Configuring an OpenStack provider` + "\n" + `
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:` + "\n" +
"```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"
}
` + "\n```" + `
### 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.
`,
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
Expand Down

0 comments on commit 58e99b4

Please sign in to comment.