From d669b93c4fe4d7fe98a2a508d03233e3d1465365 Mon Sep 17 00:00:00 2001 From: Fredrik Liv Date: Wed, 20 Sep 2023 12:22:01 +0200 Subject: [PATCH] terraform-openstack: Added possibility to enable dhcp flag critical on one interface (#10446) * terraform-openstack: Updated extra partitions to use empty list by default * terraform-openstack: Added possibility to enable dhcp flag critical on one interface --- contrib/terraform/openstack/README.md | 1 + .../openstack/modules/compute/main.tf | 7 ++++--- .../compute/templates/cloudinit.yaml.tmpl | 19 +++++++++++++++++-- .../openstack/modules/compute/variables.tf | 5 +++-- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/contrib/terraform/openstack/README.md b/contrib/terraform/openstack/README.md index d570e11fc..a99669276 100644 --- a/contrib/terraform/openstack/README.md +++ b/contrib/terraform/openstack/README.md @@ -318,6 +318,7 @@ k8s_nodes: mount_path: string # Path to where the partition should be mounted partition_start: string # Where the partition should start (e.g. 10GB ). Note, if you set the partition_start to 0 there will be no space left for the root partition partition_end: string # Where the partition should end (e.g. 10GB or -1 for end of volume) + netplan_critical_dhcp_interface: string # Name of interface to set the dhcp flag critical = true, to circumvent [this issue](https://bugs.launchpad.net/ubuntu/+source/systemd/+bug/1776013). ``` For example: diff --git a/contrib/terraform/openstack/modules/compute/main.tf b/contrib/terraform/openstack/modules/compute/main.tf index 6a5e0bcf7..64ccc7ff0 100644 --- a/contrib/terraform/openstack/modules/compute/main.tf +++ b/contrib/terraform/openstack/modules/compute/main.tf @@ -19,8 +19,8 @@ data "cloudinit_config" "cloudinit" { part { content_type = "text/cloud-config" content = templatefile("${path.module}/templates/cloudinit.yaml.tmpl", { - # template_file doesn't support lists - extra_partitions = "" + extra_partitions = [], + netplan_critical_dhcp_interface = "" }) } } @@ -821,7 +821,8 @@ resource "openstack_compute_instance_v2" "k8s_nodes" { flavor_id = each.value.flavor key_pair = openstack_compute_keypair_v2.k8s.name user_data = each.value.cloudinit != null ? templatefile("${path.module}/templates/cloudinit.yaml.tmpl", { - extra_partitions = each.value.cloudinit.extra_partitions + extra_partitions = each.value.cloudinit.extra_partitions, + netplan_critical_dhcp_interface = each.value.cloudinit.netplan_critical_dhcp_interface, }) : data.cloudinit_config.cloudinit.rendered dynamic "block_device" { diff --git a/contrib/terraform/openstack/modules/compute/templates/cloudinit.yaml.tmpl b/contrib/terraform/openstack/modules/compute/templates/cloudinit.yaml.tmpl index 879642cc1..fd05cc44e 100644 --- a/contrib/terraform/openstack/modules/compute/templates/cloudinit.yaml.tmpl +++ b/contrib/terraform/openstack/modules/compute/templates/cloudinit.yaml.tmpl @@ -1,4 +1,4 @@ -%{~ if length(extra_partitions) > 0 } +%{~ if length(extra_partitions) > 0 || netplan_critical_dhcp_interface != "" } #cloud-config bootcmd: %{~ for idx, partition in extra_partitions } @@ -8,11 +8,26 @@ bootcmd: %{~ endfor } runcmd: +%{~ if netplan_critical_dhcp_interface != "" } + - netplan apply +%{~ endif } %{~ for idx, partition in extra_partitions } - mkdir -p ${partition.mount_path} - chown nobody:nogroup ${partition.mount_path} - mount ${partition.partition_path} ${partition.mount_path} -%{~ endfor } +%{~ endfor ~} + +%{~ if netplan_critical_dhcp_interface != "" } +write_files: + - path: /etc/netplan/90-critical-dhcp.yaml + content: | + network: + version: 2 + ethernets: + ${ netplan_critical_dhcp_interface }: + dhcp4: true + critical: true +%{~ endif } mounts: %{~ for idx, partition in extra_partitions } diff --git a/contrib/terraform/openstack/modules/compute/variables.tf b/contrib/terraform/openstack/modules/compute/variables.tf index f65fd3b94..1a78f503e 100644 --- a/contrib/terraform/openstack/modules/compute/variables.tf +++ b/contrib/terraform/openstack/modules/compute/variables.tf @@ -142,13 +142,14 @@ variable "k8s_nodes" { additional_server_groups = optional(list(string)) server_group = optional(string) cloudinit = optional(object({ - extra_partitions = list(object({ + extra_partitions = optional(list(object({ volume_path = string partition_path = string partition_start = string partition_end = string mount_path = string - })) + })), []) + netplan_critical_dhcp_interface = optional(string, "") })) })) }