Skip to content

Commit e923068

Browse files
committed
just check compute keys
1 parent 09a0261 commit e923068

File tree

4 files changed

+69
-37
lines changed

4 files changed

+69
-37
lines changed

environments/.stackhpc/tofu/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ module "cluster" {
7474
flavor: var.other_node_flavor
7575
}
7676
}
77-
compute = tomap({
77+
compute = {
7878
standard: { # NB: can't call this default!
7979
nodes: ["compute-0", "compute-1"]
8080
flavor: var.other_node_flavor
@@ -87,7 +87,7 @@ module "cluster" {
8787
#nodes: ["extra-0", "extra-1"]
8888
flavor: var.other_node_flavor
8989
}
90-
})
90+
}
9191

9292
volume_backed_instances = var.volume_backed_instances
9393

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,21 @@ module "compute" {
1414
environment_root = var.environment_root
1515

1616
# can be set for group, defaults to top-level value:
17-
image_id = coalesce(each.value.image_id, var.cluster_image_id)
18-
vnic_types = coalesce(each.value.vnic_types, var.vnic_types)
19-
volume_backed_instances = coalesce(each.valuevolume_backed_instances, var.volume_backed_instances)
20-
root_volume_size = coalesce(each.value.root_volume_size, var.root_volume_size)
21-
gateway_ip = coalesce(each.value.gateway_ip, var.gateway_ip)
22-
nodename_template = coalesce(each.value.nodename_template, var.cluster_nodename_template)
17+
image_id = lookup(each.value, "image_id", var.cluster_image_id)
18+
vnic_types = lookup(each.value, "vnic_types", var.vnic_types)
19+
volume_backed_instances = lookup(each.value, "volume_backed_instances", var.volume_backed_instances)
20+
root_volume_size = lookup(each.value, "root_volume_size", var.root_volume_size)
21+
gateway_ip = lookup(each.value, "gateway_ip", var.gateway_ip)
22+
nodename_template = lookup(each.value, "nodename_template", var.cluster_nodename_template)
2323

2424
# optionally set for group:
25-
networks = concat(var.cluster_networks, coalesce(each.value.extra_networks, []))
26-
extra_volumes = coalesce(each.value.extra_volumes, {})
27-
compute_init_enable = coalesce(each.value.compute_init_enable, [])
28-
ignore_image_changes = coalesce(each.value.ignore_image_changes, false)
29-
match_ironic_node = coalesce(each.value.match_ironic_node, false)
30-
availability_zone = coalesce(each.value.availability_zone, "nova")
25+
networks = concat(var.cluster_networks, lookup(each.value, "extra_networks", []))
26+
# here null means "use module var default"
27+
extra_volumes = lookup(each.value, "extra_volumes", null)
28+
compute_init_enable = lookup(each.value, "compute_init_enable", null)
29+
ignore_image_changes = lookup(each.value, "ignore_image_changes", null)
30+
match_ironic_node = lookup(each.value, "match_ironic_node", null)
31+
availability_zone = lookup(each.value, "availability_zone", null)
3132

3233
# computed
3334
# not using openstack_compute_instance_v2.control.access_ip_v4 to avoid

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ variable "extra_volumes" {
6363
})
6464
)
6565
default = {}
66+
nullable = false
6667
}
6768

6869
variable "security_group_ids" {
@@ -78,17 +79,18 @@ variable "compute_init_enable" {
7879
type = list(string)
7980
description = "Groups to activate for ansible-init compute rebuilds"
8081
default = []
82+
nullable = false
8183
}
8284

8385
variable "ignore_image_changes" {
8486
type = bool
8587
description = "Whether to ignore changes to the image_id parameter"
8688
default = false
89+
nullable = false
8790
}
8891

8992
variable "networks" {
9093
type = list(map(string))
91-
default = []
9294
}
9395

9496
variable "fip_addresses" {
@@ -114,12 +116,14 @@ variable "match_ironic_node" {
114116
type = bool
115117
description = "Whether to launch instances on the Ironic node of the same name as each cluster node"
116118
default = false
119+
nullable = false
117120
}
118121

119122
variable "availability_zone" {
120123
type = string
121124
description = "Name of availability zone - ignored unless match_ironic_node is true"
122125
default = "nova"
126+
nullable = false
123127
}
124128

125129
variable "baremetal_nodes" {

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

Lines changed: 49 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -101,28 +101,55 @@ variable "compute" {
101101
nodename_template: Overrides variable cluster_nodename_template
102102
EOF
103103
default = {}
104-
type = map( # i.e. arbitrary keys, values are of given type ...
105-
object({
106-
# Only need to specify required/optional *keys* here to
107-
# e.g. prevent missing/typos - value types are defined in
108-
# module inputs so don't repeat here
109-
nodes = any
110-
flavor = any
111-
112-
image_id = optional(any)
113-
extra_networks = optional(any)
114-
vnic_types = optional(any)
115-
compute_init_enable = optional(any)
116-
ignore_image_changes = optional(any)
117-
volume_backed_instances = optional(any)
118-
root_volume_size = optional(any)
119-
extra_volumes = optional(any)
120-
match_ironic_node = optional(any)
121-
availability_zone = optional(any)
122-
gateway_ip = optional(any)
123-
nodename_template = optional(any)
124-
})
125-
)
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+
}
126153
}
127154

128155
variable "environment_root" {

0 commit comments

Comments
 (0)