Skip to content

Commit 5542656

Browse files
committed
add cloud-init gateway setup for compute nodes
1 parent 4abfaf6 commit 5542656

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ module "compute" {
1919
volume_backed_instances = lookup(each.value, "volume_backed_instances", var.volume_backed_instances)
2020
root_volume_size = lookup(each.value, "root_volume_size", var.root_volume_size)
2121
extra_volumes = lookup(each.value, "extra_volumes", {})
22+
gateway_nmcli_connection = lookup(each.value, "gateway_nmcli_connection", "")
23+
gateway_ip = lookup(each.value, "gateway_ip", "")
2224

2325
compute_init_enable = lookup(each.value, "compute_init_enable", [])
2426

environments/skeleton/{{cookiecutter.environment}}/terraform/compute/nodes.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,18 @@ resource "openstack_compute_instance_v2" "compute" {
8686
user_data = <<-EOF
8787
#cloud-config
8888
fqdn: ${var.cluster_name}-${each.key}.${var.cluster_name}.${var.cluster_domain_suffix}
89+
90+
runcmd:
91+
%{ if var.gateway_nmcli_connection == "dummy0" ~}
92+
- nmcli connection add type dummy ifname dummy0 con-name dummy0
93+
- nmcli connection modify dummy0 ipv4.address ${openstack_networking_port_v2.compute[each.key].all_fixed_ips[0]} ipv4.gateway ${openstack_networking_port_v2.compute[each.key].all_fixed_ips[0]} ipv4.route-metric 1000 ipv4.method manual
94+
%{ endif ~}
95+
%{ if (var.gateway_nmcli_connection != "") && (var.gateway_nmcli_connection != "dummy0") ~}
96+
- nmcli connection modify '${var.gateway_nmcli_connection}' ipv4.address ${openstack_networking_port_v2.compute[each.key].all_fixed_ips[0]} ipv4.gateway ${var.gateway_ip}
97+
%{ endif ~}
98+
%{ if var.gateway_nmcli_connection != "" }
99+
- nmcli connection up '${var.gateway_nmcli_connection}'
100+
%{ endif ~}
89101
EOF
90102

91103
}

environments/skeleton/{{cookiecutter.environment}}/terraform/compute/variables.tf

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,16 @@ variable "compute_init_enable" {
9393
type = list(string)
9494
description = "Groups to activate for ansible-init compute rebuilds"
9595
default = []
96-
}
96+
}
97+
98+
variable "gateway_nmcli_connection" {
99+
description = "Name of nmcli connection for default gateway, '' for none or 'dummy0' to create a dummy interface"
100+
type = string
101+
default = ""
102+
}
103+
104+
variable "gateway_ip" {
105+
description = "IP of default gateway. Ignored when gateway_nmcli_connection == 'dummy0'"
106+
type = string
107+
default = ""
108+
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ variable "compute" {
6060
Values are a mapping with:
6161
size: Size of volume in GB
6262
**NB**: The order in /dev is not guaranteed to match the mapping
63+
gateway_nmcli_connection: Name of nmcli connection to set a default
64+
route on via cloud-init, e.g. "System eth0"
65+
or "Bond bond0". Use "dummy0" to create
66+
a dummy interface with dummy route.
67+
gateway_ip: IP of default gateway. Ignored when gateway_nmcli_connection == "dummy0".
6368
EOF
6469
}
6570

0 commit comments

Comments
 (0)