Skip to content

Commit

Permalink
Merge pull request #360 from MusicDin/feature/network-lb
Browse files Browse the repository at this point in the history
Add load balancer resource
  • Loading branch information
simondeziel authored Oct 27, 2023
2 parents a4db600 + b2b30e4 commit a3019e1
Show file tree
Hide file tree
Showing 6 changed files with 790 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@ jobs:
sudo lxd init --auto --trust-password="$LXD_PASSWORD" --network-port=8443 --network-address='[::]'
sudo chmod 777 /var/snap/lxd/common/lxd/unix.socket
- name: Configure OVN
run: |
sudo apt-get install --no-install-recommends --yes \
ovn-host \
ovn-central \
bind9-dnsutils \
jq
sudo ovs-vsctl set open_vswitch . \
external_ids:ovn-remote=unix:/var/run/ovn/ovnsb_db.sock \
external_ids:ovn-encap-type=geneve \
external_ids:ovn-encap-ip=127.0.0.1
- name: Install dependencies
run: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin
Expand Down
102 changes: 102 additions & 0 deletions docs/resources/network_load_balancer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# lxd_network_load_balancer

LXD load balancer resource forwards ports from external IPs to internal ones within its network,
distributing traffic among multiple backends.

-> The load balancer resource is exclusively compatible with OVN (Open Virtual Network).

For more information, please refer to [How to configuration network load balancers](https://documentation.ubuntu.com/lxd/en/latest/howto/network_load_balancers/)
in the official LXD documentation.

## Example Usage

```hcl
resource "lxd_network" "network" {
name = "ovn"
type = "ovn"
config = {
...
}
}
resource "lxd_network_lb" "load_balancer" {
network = lxd_network.network.name
description = "My Load Balancer"
listen_address = "10.10.10.200"
config = {
"key" = "value"
}
backend {
name = "instance-1"
description = "Load Balancer Backend"
target_address = "10.0.0.10"
target_port = "80"
}
backend {
name = "instance-2"
description = "Load Balancer Backend"
target_address = "10.0.0.11"
target_port = "80"
}
port {
description = "Port 8080/tcp"
protocol = "tcp"
listen_port = "8080"
target_backend = [
"instance-1",
"instance-2",
]
}
}
```

## Argument Reference

* `remote` - *Optional* - The remote in which the resource will be created. If
it is not provided, the default provider remote is used.

* `project` - *Optional* - Name of the project where the load balancer will be spawned.

* `network` - *Required* - Name of the uplink network.

* `listen_address` - *Required* - IP address to listen on. Also, see the [Requirements for listen address](https://documentation.ubuntu.com/lxd/en/latest/howto/network_load_balancers/#requirements-for-listen-addresses) in the official LXD documentation.

* `description` - *Optional* - Description of the network load balancer.

* `config` - *Optional* - Map of key/value pairs (load balancer's currently support only `user.*` keys).

* `backend` - *Optional* - Load balancer's backend definition. See reference below.

* `port` - *Optional* - Load balancer's port definition. See reference below.

The `backend` block supports:

* `name` - *Required* - Name of the load balancer's backend.

* `target_address` - *Required* - IP address to forward to.

* `target_port` - *Optional* - Target port(s) (e.g. `80`, `80,32000-32080`). Default: *`listen_port` of the corresponding `port` block*

* `description` - *Optional* - Description of the load balancer's backend.

The `port` block supports:

* `listen_port` - *Required* - Listen port(s) (e.g. `80`, `80,32000-32080`).

* `target_backend` - *Required* - Backend name(s) to forward to.

* `protocol` - *Optional* - Protocol of the port(s). Can be either `tcp` or `udp`. Default: `tcp`

* `description` - *Optional* - Description of the load balancer's port.

## Attribute Reference

No attributes are exported.


1 change: 1 addition & 0 deletions lxd/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ func Provider() *schema.Provider {
"lxd_instance": resourceLxdInstance(),
"lxd_instance_file": resourceLxdInstanceFile(),
"lxd_network": resourceLxdNetwork(),
"lxd_network_lb": resourceLxdNetworkLB(),
"lxd_network_zone": resourceLxdNetworkZone(),
"lxd_network_zone_record": resourceLxdNetworkZoneRecord(),
"lxd_profile": resourceLxdProfile(),
Expand Down
Loading

0 comments on commit a3019e1

Please sign in to comment.