Skip to content

Commit 040c2bc

Browse files
committed
use first network as access network and support extra_networks only
1 parent 83a0a85 commit 040c2bc

File tree

5 files changed

+23
-24
lines changed

5 files changed

+23
-24
lines changed

docs/networks.md

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# Networks
1+
# Networking
22

33
The default OpenTofu configurations in the appliance do not provision networks,
44
subnets or associated infrastructure such as routers. The requirements are that:
55
1. At least one network exists.
6-
2. At least one network spans all nodes, referred to as the "access network".
6+
2. The first network defined spans all nodes, referred to as the "access network".
77
3. Only one subnet per network is attached to nodes.
8-
4. At least one network on each node provides outbound internet access (either directly,
9-
or via a proxy).
8+
4. At least one network on each node provides outbound internet access (either
9+
directly, or via a proxy).
1010

1111
Futhermore, it is recommended that the deploy host has an interface on the
1212
access network. While it is possible to e.g. use a floating IP on a login node
@@ -40,18 +40,17 @@ cluster_networks = [
4040
```
4141

4242
## Multiple homogenous networks
43-
This is similar to the above, except each node has multiple networks. Therefore
44-
`access_network` must be explicitly set. Note that only one subnet must have
45-
a gateway defined, else default routes via both subnets will be present causing
46-
routing problems. It also shows the second network (netB) using direct-type vNICs
47-
for RDMA.
43+
This is similar to the above, except each node has multiple networks. The first
44+
network, "netA" is the access network. Note that only one subnet must have a
45+
gateway defined, else default routes via both subnets will be present causing
46+
routing problems. It also shows the second network (netB) using direct-type
47+
vNICs for RDMA.
4848

4949
```terraform
5050
cluster_networks = [
5151
{
5252
network = "netA"
5353
subnet = "subnetA"
54-
access_network = true
5554
},
5655
{
5756
network = "netB"
@@ -68,7 +67,7 @@ vnic_types = {
6867

6968
## Additional networks on some nodes
7069

71-
This example shows how to override variables for specific node groups. In this
70+
This example shows how to modify variables for specific node groups. In this
7271
case a baremetal node group has a second network attached. As above, only a
7372
single subnet can have a gateway IP.
7473

@@ -86,12 +85,7 @@ compute = {
8685
}
8786
baremetal = {
8887
nodes = ["baremetal-0", "baremetal-1"]
89-
networks = [
90-
{
91-
network = "netA"
92-
subnet = "subnetA"
93-
access_network = true
94-
},
88+
extra_networks = [
9589
{
9690
network = "netB"
9791
subnet = "subnetB"
@@ -101,6 +95,7 @@ compute = {
10195
netA = "baremetal"
10296
netB = "baremetal"
10397
...
98+
}
10499
}
105100
}
106101
...

environments/skeleton/{{cookiecutter.environment}}/tofu/compute.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ module "compute" {
1414
environment_root = var.environment_root
1515

1616
# can be set for group, defaults to top-level value:
17-
networks = lookup(each.value, "networks", var.cluster_networks)
1817
image_id = lookup(each.value, "image_id", var.cluster_image_id)
1918
vnic_types = lookup(each.value, "vnic_types", var.vnic_types)
2019
vnic_profiles = lookup(each.value, "vnic_profiles", var.vnic_profiles)
2120
volume_backed_instances = lookup(each.value, "volume_backed_instances", var.volume_backed_instances)
2221
root_volume_size = lookup(each.value, "root_volume_size", var.root_volume_size)
22+
23+
# optionally set for group
24+
networks = concat(var.cluster_networks, lookup(each.value, "extra_networks", []))
2325
extra_volumes = lookup(each.value, "extra_volumes", {})
2426
compute_init_enable = lookup(each.value, "compute_init_enable", [])
2527
ignore_image_changes = lookup(each.value, "ignore_image_changes", false)

environments/skeleton/{{cookiecutter.environment}}/tofu/login.tf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,17 @@ module "login" {
1111
cluster_domain_suffix = var.cluster_domain_suffix
1212

1313
# can be set for group, defaults to top-level value:
14-
networks = lookup(each.value, "networks", var.cluster_networks)
1514
image_id = lookup(each.value, "image_id", var.cluster_image_id)
1615
vnic_types = lookup(each.value, "vnic_types", var.vnic_types)
1716
vnic_profiles = lookup(each.value, "vnic_profiles", var.vnic_profiles)
1817
volume_backed_instances = lookup(each.value, "volume_backed_instances", var.volume_backed_instances)
1918
root_volume_size = lookup(each.value, "root_volume_size", var.root_volume_size)
19+
20+
# optionally set for group
21+
networks = concat(var.cluster_networks, lookup(each.value, "extra_networks", []))
2022
extra_volumes = lookup(each.value, "extra_volumes", {})
2123

24+
# can't be set for login
2225
compute_init_enable = []
2326
ignore_image_changes = false
2427

environments/skeleton/{{cookiecutter.environment}}/tofu/node_group/nodes.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ resource "openstack_compute_instance_v2" "compute_fixed_image" {
7878
for_each = {for net in var.networks: net.network => net}
7979
content {
8080
port = openstack_networking_port_v2.compute["${each.key}-${network.key}"].id
81-
access_network = length(var.networks) == 1 ? true : lookup(network.value, "access_network", false)
81+
access_network = network.key == var.networks[0].network
8282
}
8383
}
8484

@@ -129,7 +129,7 @@ resource "openstack_compute_instance_v2" "compute" {
129129
for_each = {for net in var.networks: net.network => net}
130130
content {
131131
port = openstack_networking_port_v2.compute["${each.key}-${network.key}"].id
132-
access_network = length(var.networks) == 1 ? true : lookup(network.value, "access_network", false)
132+
access_network = network.key == var.networks[0].network
133133
}
134134
}
135135

environments/skeleton/{{cookiecutter.environment}}/tofu/variables.tf

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ variable "cluster_networks" {
1515
List of mappings defining networks. Mapping key/values:
1616
network: Name of existing network
1717
subnet: Name of existing subnet
18-
access_network: Bool defining whether to use network for Ansible and
19-
K3s. This network must be present on all nodes.
20-
Defaults to true if only one network is specified.
2118
EOT
2219
}
2320

@@ -46,6 +43,7 @@ variable "login" {
4643
flavor: String flavor name
4744
Optional:
4845
image_id: Overrides variable cluster_image_id
46+
extra_networks: List of mappings in same format as cluster_networks
4947
vnic_type: Overrides variable vnic_type
5048
vnic_profile: Overrides variable vnic_profile
5149
volume_backed_instances: Overrides variable volume_backed_instances
@@ -77,6 +75,7 @@ variable "compute" {
7775
flavor: String flavor name
7876
Optional:
7977
image_id: Overrides variable cluster_image_id
78+
extra_networks: List of mappings in same format as cluster_networks
8079
vnic_type: Overrides variable vnic_type
8180
vnic_profile: Overrides variable vnic_profile
8281
compute_init_enable: Toggles compute-init rebuild (see compute-init role docs)

0 commit comments

Comments
 (0)