From 42fb1ea5012d5cda0870ef25ca52ba84743a3142 Mon Sep 17 00:00:00 2001 From: Fredrik Liv Date: Tue, 8 Nov 2022 15:49:42 +0100 Subject: [PATCH] Added network_id as an override variable --- contrib/terraform/openstack/README.md | 1 + contrib/terraform/openstack/modules/compute/main.tf | 6 ++++-- contrib/terraform/openstack/modules/compute/variables.tf | 2 ++ contrib/terraform/openstack/variables.tf | 2 ++ 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/contrib/terraform/openstack/README.md b/contrib/terraform/openstack/README.md index 3f19f9823..f8016d07c 100644 --- a/contrib/terraform/openstack/README.md +++ b/contrib/terraform/openstack/README.md @@ -309,6 +309,7 @@ k8s_nodes: image_id: string # (optional) Image ID to use, defaults to var.image_id or var.image root_volume_size_in_gb: number # (optional) Size of the block storage to use as root disk, defaults to var.node_root_volume_size_in_gb or to use volume from flavor otherwise volume_type: string # (optional) Volume type to use, defaults to var.node_volume_type + network_id: string # (optional) Use this network_id for the node, defaults to either var.network_id or ID of var.network_name server_group: string # (optional) Server group to add this node to. If set, this has to be one specified in additional_server_groups, defaults to use the server group specified in node_server_group_policy cloudinit: # (optional) Options for cloud-init extra_partitions: # List of extra partitions (other than the root partition) to setup during creation diff --git a/contrib/terraform/openstack/modules/compute/main.tf b/contrib/terraform/openstack/modules/compute/main.tf index a1b32173c..bc8fda816 100644 --- a/contrib/terraform/openstack/modules/compute/main.tf +++ b/contrib/terraform/openstack/modules/compute/main.tf @@ -216,6 +216,7 @@ locals { "image_id" = node.image_id != null ? node.image_id : local.image_to_use_node, "volume_size" = node.root_volume_size_in_gb != null ? node.root_volume_size_in_gb : var.node_root_volume_size_in_gb, "volume_type" = node.volume_type != null ? node.volume_type : var.node_volume_type, + "network_id" = node.network_id != null ? node.network_id : (var.use_existing_network ? data.openstack_networking_network_v2.k8s_network[0].id : var.network_id) "server_group" = node.server_group != null ? [openstack_compute_servergroup_v2.k8s_node_additional[node.server_group].id] : (var.node_server_group_policy != "" ? [openstack_compute_servergroup_v2.k8s_node[0].id] : []) } } @@ -227,6 +228,7 @@ locals { "image_id" = node.image_id != null ? node.image_id : local.image_to_use_master, "volume_size" = node.root_volume_size_in_gb != null ? node.root_volume_size_in_gb : var.master_root_volume_size_in_gb, "volume_type" = node.volume_type != null ? node.volume_type : var.master_volume_type, + "network_id" = node.network_id != null ? node.network_id : (var.use_existing_network ? data.openstack_networking_network_v2.k8s_network[0].id : var.network_id) } } } @@ -356,7 +358,7 @@ resource "openstack_compute_instance_v2" "k8s_master" { resource "openstack_networking_port_v2" "k8s_masters_port" { for_each = var.number_of_k8s_masters == 0 && var.number_of_k8s_masters_no_etcd == 0 && var.number_of_k8s_masters_no_floating_ip == 0 && var.number_of_k8s_masters_no_floating_ip_no_etcd == 0 ? var.k8s_masters : {} name = "${var.cluster_name}-k8s-${each.key}" - network_id = var.use_existing_network ? data.openstack_networking_network_v2.k8s_network[0].id : var.network_id + network_id = local.k8s_masters_settings[each.key].network_id admin_state_up = "true" port_security_enabled = var.force_null_port_security ? null : var.port_security_enabled security_group_ids = var.port_security_enabled ? local.master_sec_groups : null @@ -794,7 +796,7 @@ resource "openstack_compute_instance_v2" "k8s_node_no_floating_ip" { resource "openstack_networking_port_v2" "k8s_nodes_port" { for_each = var.number_of_k8s_nodes == 0 && var.number_of_k8s_nodes_no_floating_ip == 0 ? var.k8s_nodes : {} name = "${var.cluster_name}-k8s-node-${each.key}" - network_id = var.use_existing_network ? data.openstack_networking_network_v2.k8s_network[0].id : var.network_id + network_id = local.k8s_nodes_settings[each.key].network_id admin_state_up = "true" port_security_enabled = var.force_null_port_security ? null : var.port_security_enabled security_group_ids = var.port_security_enabled ? local.worker_sec_groups : null diff --git a/contrib/terraform/openstack/modules/compute/variables.tf b/contrib/terraform/openstack/modules/compute/variables.tf index 1f78136e2..f65fd3b94 100644 --- a/contrib/terraform/openstack/modules/compute/variables.tf +++ b/contrib/terraform/openstack/modules/compute/variables.tf @@ -125,6 +125,7 @@ variable "k8s_masters" { image_id = optional(string) root_volume_size_in_gb = optional(number) volume_type = optional(string) + network_id = optional(string) })) } @@ -137,6 +138,7 @@ variable "k8s_nodes" { image_id = optional(string) root_volume_size_in_gb = optional(number) volume_type = optional(string) + network_id = optional(string) additional_server_groups = optional(list(string)) server_group = optional(string) cloudinit = optional(object({ diff --git a/contrib/terraform/openstack/variables.tf b/contrib/terraform/openstack/variables.tf index 826b9901a..efd0ed7e1 100644 --- a/contrib/terraform/openstack/variables.tf +++ b/contrib/terraform/openstack/variables.tf @@ -302,6 +302,7 @@ variable "k8s_masters" { image_id = optional(string) root_volume_size_in_gb = optional(number) volume_type = optional(string) + network_id = optional(string) })) } @@ -315,6 +316,7 @@ variable "k8s_nodes" { image_id = optional(string) root_volume_size_in_gb = optional(number) volume_type = optional(string) + network_id = optional(string) server_group = optional(string) cloudinit = optional(object({ extra_partitions = list(object({