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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions docs/resources/network_peer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# 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" "network1" {
name = "lan0"
type = "ovn"

config = {
# ...
}
}

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

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

resource "incus_network_peer" "lan1_lan0"{
name = "lab1-lan0"
description = "A meaningful description"
network = "lan1"
project = "default"
target_network = "lan0"
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.
58 changes: 28 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,14 @@ 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 {
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)
}
Loading
Loading