From d0ad3a226d6ba25bdaecfef40ec13bdf1ea3185c Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Thu, 11 Jan 2024 08:54:10 +0100 Subject: [PATCH] terraform, azure: add node_pools variable validation --- terraform/azure/projects/utoronto.tfvars | 2 +- terraform/azure/variables.tf | 41 +++++++++++++++++------- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/terraform/azure/projects/utoronto.tfvars b/terraform/azure/projects/utoronto.tfvars index f7888250e5..6a552efa24 100644 --- a/terraform/azure/projects/utoronto.tfvars +++ b/terraform/azure/projects/utoronto.tfvars @@ -55,5 +55,5 @@ node_pools = { }, ], - dask : [] + dask : [], } diff --git a/terraform/azure/variables.tf b/terraform/azure/variables.tf index afeee2db6e..85856ea2e3 100644 --- a/terraform/azure/variables.tf +++ b/terraform/azure/variables.tf @@ -79,17 +79,21 @@ variable "ssh_pub_key" { } variable "node_pools" { - type = map(list(object({ - name : string, - vm_size : string, - os_disk_size_gb : optional(number, 100), - kubelet_disk_type : optional(string, "Temporary"), - min : number, - max : number, - labels : optional(map(string), {}), - taints : optional(list(string), []), - kubernetes_version : optional(string, ""), - }))) + type = map( + list( + object({ + name : string, + vm_size : string, + os_disk_size_gb : optional(number, 100), + kubelet_disk_type : optional(string, "Temporary"), + min : number, + max : number, + labels : optional(map(string), {}), + taints : optional(list(string), []), + kubernetes_version : optional(string, ""), + }) + ) + ) description = <<-EOT Node pools to create to be listed under the keys 'core', 'user', and 'dask'. @@ -97,6 +101,21 @@ variable "node_pools" { special treatment by being listed directly in the cluster resource's 'default_node_pool' field. EOT + + validation { + condition = length(var.node_pools["core"]) == 1 + error_message = "The core node pool is mapped to the cluster resource's `default_node_pool`, due to this we require exactly one core node pool to be specified." + } + + validation { + condition = length(setsubtract(keys(var.node_pools), ["core", "user", "dask"])) == 0 + error_message = "Only three kinds of node pools supported: 'core', 'user', and 'dask'." + } + + validation { + condition = length(setintersection(keys(var.node_pools), ["core", "user", "dask"])) == 3 + error_message = "All three kinds of node pools ('core', 'user', and 'dask') must be declared, even if they are empty lists of node pools." + } } variable "create_service_principal" {