Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new incus_network_peer resource #157

Merged
merged 10 commits into from
Feb 10, 2025
10 changes: 9 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,21 @@ jobs:
sudo apt-get update
sudo apt-get install --no-install-recommends --yes \
ovn-host \
ovn-central
ovn-central \
ovn-ic \
ovn-ic-db

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

sudo ovn-nbctl set NB_Global . \
name=region \
options:ic-route-adv=true \
options:ic-route-learn=true
sudo ovs-vsctl set open_vswitch . external_ids:ovn-is-interconn=true

sudo systemctl restart incus

- name: Install dependencies
Expand Down
1 change: 1 addition & 0 deletions docs/resources/network_integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ resource "incus_network_peer" "this" {
name = "ovn-peer"
network = incus_network.default.name
target_integration = incus_network_integration.this.name
type = "remote"
}
```

Expand Down
77 changes: 77 additions & 0 deletions docs/resources/network_peer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# incus_network_peer

Incus allows creating peer routing relationships between two OVN networks. Using this method, traffic between the two
networks can go directly from one OVN network to the other and thus stays within the OVN subsystem, rather than transiting
through the uplink network.

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

For more information, please refer to [How to create peer routing relationships](https://linuxcontainers.org/incus/docs/main/howto/network_ovn_peers/)
in the official Incus documentation.

## Example Usage

```hcl
resource "incus_network" "lan0" {
name = "lan0"
type = "ovn"

config = {
# ...
}
}

resource "incus_network" "lan1" {
name = "lan1"
type = "ovn"

config = {
# ...
}
}

resource "incus_network_peer" "lan0_lan1"{
name = "lab0-lan1"
description = "A meaningful description"
network = incus_network.lan0.name
project = "default"
target_network = incus_network.lan1.name
target_project = "default"
}

resource "incus_network_peer" "lan1_lan0"{
name = "lab1-lan0"
description = "A meaningful description"
network = incus_network.lan1.name
project = "default"
target_network = incus_network.lan0.name
target_project = "default"
}
```

## Argument Reference

* `name` - **required** - Name of the network peering on the local network

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

* `target_network` - **required** - Which network to create a peering with (required at create time for local peers)

* `description` - *Optional* - Description of the network peering

* `config` - *Optional* - Configuration options as key/value pairs (only user.* custom keys supported)

* `type` - *Optional* - Type of network peering

* `target_intergration` - *Optional* - Name of the integration (required at create time for remote peers)

* `target_project` - *Optional* - Which project the target network exists in (required at create time for local peers)

* `project` - *Optional* - Name of the project where the network is located.

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

## Attribute Reference

No attributes are exported.
63 changes: 33 additions & 30 deletions internal/network/resource_network_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,24 +95,23 @@ func TestAccNetworkIntegration_withInvalidType(t *testing.T) {
})
}

// Waiting for https://github.com/lxc/terraform-provider-incus/issues/123
// func TestAccNetworkIntegration_attach(t *testing.T) {
// resource.Test(t, resource.TestCase{
// PreCheck: func() {
// acctest.PreCheck(t)
// acctest.PreCheckAPIExtensions(t, "network_integrations")
// },
// ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories,
// Steps: []resource.TestStep{
// {
// Config: testAccNetworkIntegration_attach(),
// Check: resource.ComposeTestCheckFunc(
// resource.TestCheckResourceAttr("incus_network_integration.test", "name", "test"),
// ),
// },
// },
// })
// }
func TestAccNetworkIntegration_attach(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
acctest.PreCheck(t)
acctest.PreCheckAPIExtensions(t, "network_integrations")
},
ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccNetworkIntegration_attach(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("incus_network_integration.test", "name", "test"),
),
},
},
})
}

func testAccNetworkIntegration_basic() string {
return `
Expand Down Expand Up @@ -154,15 +153,19 @@ resource "incus_network_integration" "test" {
`, networkIntegrationType)
}

// Waiting for https://github.com/lxc/terraform-provider-incus/issues/123
// func testAccNetworkIntegration_attach() string {
// networkIntegrationRes := `
// resource "incus_network_peer" "test" {
// name = "ovn-lan1"
// network = incus_network.ovn.name
// target_integration = incus_network_integration.test.name
// type = "ovn"
// }
// `
// return fmt.Sprintf("%s\n%s\n%s", ovnNetworkResource(), testAccNetworkIntegration_basic(), networkIntegrationRes)
// }
func testAccNetworkIntegration_attach() string {
networkIntegrationConfig := map[string]string{
"ovn.northbound_connection": "unix:/var/run/ovn/ovn_ic_nb_db.sock",
"ovn.southbound_connection": "unix:/var/run/ovn/ovn_ic_sb_db.sock",
}

networkIntegrationRes := `
resource "incus_network_peer" "test" {
name = "ovn-lan1"
network = incus_network.ovn.name
target_integration = incus_network_integration.test.name
type = "remote"
}
`
return fmt.Sprintf("%s\n%s\n%s", ovnNetworkResource(), testAccNetworkIntegration_withConfig(networkIntegrationConfig), networkIntegrationRes)
}
Loading
Loading