Skip to content

Commit 63afe0d

Browse files
committed
move validation into nodegroup module
1 parent e923068 commit 63afe0d

File tree

4 files changed

+42
-49
lines changed

4 files changed

+42
-49
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,8 @@ module "compute" {
3636
control_address = openstack_networking_port_v2.control[var.cluster_networks[0].network].all_fixed_ips[0]
3737
security_group_ids = [for o in data.openstack_networking_secgroup_v2.nonlogin: o.id]
3838
baremetal_nodes = data.external.baremetal_nodes.result
39+
40+
# input dict validation:
41+
group_name = each.key
42+
group_keys = keys(each.value)
3943
}

environments/skeleton/{{cookiecutter.environment}}/tofu/login.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,8 @@ module "login" {
3939
control_address = openstack_networking_port_v2.control[var.cluster_networks[0].network].all_fixed_ips[0]
4040
security_group_ids = [for o in data.openstack_networking_secgroup_v2.login: o.id]
4141
baremetal_nodes = data.external.baremetal_nodes.result
42+
43+
# input dict validation:
44+
group_name = each.key
45+
group_keys = keys(each.value)
4246
}

environments/skeleton/{{cookiecutter.environment}}/tofu/node_group/variables.tf

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,36 @@ variable "nodename_template" {
140140
type = string
141141
default = ""
142142
}
143+
144+
variable "group_name" {
145+
type = string
146+
}
147+
148+
variable "group_keys" {
149+
type = list
150+
validation {
151+
condition = length(setsubtract(var.group_keys, var.allowed_keys)) == 0
152+
error_message = "Compute group ${var.group_name} in var.compute contains invalid key(s): ${
153+
join(", ", setsubtract(var.group_keys, var.allowed_keys))}"
154+
}
155+
}
156+
157+
variable "allowed_keys" {
158+
type = list
159+
default = [
160+
"nodes",
161+
"flavor",
162+
"image_id",
163+
"extra_networks",
164+
"vnic_types",
165+
"compute_init_enable",
166+
"ignore_image_changes",
167+
"volume_backed_instances",
168+
"root_volume_size",
169+
"extra_volumes",
170+
"match_ironic_node",
171+
"availability_zone",
172+
"gateway_ip",
173+
"nodename_template"
174+
]
175+
}

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

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -101,55 +101,7 @@ variable "compute" {
101101
nodename_template: Overrides variable cluster_nodename_template
102102
EOF
103103
default = {}
104-
type = any # can't do any better; TF type constraints can't cope with inhomogenous mappings
105-
# module call will fail if missing required values so only need to check for unexpected ones
106-
validation {
107-
condition = length(
108-
setsubtract(
109-
flatten([for k, v in var.compute: keys(v)]),
110-
[
111-
"nodes",
112-
"flavor",
113-
"image_id",
114-
"extra_networks",
115-
"vnic_types",
116-
"compute_init_enable",
117-
"ignore_image_changes",
118-
"volume_backed_instances",
119-
"root_volume_size",
120-
"extra_volumes",
121-
"match_ironic_node",
122-
"availability_zone",
123-
"gateway_ip",
124-
"nodename_template"
125-
]
126-
)
127-
) == 0
128-
error_message = <<-EOT
129-
var.compute contains mappings with invalid keys: ${
130-
join(", ", setsubtract(
131-
flatten([for k, v in var.compute: keys(v)]),
132-
[
133-
"nodes",
134-
"flavor",
135-
"image_id",
136-
"extra_networks",
137-
"vnic_types",
138-
"compute_init_enable",
139-
"ignore_image_changes",
140-
"volume_backed_instances",
141-
"root_volume_size",
142-
"extra_volumes",
143-
"match_ironic_node",
144-
"availability_zone",
145-
"gateway_ip",
146-
"nodename_template"
147-
]
148-
)
149-
)
150-
}
151-
EOT
152-
}
104+
type = any # can't do any better; TF type constraints can't cope with inhomogenous inner mappings
153105
}
154106

155107
variable "environment_root" {

0 commit comments

Comments
 (0)