Skip to content

Commit 98ed51b

Browse files
wtripp180901sjpb
andauthored
Add option for additional user data (#757)
* allow setting volume type for extra_volumes * Added config drive option to tofu * add option for additional user data * docs suggestions Co-authored-by: Steve Brasier <[email protected]> * made user_data node variables non-nullable --------- Co-authored-by: Steve Brasier <[email protected]> Co-authored-by: Steve Brasier <[email protected]>
1 parent a3de2b7 commit 98ed51b

File tree

7 files changed

+54
-0
lines changed

7 files changed

+54
-0
lines changed

environments/site/tofu/additional.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ module "additional" {
3333
availability_zone = lookup(each.value, "availability_zone", null)
3434
ip_addresses = lookup(each.value, "ip_addresses", null)
3535
security_group_ids = lookup(each.value, "security_group_ids", [for o in data.openstack_networking_secgroup_v2.nonlogin: o.id])
36+
additional_cloud_config = lookup(each.value, "additional_cloud_config", var.additional_cloud_config)
37+
additional_cloud_config_vars = lookup(each.value, "additional_cloud_config_vars", var.additional_cloud_config_vars)
3638

3739
# can't be set for additional nodes
3840
compute_init_enable = []
@@ -65,5 +67,7 @@ module "additional" {
6567
"gateway_ip",
6668
"nodename_template",
6769
"security_group_ids",
70+
"additional_cloud_config",
71+
"additional_cloud_config_vars"
6872
]
6973
}

environments/site/tofu/compute.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ module "compute" {
2222
root_volume_type = lookup(each.value, "root_volume_type", var.root_volume_type)
2323
gateway_ip = lookup(each.value, "gateway_ip", var.gateway_ip)
2424
nodename_template = lookup(each.value, "nodename_template", var.cluster_nodename_template)
25+
additional_cloud_config = lookup(each.value, "additional_cloud_config", var.additional_cloud_config)
26+
additional_cloud_config_vars = lookup(each.value, "additional_cloud_config_vars", var.additional_cloud_config_vars)
2527

2628
# optionally set for group:
2729
networks = concat(var.cluster_networks, lookup(each.value, "extra_networks", []))
@@ -60,6 +62,8 @@ module "compute" {
6062
"ip_addresses",
6163
"gateway_ip",
6264
"nodename_template",
65+
"additional_cloud_config",
66+
"additional_cloud_config_vars"
6367
]
6468

6569
}

environments/site/tofu/control.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ resource "openstack_compute_instance_v2" "control" {
9292
%{if var.home_volume_provisioning != "none"}
9393
- [LABEL=home, /exports/home]
9494
%{endif}
95+
96+
%{if var.additional_cloud_config != ""}
97+
${templatestring(var.additional_cloud_config, var.additional_cloud_config_vars)}
98+
%{endif}
9599
EOF
96100

97101
config_drive = var.config_drive

environments/site/tofu/login.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ module "login" {
2222
root_volume_type = lookup(each.value, "root_volume_type", var.root_volume_type)
2323
gateway_ip = lookup(each.value, "gateway_ip", var.gateway_ip)
2424
nodename_template = lookup(each.value, "nodename_template", var.cluster_nodename_template)
25+
additional_cloud_config = lookup(each.value, "additional_cloud_config", var.additional_cloud_config)
26+
additional_cloud_config_vars = lookup(each.value, "additional_cloud_config_vars", var.additional_cloud_config_vars)
2527

2628
# optionally set for group:
2729
networks = concat(var.cluster_networks, lookup(each.value, "extra_networks", []))
@@ -64,6 +66,8 @@ module "login" {
6466
"ip_addresses",
6567
"gateway_ip",
6668
"nodename_template",
69+
"additional_cloud_config",
70+
"additional_cloud_config_vars",
6771
"security_group_ids"
6872
]
6973

environments/site/tofu/node_group/nodes.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ resource "openstack_compute_instance_v2" "compute_fixed_image" {
116116
user_data = <<-EOF
117117
#cloud-config
118118
fqdn: ${local.fqdns[each.key]}
119+
120+
%{if var.additional_cloud_config != ""}
121+
${templatestring(var.additional_cloud_config, var.additional_cloud_config_vars)}
122+
%{endif}
119123
EOF
120124

121125
availability_zone = var.match_ironic_node ? "${local.baremetal_az}::${var.baremetal_nodes[each.key]}" : var.availability_zone
@@ -173,6 +177,10 @@ resource "openstack_compute_instance_v2" "compute" {
173177
user_data = <<-EOF
174178
#cloud-config
175179
fqdn: ${local.fqdns[each.key]}
180+
181+
%{if var.additional_cloud_config != ""}
182+
${templatestring(var.additional_cloud_config, var.additional_cloud_config_vars)}
183+
%{endif}
176184
EOF
177185

178186
availability_zone = var.match_ironic_node ? "${local.baremetal_az}::${var.baremetal_nodes[each.key]}" : var.availability_zone

environments/site/tofu/node_group/variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,3 +196,15 @@ variable "allowed_keys" {
196196
variable "config_drive" {
197197
type = bool
198198
}
199+
200+
variable "additional_cloud_config" {
201+
type = string
202+
default = ""
203+
nullable = false
204+
}
205+
206+
variable "additional_cloud_config_vars" {
207+
type = map(any)
208+
default = {}
209+
nullable = false
210+
}

environments/site/tofu/variables.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,3 +322,21 @@ variable "config_drive" {
322322
type = bool
323323
default = null
324324
}
325+
326+
variable "additional_cloud_config" {
327+
description = <<-EOT
328+
Multiline string to be appended to the node's cloud-init cloud-config user-data.
329+
Must be in yaml format and not include the #cloud-config or any other user-data headers.
330+
See https://cloudinit.readthedocs.io/en/latest/explanation/format.html#cloud-config-data.
331+
Can be a templatestring parameterised by `additional_cloud_config_vars`.
332+
The `boot-cmd`, `fqdn` and `mounts` modules must not be specified.
333+
EOT
334+
type = string
335+
default = ""
336+
}
337+
338+
variable "additional_cloud_config_vars" {
339+
description = "Map of values passed to the `additional_cloud_config` templatestring"
340+
type = map(any)
341+
default = {}
342+
}

0 commit comments

Comments
 (0)