diff --git a/environments/skeleton/{{cookiecutter.environment}}/terraform/compute.tf b/environments/skeleton/{{cookiecutter.environment}}/terraform/compute.tf index a90108924..141ff3fd1 100644 --- a/environments/skeleton/{{cookiecutter.environment}}/terraform/compute.tf +++ b/environments/skeleton/{{cookiecutter.environment}}/terraform/compute.tf @@ -19,6 +19,8 @@ module "compute" { volume_backed_instances = lookup(each.value, "volume_backed_instances", var.volume_backed_instances) root_volume_size = lookup(each.value, "root_volume_size", var.root_volume_size) extra_volumes = lookup(each.value, "extra_volumes", {}) + gateway_nmcli_connection = lookup(each.value, "gateway_nmcli_connection", "") + gateway_ip = lookup(each.value, "gateway_ip", "") compute_init_enable = lookup(each.value, "compute_init_enable", []) diff --git a/environments/skeleton/{{cookiecutter.environment}}/terraform/compute/nodes.tf b/environments/skeleton/{{cookiecutter.environment}}/terraform/compute/nodes.tf index 9bb75466e..fee03098d 100644 --- a/environments/skeleton/{{cookiecutter.environment}}/terraform/compute/nodes.tf +++ b/environments/skeleton/{{cookiecutter.environment}}/terraform/compute/nodes.tf @@ -86,6 +86,18 @@ resource "openstack_compute_instance_v2" "compute" { user_data = <<-EOF #cloud-config fqdn: ${var.cluster_name}-${each.key}.${var.cluster_name}.${var.cluster_domain_suffix} + + runcmd: +%{ if var.gateway_nmcli_connection == "dummy0" ~} + - nmcli connection add type dummy ifname dummy0 con-name dummy0 + - 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 +%{ endif ~} +%{ if (var.gateway_nmcli_connection != "") && (var.gateway_nmcli_connection != "dummy0") ~} + - 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} +%{ endif ~} +%{ if var.gateway_nmcli_connection != "" } + - nmcli connection up '${var.gateway_nmcli_connection}' +%{ endif ~} EOF } diff --git a/environments/skeleton/{{cookiecutter.environment}}/terraform/compute/variables.tf b/environments/skeleton/{{cookiecutter.environment}}/terraform/compute/variables.tf index b0e489017..05d6b162e 100644 --- a/environments/skeleton/{{cookiecutter.environment}}/terraform/compute/variables.tf +++ b/environments/skeleton/{{cookiecutter.environment}}/terraform/compute/variables.tf @@ -93,4 +93,16 @@ variable "compute_init_enable" { type = list(string) description = "Groups to activate for ansible-init compute rebuilds" default = [] -} \ No newline at end of file +} + +variable "gateway_nmcli_connection" { + description = "Name of nmcli connection for default gateway, '' for none or 'dummy0' to create a dummy interface" + type = string + default = "" +} + +variable "gateway_ip" { + description = "IP of default gateway. Ignored when gateway_nmcli_connection == 'dummy0'" + type = string + default = "" +} diff --git a/environments/skeleton/{{cookiecutter.environment}}/terraform/variables.tf b/environments/skeleton/{{cookiecutter.environment}}/terraform/variables.tf index bdffd40ce..5a5722175 100644 --- a/environments/skeleton/{{cookiecutter.environment}}/terraform/variables.tf +++ b/environments/skeleton/{{cookiecutter.environment}}/terraform/variables.tf @@ -60,6 +60,11 @@ variable "compute" { Values are a mapping with: size: Size of volume in GB **NB**: The order in /dev is not guaranteed to match the mapping + gateway_nmcli_connection: Name of nmcli connection to set a default + route on via cloud-init, e.g. "System eth0" + or "Bond bond0". Use "dummy0" to create + a dummy interface with dummy route. + gateway_ip: IP of default gateway. Ignored when gateway_nmcli_connection == "dummy0". EOF }