Skip to content

Commit 3f5d5f8

Browse files
committed
test lifecycle ignore image changes via variable
1 parent d317920 commit 3f5d5f8

File tree

3 files changed

+59
-5
lines changed

3 files changed

+59
-5
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ module "compute" {
66
# must be set for group:
77
nodes = each.value.nodes
88
flavor = each.value.flavor
9-
109
cluster_name = var.cluster_name
1110
cluster_domain_suffix = var.cluster_domain_suffix
1211
cluster_net_id = data.openstack_networking_network_v2.cluster_net.id
@@ -21,6 +20,7 @@ module "compute" {
2120
extra_volumes = lookup(each.value, "extra_volumes", {})
2221

2322
compute_init_enable = lookup(each.value, "compute_init_enable", [])
23+
ignore_image_changes = lookup(each.value, "ignore_image_changes", false)
2424

2525
key_pair = var.key_pair
2626
environment_root = var.environment_root

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

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ locals {
99
# this is a mapping with
1010
# keys "compute-0-vol-a", "compute-0-vol-b" ...
1111
# values which are a mapping e.g. {"node"="compute-0", "volume"="vol-a"}
12+
compute_instances = var.ignore_image_changes ? openstack_compute_instance_v2.compute_fixed_image : openstack_compute_instance_v2.compute
1213
}
1314

1415
resource "openstack_blockstorage_volume_v3" "compute" {
@@ -24,7 +25,7 @@ resource "openstack_compute_volume_attach_v2" "compute" {
2425

2526
for_each = local.all_compute_volumes
2627

27-
instance_id = openstack_compute_instance_v2.compute["${each.value.node}"].id
28+
instance_id = local.compute_instances["${each.value.node}"].id
2829
volume_id = openstack_blockstorage_volume_v3.compute["${each.key}"].id
2930
}
3031

@@ -48,9 +49,57 @@ resource "openstack_networking_port_v2" "compute" {
4849
}
4950
}
5051

52+
resource "openstack_compute_instance_v2" "compute_fixed_image" {
53+
54+
for_each = var.ignore_image_changes ? toset(var.nodes) : []
55+
56+
name = "${var.cluster_name}-${each.key}"
57+
image_id = var.image_id
58+
flavor_name = var.flavor
59+
key_pair = var.key_pair
60+
61+
dynamic "block_device" {
62+
for_each = var.volume_backed_instances ? [1]: []
63+
content {
64+
uuid = var.image_id
65+
source_type = "image"
66+
destination_type = "volume"
67+
volume_size = var.root_volume_size
68+
boot_index = 0
69+
delete_on_termination = true
70+
}
71+
}
72+
73+
network {
74+
port = openstack_networking_port_v2.compute[each.key].id
75+
access_network = true
76+
}
77+
78+
metadata = merge(
79+
{
80+
environment_root = var.environment_root
81+
k3s_token = var.k3s_token
82+
control_address = var.control_address
83+
},
84+
{for e in var.compute_init_enable: e => true}
85+
)
86+
87+
user_data = <<-EOF
88+
#cloud-config
89+
fqdn: ${var.cluster_name}-${each.key}.${var.cluster_name}.${var.cluster_domain_suffix}
90+
EOF
91+
92+
lifecycle {
93+
ignore_changes = [
94+
image_id,
95+
]
96+
}
97+
98+
}
99+
51100
resource "openstack_compute_instance_v2" "compute" {
52101

53-
for_each = toset(var.nodes)
102+
for_each = var.ignore_image_changes ? [] : toset(var.nodes)
54103

55104
name = "${var.cluster_name}-${each.key}"
56105
image_id = var.image_id
@@ -91,5 +140,5 @@ resource "openstack_compute_instance_v2" "compute" {
91140
}
92141

93142
output "compute_instances" {
94-
value = openstack_compute_instance_v2.compute
143+
value = local.compute_instances
95144
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,9 @@ variable "compute_init_enable" {
9393
type = list(string)
9494
description = "Groups to activate for ansible-init compute rebuilds"
9595
default = []
96-
}
96+
}
97+
98+
variable "ignore_image_changes" {
99+
type = bool
100+
default = false
101+
}

0 commit comments

Comments
 (0)