Skip to content

Commit ae1b37a

Browse files
fix: build vsphere vm dict with merge operator in KCL (#56)
KCL conditional blocks inside a dict literal override previous keys. Build the vm dict separately with |= merge operator, then assign once. Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 2defdc1 commit ae1b37a

1 file changed

Lines changed: 24 additions & 22 deletions

File tree

configurations/apps/vm-provision/compositions/vm-provision.yaml

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,29 @@ spec:
4343
4444
if _provider == "vsphere":
4545
_vs = _spec?.vsphere or {}
46+
_vsVm = {
47+
name = _vm.name
48+
count = _vm?.count or "1"
49+
cpu = _vm?.cpu or "4"
50+
ram = _vm?.ram or "4096"
51+
disk = _vm?.disk or "64"
52+
firmware = _vm?.firmware or "bios"
53+
template = _vm.template
54+
bootstrap = '["echo STUTTGART-THINGS"]'
55+
annotation = _vm?.annotation or "VM BUILD w/ CROSSPLANE FOR STUTTGART-THINGS"
56+
unverifiedSsl = _vs?.unverifiedSsl or "true"
57+
}
58+
if _vs?.folderPath:
59+
_vsVm |= {folderPath = _vs.folderPath}
60+
if _vs?.datacenter:
61+
_vsVm |= {datacenter = _vs.datacenter}
62+
if _vs?.datastore:
63+
_vsVm |= {datastore = _vs.datastore}
64+
if _vs?.resourcePool:
65+
_vsVm |= {resourcePool = _vs.resourcePool}
66+
if _vs?.network:
67+
_vsVm |= {network = _vs.network}
68+
4669
_vsphereVM = {
4770
apiVersion = "resources.stuttgart-things.com/v1alpha1"
4871
kind = "VsphereVM"
@@ -58,35 +81,14 @@ spec:
5881
name = _providerRef.name
5982
kind = _providerRef?.kind or "ClusterProviderConfig"
6083
}
61-
vm = {
62-
name = _vm.name
63-
count = _vm?.count or "1"
64-
cpu = _vm?.cpu or "4"
65-
ram = _vm?.ram or "4096"
66-
disk = _vm?.disk or "64"
67-
firmware = _vm?.firmware or "bios"
68-
template = _vm.template
69-
bootstrap = '["echo STUTTGART-THINGS"]'
70-
annotation = _vm?.annotation or "VM BUILD w/ CROSSPLANE FOR STUTTGART-THINGS"
71-
unverifiedSsl = _vs?.unverifiedSsl or "true"
72-
}
84+
vm = _vsVm
7385
tfvars = {
7486
secretName = _tfvars.secretName
7587
secretKey = _tfvars?.secretKey or "terraform.tfvars"
7688
}
7789
connectionSecret = {
7890
name = _connSecret.name
7991
}
80-
if _vs?.folderPath:
81-
vm = {folderPath = _vs.folderPath}
82-
if _vs?.datacenter:
83-
vm = {datacenter = _vs.datacenter}
84-
if _vs?.datastore:
85-
vm = {datastore = _vs.datastore}
86-
if _vs?.resourcePool:
87-
vm = {resourcePool = _vs.resourcePool}
88-
if _vs?.network:
89-
vm = {network = _vs.network}
9092
}
9193
}
9294
_resources += [_vsphereVM]

0 commit comments

Comments
 (0)